#ifndef TICTACTOE_H_ #define TICTACTOE_H_ // (c) Markus Lumpe, CS 229 Spring 2007 #include // strings #include using namespace std; class TicTacToe; class TicTacToeView { public: virtual ~TicTacToeView() {}; // kill warning virtual void registerGame( TicTacToe* aGame ) = 0; virtual void printBoard() = 0; virtual void draw() = 0; virtual void declareWinner( int aPlayer ) = 0; }; class MoveException { private: string fMessage; public: MoveException( string aMessage ); string getMessage(); }; class TicTacToe { private: int fBoard[3][3]; int fFieldsSet; bool fPlay; TicTacToeView& fView; int fPlayerId; int fComputerId; static int fOptimalMoves[9]; void setMove( int aMove, int aPlayerId ); void unsetMove( int aMove ); bool isFree( int aMove ); int computeComputerMove(); int findComputerResponse( int aMove1, int aMove2 ); int countSetFields(); void announceGameOver(); void announcePlayerHasWon( int aPlayer ); bool checkWin(); bool checkRows(); bool checkRow( int aRow ); bool checkColumns(); bool checkColumn( int aColumn ); bool checkNWToSE(); bool checkNEToSW(); public: TicTacToe( TicTacToeView& aView ); int getField( int aIndex ); void setField( int aIndex, int aValue ); int performComputerMove( int aPlayerId, int aComputerId ); bool isActive(); void isGameOver( int aPlayer ); }; #endif /*TICTACTOE_H_*/