| |
ChineseCheckers
category: Morphic-Games
superclass: BorderedMorph
subclasses:
An implementation of Chinese Checkers by Dan Ingalls. April 9, 2000.
board: A 19x19 rhombic array, addressed by row@col points, in which is imbedded the familiar six-pointed layout of cells. A cell outside the board is nil (-).
- - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - 5 - - - - -
- - - - - - - - - - - - 5 5 - - - - -
- - - - - - - - - - - 5 5 5 - - - - -
- - - - - - - - - - 5 5 5 5 - - - - -
- - - - - 6 6 6 6 0 0 0 0 0 4 4 4 4 -
- - - - - 6 6 6 0 0 0 0 0 0 4 4 4 - -
- - - - - 6 6 0 0 0 0 0 0 0 4 4 - - -
- - - - - 6 0 0 0 0 0 0 0 0 4 - - - -
- - - - - 0 0 0 0 0 0 0 0 0 - - - - -
- - - - 1 0 0 0 0 0 0 0 0 3 - - - - -
- - - 1 1 0 0 0 0 0 0 0 3 3 - - - - -
- - 1 1 1 0 0 0 0 0 0 3 3 3 - - - - -
- 1 1 1 1 0 0 0 0 0 3 3 3 3 - - - - -
- - - - - 2 2 2 2 - - - - - - - - - -
- - - - - 2 2 2 - - - - - - - - - - -
- - - - - 2 2 - - - - - - - - - - - -
- - - - - 2 - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -
Cells within the board contain 0 if empty, or a team number (1..6) if occupied by a piece of that team. An extra border of nils around the whole reduces bounds checking to a nil test.
sixDeltas: An array giving the x@y deltas for the 6 valid steps in CCW order from a given cell. For team 1 they are: in fr, fl, l, bl, br, r. To get, eg fl for a given team, use (sixDeltas atWrap: team+1).
teams: An array of six teams, each of which is an array of the x@y locations of the 10 pieces.
homes: The x@y coordinates of the six home points, namely 14@2, 18@6, 14@14, 6@18, 2@14, 6@6. The goal, or farthest point in destination triangle, is thus (homes atWrap: teamNo+3).
autoPlay: An array of booleans, parallel to teams, where true means that Squeak will make the moves for the corresponding team.
whoseMove: A team number specifying whose turn it is next. Set to 0 when game is over.
plannedMove: If not nil, it means the board is in a state where it is animating the next move to be made so that it can be seen.
movePhase: Holds the state of display of the planned move so that, eg, it can appear one jump at a time. Advances from 1 to (plannedMove size * 2).
A move is an array of locs which are the path of the move.
Once the morph is open, the menu command 'reset...' allows you to reset the board and change the number of players. The circle at turnIndicatorLoc indicates the color of the team whose turn it is. If it is a human, play waits for drag and drop of a piece of that color.
The current strategy is very simple: generate all moves, score them and pick the best. Beyond this, it will look ahead a number of moves, but this becomes very expensive without pruning. Pruning would help the speed of play, especially in the end game where we look a little deeper. A more effective strategy would consider opponents' possible moves as well, but this is left as an exercise for the serious programmer.




|
|