//////////////////////////////////////////////////////// // // TTTBoard.h // // Written by Jeff Ondich on 1/14/98 // Modified by Dave Musicant on 9/20/02 // // This is the interface for the class TTTBoard. // TTTBoard objects store the current state of // a game of Tic-Tac-Toe, and provide operations for // manipulating the game. // //////////////////////////////////////////////////////// #ifndef TTTBOARD_H #define TTTBOARD_H const char playerX = 'X'; const char playerO = 'O'; const char noPlayer = ' '; class TTTBoard { private: char board[3][3]; char whoseTurn; public: // Constructor TTTBoard(); // Getting information about data members bool isOpen(int row, int col) const; char whoIsThere(int row, int col) const; char whoseTurn() const; char winningPlayer() const; // Making moves bool makeMove(char thePlayer, int row, int col); // Displaying the state of the game void drawBoard(); }; //////////////////////////////////////////////////////// // // Descriptions of the member functions // //////////////////////////////////////////////////////// // The constructor TTTBoard() initializes the board // to empty--neither X nor O has moved--and sets // whoseTurn to playerX. // isOpen() returns false if theSquare is // occupied by an X or an O, and true otherwise. // whoIsThere() returns playerX, playerO, or noPlayer, // depending on what is in theSquare. // whoseTurn() returns playerX or playerO, depending on // whose turn it is. As indicated in the description of // the constructor, X always goes first. // winningPlayer() returns playerX, playerO, or noPlayer, // depending on if any player has three in a row. If two players // both have three in a row (which should be impossible), // winningPlayer() returns noPlayer. If a single player has // more than one three in a row at a time and the other // player does not have three in a row, winningPlayer() // returns that player with multiple wins. // If it is thePlayer's move and the square is open, makeMove() // makes a move for thePlayer in the square and returns true. // Otherwise, makeMove() returns false. // drawBoard() prints some kind of representation of the // Tic-Tac-Toe board to standard output (cout). For // example, the display might look like this: // // | | // X | O | // | | // ----------- // | | // X | | // | | // ----------- // | | // O | | // | | // // It is X's turn. // #endif