Thursday, March 31, 2011

The Chess Pieces and Tiles

Bear with me as I work backwards in creating the board - this whole "documentation" thing sometimes is difficult.

The board is composed of tiles, each of which is a class. The most important parts of each tile are as follows:

   1:  public class Tile
   2:  {
   3:      public File file;
   4:      public Rank rank;
   5:      public ChessPiece piece;
   6:      public Tile[] neighbors;

If a tile does not have a piece on it, the piece variable is null; likewise, if a piece is a border tile, the entry for it's neighbor (of 6 possible) is null - this tells us when a piece is an edge tile.

Pieces are likewise classes, and their most important parts are as follows:

   1:  public class ChessPiece
   2:  {
   3:      public PieceType type;
   4:      public PieceColor side;
   5:      public Tile tile;
   6:      public bool Alive;
   7:      public bool WasMoved;
   8:      public bool WasOnStartingTile;
   9:      public List<Tile> MoveableTiles = new List<Tile>();
  10:      public List<Tile> AttackableTiles = new List<Tile>();
 
Besides the obvious components, "WasMoved" is used to determine if the piece has moved (castling) and "WasOnStartingTile" is used for pawns, to determine if they can be attacked en passant. The lists are updated to determine where a piece can move or attack from its current position.

Movements shall be covered next!

No comments:

Post a Comment