Reversi 2D阵列打印

时间:2014-09-22 05:30:37

标签: c++ console-application

(这是作业)我正在尝试打印带有行和列标题的黑白棋盘。我的问题是为什么不打印期间而是打印“B”和“W”。有什么提示吗?

#include <iostream>
#include <cstdlib> 
using namespace std;
const int BOARD_SIZE = 8, MOVE_SYMBOL = 3;
void PrintBoard(char board[8][8]);

int main(int argc, char* argv[]) {
   const int BOARD_SIZE = 8;

   char board[BOARD_SIZE][BOARD_SIZE] =
 {
  { 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 1, -1, 0, 0, 0 },
  { 0, 0, 0, -1, 1, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0 },
  { 0, 0, 0, 0, 0, 0, 0, 0 }
 };
PrintBoard(board);
}
// Prints current state of Reversi Board 15L
void PrintBoard(char board[BOARD_SIZE][BOARD_SIZE]) { 
char output[MOVE_SYMBOL] = { 'W', ' . ', 'B' };
cout << "\n- 0  1  2  3  4  5  6  7";
for (int i = 0; i < BOARD_SIZE; i++) {
  cout << "\n" << i;
  for (int j = 0; j < BOARD_SIZE; j++) {
     cout << output[board[i][j] + 1];
   }
}

输出:

- 0  1  2  3  4  5  6  7
0
1
2
3   BW
4   WB
5
6
7        Press any key to continue . . .

1 个答案:

答案 0 :(得分:7)

这是因为你的时期周围的空间。一个字母位于一个位置,因此'.'而不是' . '