Better javadoc
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 11 May 2009 18:47:39 +0200
changeset 162a9cbf22a8f1
parent 15 8c8eafa8b3ae
child 17 c496a8660fa6
Better javadoc
quoridor/src/main/java/cz/xelfi/quoridor/Board.java
quoridor/src/main/java/cz/xelfi/quoridor/Fence.java
quoridor/src/main/java/cz/xelfi/quoridor/Move.java
quoridor/src/main/java/cz/xelfi/quoridor/Player.java
quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java
     1.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Board.java	Mon May 11 18:35:16 2009 +0200
     1.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Board.java	Mon May 11 18:47:39 2009 +0200
     1.3 @@ -45,14 +45,20 @@
     1.4  import java.util.regex.Pattern;
     1.5  
     1.6  /**
     1.7 - * This is a class that represents a snapshot of the game position,
     1.8 - * with all the placed and not-yet placed fences and player positions.
     1.9 - * It it can print itself to stream following the format defined at
    1.10 - * http://www.gamerz.net/pbmserv/quoridor.html
    1.11 - * and shall be able to read that format back. The class is immutable
    1.12 - * but it contains "move operations" that produce new Board position.
    1.13 - * <p>
    1.14 - *
    1.15 + * Represents a snapshot of the game position,
    1.16 + * including all the placed and not-yet placed fences and player positions.
    1.17 + * It it can print itself to stream in
    1.18 + * <a href="http://www.gamerz.net/pbmserv/quoridor.html">ascii art format<a/>
    1.19 + * and can it read back. The class is immutable
    1.20 + * but it contains {@link #apply(cz.xelfi.quoridor.Move)}
    1.21 + * that produce new {@link Board} with position created after
    1.22 + * applying some {@link Move}. Use:
    1.23 + * <pre>
    1.24 + * Board whiteOnTurn = Board.empty();
    1.25 + * Board blackOnTurn = whiteOnTurn.apply(Move.NORTH);
    1.26 + * Board whiteAgain = blackOnTurn.apply(Move.SOUTH);
    1.27 + * Board withOneFence = whiteAgain.apply(Move.fence('D', 7));
    1.28 + * </pre>
    1.29   * 
    1.30   * @author Jaroslav Tulach
    1.31   */
    1.32 @@ -128,10 +134,10 @@
    1.33          this.turn = turn % players.size();
    1.34      }
    1.35      
    1.36 -    /** Creates initial empty board with default positions of 
    1.37 -     * players.
    1.38 +    /** Returns empty board with default starting position.
    1.39 +     * @return board with two pawns.
    1.40       */
    1.41 -    public static Board createEmptyBoard () {
    1.42 +    public static Board empty () {
    1.43          return new Board (8, 0, 10, 8, 16, 10);
    1.44      }
    1.45      
    1.46 @@ -169,7 +175,14 @@
    1.47          }
    1.48          return null;
    1.49      }
    1.50 -    
    1.51 +
    1.52 +    /** Applies given move to current board.
    1.53 +     *
    1.54 +     * @param move move creates by one of the factory methods or fields of the {@link Move} class
    1.55 +     * @return new board derived from this one
    1.56 +     *
    1.57 +     * @throws cz.xelfi.quoridor.IllegalPositionException throws exception if the move is illegal
    1.58 +     */
    1.59      public Board apply(Move move) throws IllegalPositionException {
    1.60          if (getWinner() != null) {
    1.61              throw new IllegalPositionException("Game finished!"); // NOI18N
     2.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Fence.java	Mon May 11 18:35:16 2009 +0200
     2.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Fence.java	Mon May 11 18:47:39 2009 +0200
     2.3 @@ -26,9 +26,36 @@
     2.4  package cz.xelfi.quoridor;
     2.5  
     2.6  /**
     2.7 - * Defines a fence. Its position is defined as position of its
     2.8 - * center (index from 0-15 in both directions) and its orientation
     2.9 - * either horizontal or vertical.
    2.10 + * Represents position of a fence on a {@link Board}. The fence can be oriented 
    2.11 + * either in
    2.12 + * {@link Orientation#HORIZONTAL} or {@link Orientation#VERTICAL} direction.
    2.13 + * The faces postions are numbered 1-8 and A-H according to following
    2.14 + * graph: <pre>
    2.15 +            H   G   F   E   D   C   B   A
    2.16 +            |   |   |   |   |   |   |   |
    2.17 +        +-----------------------------------+
    2.18 +        |                                   |
    2.19 +     1--|   +   +   +   +   +   +   +   +   |--1
    2.20 +        |                                   |
    2.21 +     2--|   +   +   +   +   +   +   +   +   |--2
    2.22 +        |                                   |
    2.23 +     3--|   +   +   +   +   +   +   +   +   |--3
    2.24 +        |                                   |
    2.25 +     4--|   +   +   +   +   +   +   +   +   |--4
    2.26 +[E]     |                                   |     [W]
    2.27 +     5--|   +   +   +   +   +   +   +   +   |--5
    2.28 +        |                                   |
    2.29 +     6--|   +   +   +   +   +   +   +   +   |--6
    2.30 +        |                                   |
    2.31 +     7--|   +   +   +   +   +   +   +   +   |--7
    2.32 +        |                                   |
    2.33 +     8--|   +   +   +   +   +   +   +   +   |--8
    2.34 +        |                                   |
    2.35 +        +-----------------------------------+
    2.36 +            |   |   |   |   |   |   |   |
    2.37 +            H   G   F   E   D   C   B   A
    2.38 +     * </pre>
    2.39 + *
    2.40   */
    2.41  public final class Fence extends Object {
    2.42  
    2.43 @@ -82,10 +109,10 @@
    2.44          return false;
    2.45      }
    2.46  
    2.47 -    /** The fences orientation. Either horizontal of vertical.
    2.48 +    /** The possible orientation of a {@link Fence}.
    2.49 +     * Either horizontal of vertical.
    2.50       */
    2.51      public static enum Orientation {
    2.52 -
    2.53          HORIZONTAL, VERTICAL;
    2.54  
    2.55          private Orientation() {
     3.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Move.java	Mon May 11 18:35:16 2009 +0200
     3.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Move.java	Mon May 11 18:47:39 2009 +0200
     3.3 @@ -28,7 +28,8 @@
     3.4  
     3.5  import cz.xelfi.quoridor.Player.Direction;
     3.6  
     3.7 -/**
     3.8 +/** Encapsulates one possible move that can be applied to existing {@link Board}
     3.9 + * by calling its {@link Board#apply} method.
    3.10   *
    3.11   * @author Jaroslav Tulach <jtulach@netbeans.org>
    3.12   */
     4.1 --- a/quoridor/src/main/java/cz/xelfi/quoridor/Player.java	Mon May 11 18:35:16 2009 +0200
     4.2 +++ b/quoridor/src/main/java/cz/xelfi/quoridor/Player.java	Mon May 11 18:47:39 2009 +0200
     4.3 @@ -26,7 +26,8 @@
     4.4  package cz.xelfi.quoridor;
     4.5  
     4.6  /**
     4.7 - * Defines properties (mostly position) of a player.
     4.8 + * Represents position and number of available fences of a player on
     4.9 + * a {@link Board}.
    4.10   */
    4.11  public final class Player extends Object {
    4.12  
     5.1 --- a/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java	Mon May 11 18:35:16 2009 +0200
     5.2 +++ b/quoridor/src/test/java/cz/xelfi/quoridor/BoardCase.java	Mon May 11 18:47:39 2009 +0200
     5.3 @@ -37,7 +37,7 @@
     5.4  
     5.5      protected BoardCase(String n) {
     5.6          super(n);
     5.7 -        board = Board.createEmptyBoard();
     5.8 +        board = Board.empty();
     5.9      }
    5.10  
    5.11      protected abstract Board move(Board b, int player, Player.Direction... where)