/* TTTGame.h * * * Written February, 2004 by Pat Troy for CS 422 */ #include enum GameStatus { POSITIONINUSE=-2, INVALIDMOVE = -1, VALIDMOVE = 0, WINGAME = 1, LOSEGAME = 2, CATSGAME = 3}; enum PlayerID { DEFAULTPLAYER, USERPLAYER, COMPUTERPLAYER }; enum POSORCOUNT {POS, COUNT}; extern int posArray[8][3]; // {{1,2,3}, /* positions in the first row */ // {4,5,6}, /* positions in the second row */ // {7,8,9}, /* positions in the third row */ // {1,4,7}, /* positions in the first column */ // {2,5,8}, /* positions in the second column */ // {3,6,9}, /* positions in the third column */ // {1,5,9}, /* positions in the first diagonal */ // {3,5,7}}; /* positions in the second diagonal */ class TTTGame { protected: /* The constructors will be protected to force the use of the static createTTTGame method. */ TTTGame(); /* There is also a static pointer to TTTGame to keep track of the single instance of the class. */ static TTTGame *game; /* The normal data members of the class */ char board[10]; int turn; int startingPlayer; int moveNumber; int numStarted; int numWon; int numLost; int numCats; /* A "Cat's Game" is a game with no winner */ public: /* These static methods will create and/or return the instance of the game maintained in the static pointer */ static TTTGame *createTTTGame ( void ); static TTTGame *getGame ( void ); /* Here are the normal methods of the class */ int newGame (int startPlayer = 0); char getPosition ( int pos ); int userMove (char move); int computerMove ( void ); int getTurn ( void ); int getNumStarted ( void ); int getNumWon ( void ); int getNumLost ( void ); int getNumCats ( void ); int findWinningMove (char, int); int determineComputerMove (); int isGameWon (); /* return -1 when there is no winner or the first dimension of the posArray which indicates the winning 3 positions */ };