home *** CD-ROM | disk | FTP | other *** search
- ///////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////
- // This example code is from the book:
- //
- // Object-Oriented Programming with C++ and OSF/Motif
- // by
- // Douglas Young
- // Prentice Hall, 1992
- // ISBN 0-13-630252-1
- //
- // Copyright 1991 by Prentice Hall
- // All Rights Reserved
- //
- // Permission to use, copy, modify, and distribute this software for
- // any purpose except publication and without fee is hereby granted, provided
- // that the above copyright notice appear in all copies of the software.
- ///////////////////////////////////////////////////////////////////////////////
- //////////////////////////////////////////////////////////////////////////////
-
-
- /////////////////////////////////////////////////////////////
- // Board.h: Represent a tictactoe board
- /////////////////////////////////////////////////////////////
- #ifndef BOARD_H
- #define BOARD_H
-
- // Different versions of C++ (2.X, 3.X, etc.) treat enumerated types declared
- // within a class differently. Although I prefer encapsulating these values in the
- // Board class, the easiest way to make these examples work with all versions
- // is to just move them out of the class declaration:
-
- enum MoveStatus { validMove, illegalMove };
- enum markType { NOBODYYET, OO, XX, TIE };
-
- // Convenient values
-
- class Board {
-
- protected:
-
- int _state[9]; // Internal game state
- int _freeList[9]; // List used to report free squares
- int numFreeSquares();
- int *_winningPattern; // Pattern last tested when someone wins
- static int _winningBits[8][9];
-
- public:
-
- Board();
- MoveStatus recordMove ( int, markType ); // Record an X or an O
-
- // Return number of available squares, and their indexes
-
- int *const freeSquares ( int& );
-
- // Public access for winning pattern of squares
-
- int *const winningSquares() { return _winningPattern; }
-
- void clear(); // Clear and reset the board
- markType whoHasWon(); // Return code for possible winner
- virtual const char *const className() { return "Board"; }
- };
- #endif
-