just a general question regarding a checkers project. I built a class hierarchy for the game pieces (that could be extended for chess etc). The hierarchy looks something like
interface GamePiece() {...}
class EmptySquare implements GamePiece {...}
class Pawn implements GamePiece extends EmptySquare {...}
class Queen implements GamePiece extends EmptySquare {...}
I store an object reference in the board[][]
array. In the tree search that array is cloned for each recursion (not with doMove()
... call recursion ... undoMove()
). I store object refs for the game pieces so I can do something like this for generating the list of moves:
for(sq:Squares)
sq.getPossibleMoves()
possibleMoves.addAll(sq.possibleMoves)
I'm not sure how much space this array of references takes up and if that is any good way to it from a performance point of view. It works nicely logically though. Would you do it like that or sacrifice the nicer code for a more compact game board array and the use switch()
to call subroutines for each piece to make the move list?
Queen
extendEmptySquare
? That doesn't seem right. Maybe extendAbstractPiece
or extend nothing. The board can have aMap<Square,Piece>
... \$\endgroup\$