|
发表于 2023-6-29 07:24:02
|
显示全部楼层
Python:
- # 定义棋盘大小和四个主场区域的位置
- board_size = 7
- home_positions = {
- '秦': [(0, 0), (0, 1), (1, 0), (1, 1)],
- '晋': [(0, 5), (0, 6), (1, 5), (1, 6)],
- '齐': [(5, 0), (5, 1), (6, 0), (6, 1)],
- '楚': [(5, 5), (5, 6), (6, 5), (6, 6)]
- }
- # 初始化棋盘
- board = [[''] * board_size for _ in range(board_size)]
- # 在棋盘上放置四个主场的棋子
- for player, positions in home_positions.items():
- for position in positions:
- row, col = position
- board[row][col] = player
- # 打印当前棋盘状态
- for row in board:
- print(row)
复制代码
C++:
- #include <iostream>
- #include <vector>
- #include <string>
- using namespace std;
- int main() {
- // 定义棋盘大小和四个主场区域的位置
- int board_size = 7;
- vector<vector<string>> board(board_size, vector<string>(board_size, ""));
- vector<vector<pair<int, int>>> home_positions = {
- {{0, 0}, {0, 1}, {1, 0}, {1, 1}}, // 秦
- {{0, 5}, {0, 6}, {1, 5}, {1, 6}}, // 晋
- {{5, 0}, {5, 1}, {6, 0}, {6, 1}}, // 齐
- {{5, 5}, {5, 6}, {6, 5}, {6, 6}} // 楚
- };
- // 在棋盘上放置四个主场的棋子
- for (int i = 0; i < home_positions.size(); i++) {
- string player = "";
- switch (i) {
- case 0:
- player = "秦";
- break;
- case 1:
- player = "晋";
- break;
- case 2:
- player = "齐";
- break;
- case 3:
- player = "楚";
- break;
- }
- for (auto position : home_positions[i]) {
- int row = position.first;
- int col = position.second;
- board[row][col] = player;
- }
- }
- // 打印当前棋盘状态
- for (int i = 0; i < board_size; i++) {
- for (int j = 0; j < board_size; j++) {
- cout << board[i][j] << " ";
- }
- cout << endl;
- }
-
- return 0;
- }
复制代码 |
|