next up previous contents
Next: Static evaluation function Up: Development Previous: Development   Contents

Program structure

CHEOPS is comprised of four classes and a main program which provides an interface and ties everything together. The ChessBoard class is at the heart of the program; it is a fully encapsulated data structure allowing for the manipulation of chessboards and the pieces thereon contained. The board itself is represented by a privately-declared 64-element array, each cell containing an enum value representing the type and colour of the piece.1 There are also numerous flags and counters, the purposes of which should be obvious from the source code and its internal documentation. The class has just two major public functions--canmove(), which returns a boolean value indicating whether or not a given move is valid; and domove(), which actually performs a move, rearranging the pieces on the board and updating the appropriate status flags. In addition to these, there are a score of small inline functions for performing menial status checks and type conversions. These functions add an extra layer of abstraction within the class, permitting the implementation of the board and pieces to be changed without having to modify the other functions in the class or its friends. Even the board arithmetic is self-contained to a degree--individual squares are represented not by integers 0 to 63 but by enum constants a1 to h8, and incrementing ranks and files is done using constants Rank and File. This data hiding would make it easy to change the board array to, say, the popular 10 $\times$ 12 or 0x88 formats [1].

The remaining three classes define the players. At the top of the hierarchy is Player, an abstract base class serving as a template for its two derived classes, HumanPlayer and ComputerPlayer. The Player class itself is very small and contains no executable functions. It has just three main members: one boolean flag indicating whether the player is human, and two pure virtual functions, the first of which is used to get commands from the player, and the second to modify his2 stats. In HumanPlayer, the first function prints out the familiar command prompt and relays the input back to the main program, while in ComputerPlayer it runs the minimax search algorithm to come up with the optimal move. The second function, while vestigial in HumanPlayer, is used in the other class to set the weights for the static evaluation function.

The ComputerPlayer class is one of the largest in CHEOPS, and thus deserves particular notice here. Because it needs to examine in detail the state of the chessboard, ComputerPlayer is a friend class of ChessBoard. It includes functions for determining potential moves, finding the distance between two board squares, assessing board configurations, and, of course, choosing the optimal move using a minimax search of the game tree. The actual criteria used to evaluate a particular board position are many and varied, and are treated specifically in the following section.


next up previous contents
Next: Static evaluation function Up: Development Previous: Development   Contents
Tristan Miller 2002-02-06