player.gamer.statemachine.sadna

## Class Board

- java.lang.Object
- - player.gamer.statemachine.sadna.Board

-     public class Board
      extends java.lang.Object

  Represent Connect Four game board

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `Board.LineType`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `ATTR_VEC_SIZE`
    `static int` | `DISTANCE_FROM_CENTER`
    `static int` | `DOUBLE_THREAT`
    `static int` | `FOUR_COINS_INDEX`
    `static int` | `HEIGHT`
    `static int` | `IMMEDIATE_THREAT`
    `static int` | `ONE_COIN_INDEX`
    `static int` | `THREE_COLUMN_INDEX`
    `static int` | `THREE_EVEN_INDEX`
    `static int` | `THREE_ODD_INDEX`
    `static int` | `TWO_COINS_INDEX`
    `static int` | `WIDTH`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Board()`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int[]` | `calclateAttributeVector()` Go over the board and calculate the attributes vector.
    `boolean` | `didWin()`
    `boolean` | `forcedMoveExists(int column, Coin coin)` Calculate if forced moved exists on the board.
    `Coin` | `getCoin(int column, int row)`
    `int` | `getHeight(int column)`
    `void` | `removeCoin(int column)`
    `void` | `setCoin(int column, Coin coin)`
    `void` | `setDidWin(boolean didWin)`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### ATTR_VEC_SIZE

          public static final int ATTR_VEC_SIZE

      See Also:
        Constant Field Values

    - #### HEIGHT

          public static final int HEIGHT

      See Also:
        Constant Field Values

    - #### WIDTH

          public static final int WIDTH

      See Also:
        Constant Field Values

    - #### FOUR_COINS_INDEX

          public static final int FOUR_COINS_INDEX

      See Also:
        Constant Field Values

    - #### THREE_EVEN_INDEX

          public static final int THREE_EVEN_INDEX

      See Also:
        Constant Field Values

    - #### THREE_ODD_INDEX

          public static final int THREE_ODD_INDEX

      See Also:
        Constant Field Values

    - #### THREE_COLUMN_INDEX

          public static final int THREE_COLUMN_INDEX

      See Also:
        Constant Field Values

    - #### TWO_COINS_INDEX

          public static final int TWO_COINS_INDEX

      See Also:
        Constant Field Values

    - #### ONE_COIN_INDEX

          public static final int ONE_COIN_INDEX

      See Also:
        Constant Field Values

    - #### DISTANCE_FROM_CENTER

          public static final int DISTANCE_FROM_CENTER

      See Also:
        Constant Field Values

    - #### IMMEDIATE_THREAT

          public static final int IMMEDIATE_THREAT

      See Also:
        Constant Field Values

    - #### DOUBLE_THREAT

          public static final int DOUBLE_THREAT

      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### Board

          public Board()

  - ### Method Detail

    - #### setCoin

          public void setCoin(int column,
                     Coin coin)

      Parameters:
        `column` - The column to drop the coin in
        `coin` - Player coin or Opponent coin

    - #### removeCoin

          public void removeCoin(int column)

      Parameters:
        `column` - The column the highest coin should be removed from

    - #### getCoin

          public Coin getCoin(int column,
                     int row)

    - #### getHeight

          public int getHeight(int column)

      Returns:
        The row of the first available square in the given column

    - #### forcedMoveExists

          public boolean forcedMoveExists(int column,
                                 Coin coin)

      Calculate if forced moved exists on the board. Force move exists if putting the given coin in the given column will win the game - the coin will complete 4 in a row, column or diagonal.
      Parameters:
        `column` - The column the coin is played on
        `coin` - The next coin to play
      Returns:
        True if force move exists, otherwise false

    - #### setDidWin

          public void setDidWin(boolean didWin)

    - #### didWin

          public boolean didWin()

    - #### calclateAttributeVector

          public int[] calclateAttributeVector()

      Go over the board and calculate the attributes vector. Every 4 adjacent squares are tested to see if they hold one of the attributes. For example, this situation: _ _ O O O _ _ _ will be counted as: 2 coins in a row (for the first 4 squares), 3 coins in a row (for the second 4 squares), 3 coins in a row, 2 coins in a row and one coin in a row. Also, three times one coin in a column. This situation: X O O O X (where X is Red coin and O is black coin) however will not be counted as three in a row - since the black coins are blocked.
      Returns:
        Attributes vector, every index holds the number of times the attribute appears on the board