Counting Through a Move Array

The move array could be placed in the board drawer class directly since the board drawer will be the only object using it to make the moves and to take back the moves and so forth. But, to coincide with the move array the board will have to have tons of counters to access it. There are two different kinds of counts that I keep in my game. The first I call the absolute move count. It increments and decrements irrespective to which side is moving and really has no meaning in the true sence of the game. The other counters are for white and black, counting how many moves each side has made respectively. Both of these counters need to have something that represents a total so that we know when we've reached the end of the array that they are counting. The move array and the capturing array operate around the absolute game count since it doesn't matter whose moving, but other objects in my game, like the table that I use, need the white and black count. Management of counters becomes very difficult in a game with many arrays. It is because of this that I designed a counter object for this purpose alone. It handles all of the moves counts and operates under the following assertions about what can happen to the game count during the course of play by a user:

  • white or black makes a move and their respective counters increment as well as their respective totals.
  • white or black takes back a move and their respective counters decrement, but not the total
  • A move is made and the absolute game count increments as well as its total
  • A move is taken back and the absolute game count decrements but not its total
  • black or white has taken back n moves and makes a new one. The respective total of that move count is updated to equal the current value of that sides count. (whiteTotalCount = whiteCount)
  • black has taken back n moves and makes a new one. The absolute total move count is updated to equal the current value of the absolute move count
  • all counters are reset
  • The user wishes to move to the end of the game and the count becomes equal to its respective total

In this way the counters can manage the arrays in a chess game. There need not be a class for this, but it makes things less chaotic when you have functions and you know exactly what they're going to do. Also, if one were to pass a counter to a function, it would contain all the data about the count in the game for the calling function to access.

next   start