View Javadoc

1   package com.webstersmalley.chessweb.model;
2   
3   import org.apache.commons.logging.Log;
4   import org.apache.commons.logging.LogFactory;
5   
6   /***
7    * Represents a standard chess board. ie an 8x8 board, with the pieces laid out
8    * in the usual way.
9    * 
10   * @author Matthew Smalley
11   */
12  public final class StandardBoard extends Board {
13      /*** Logger for the class. */
14      private final Log logger = LogFactory.getLog(getClass());
15  
16      /*** Width of the board. */
17      private static final int STANDARD_BOARD_WIDTH = 8;
18  
19      /*** Height of the board. */
20      private static final int STANDARD_BOARD_HEIGHT = 8;
21  
22      /***
23       * Construct a new Standard chess board. Creates it with the 8x8 size, plus
24       * places the pieces in their start positions.
25       */
26      public StandardBoard() {
27          logger.debug("Creating a new standard board");
28          this.setWidth(STANDARD_BOARD_WIDTH);
29          this.setHeight(STANDARD_BOARD_HEIGHT);
30          setup();
31          for (int i = 0; i < Piece.ALL_PIECES.length; i++) {
32              Piece piece = Piece.ALL_PIECES[i];
33              logger.debug("Positioning the " + piece.getName() + "s");
34              String[] startingPositions = piece.getStartingPositions()
35                      .split(":");
36              for (int j = 0; j < startingPositions.length; j++) {
37                  place(new Position(startingPositions[j]), piece);
38              }
39          }
40          setNextTurn(Team.WHITE);
41      }
42  }