#include #include "tictactoe.h" using namespace std; int main() { int board[3][3] = { {1, 0, 2}, {0, 2, 2}, {1, 1, 1} }; // A two-dimensional array which represents the board int xChoise; int yChoise; int whoseTurn = 0; // Tells whose turn is it now. 0=human, 1=machine printBoard(board); cout << checkBoard(board) << endl; return 0; } int checkBoard(int board[3][3]) { if (board[0][0] == board[1][1] && board[1][1] == board[2][2]) return board[0][0]; else if (board[0][2] == board[1][1] && board[1][1] == board[2][0]) return board[0][2]; for (int x = 0; x < 3; x++) { if (board[x][0] == board[x][1] && board[x][1] == board[x][2]) return board[x][0]; } for (int y = 0; y < 3; y++) { if (board[0][y] == board[1][y] && board[1][y] == board[2][y]) return board[0][y]; } return 0; } void printBoard(int board[3][3]) { for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { switch (board[x][y]) { case 0: cout << " "; break; case 1: cout << "X "; break; case 2: cout << "O "; break; } } cout << endl; } }