Package edu.wisc.game.sql

## Class Board

- java.lang.Object
- - edu.wisc.game.sql.Board

-     @Entity
      public class Board
      extends Object

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `static class` | `Board.Pos` | Can be used to describe the position of a piece on the [1:N]x[1:N] grid, or that of a bucket (at (0,0), ...

  - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `static Board.Pos[]` | `buckets` | The positions of the 4 buckets
    `static int` | `N` |

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Board()` | Creates an empty board
    `Board​(RandomRG random, int randomCnt, ImageObject.Generator imageGenerator)` | The main constructor for a random image-and-property-based initial board in GS 3.*.
    `Board​(RandomRG random, edu.wisc.game.sql.PositionMask positionMask, int randomCnt, boolean crowded)` | The simple constructor, creates a random board with a given number of pieces, using the 4 legacy colors.
    `Board​(RandomRG random, edu.wisc.game.sql.PositionMask positionMask, int randomCnt, int nShapes, int nColors, Piece.Shape[] allShapes, Piece.Color[] allColors, boolean crowded)` | The main constructor for a random initial board in GS 2.*.
    `Board​(Vector<Piece> pieces, Vector<Piece> removedPieces, BitSet[] moveableTo)` | Creates a Board object to be sent out (as JSON) to the player's client, based on the current state of the episode.

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addPiece​(Piece c)` |
    `Piece[]` | `asBoardPieces()` | Produces an array of pieces with N*N elements, with nulls for empty cells.
    `void` | `checkShapesAndColors​(ColorMap cm)` | Checking that a board description does not include any colors or shapes that cannot be displayed
    `static int` | `findBucketId​(Board.Pos p)` | Which bucket is in this position?
    `long` | `getId()` |
    `String` | `getName()` |
    `Vector<Piece>` | `getValue()` |
    `long` | `persistNewBoard()` | We aren't actually using SQL server to store boards, even though we have support for this
    `static Board` | `readBoard​(File f)` | Reads a board description from a JSON file
    `static Board` | `readBoard​(Reader r)` |
    `static Board` | `readBoardFromString​(String jsonText)` |
    `void` | `removePiece​(Piece c)` |
    `void` | `scrubDropped()` | Removes the "dropped" field from all game pieces.
    `void` | `setId​(long _id)` |
    `void` | `setName​(String _name)` |
    `void` | `setValue​(Vector<Piece> _value)` |
    `static int` | `xynum​(int x, int y)` | The position number for the point at (x,y)

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

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

- - ### Field Detail

    - #### N

          public static final int N

      See Also:
        Constant Field Values

    - #### buckets

          public static final Board.Pos[] buckets

      The positions of the 4 buckets

  - ### Constructor Detail

    - #### Board

          public Board()

      Creates an empty board

    - #### Board

          public Board​(RandomRG random,
                       edu.wisc.game.sql.PositionMask positionMask,
                       int randomCnt,
                       boolean crowded)

      The simple constructor, creates a random board with a given number of pieces, using the 4 legacy colors.

    - #### Board

          public Board​(RandomRG random,
                       edu.wisc.game.sql.PositionMask positionMask,
                       int randomCnt,
                       int nShapes,
                       int nColors,
                       Piece.Shape[] allShapes,
                       Piece.Color[] allColors,
                       boolean crowded)

      The main constructor for a random initial board in GS 2.*.
      Parameters:
        `random` - The random number generator to use
        `positionMask` - This may restrict the positions to which game pieces may be placed
        `randomCnt` - required number of pieces.
        `nShapes` - required number of shapes. If 0 is passed, there is no restriction (independent decision is made for each piece)
        `nColors` - required number of colors. If 0 is passed, there is no restriction (independent decision is made for each piece)
        `allShapes` - the set from which shapes are drawn
        `allColors` - the set from which colors are drawn

    - #### Board

          public Board​(RandomRG random,
                       int randomCnt,
                       ImageObject.Generator imageGenerator)

      The main constructor for a random image-and-property-based initial board in GS 3.*.
      Parameters:
        `randomCnt` - required number of pieces.
        `allImages` - the set from which images are drawn

    - #### Board

          public Board​(Vector<Piece> pieces,
                       Vector<Piece> removedPieces,
                       BitSet[] moveableTo)

      Creates a Board object to be sent out (as JSON) to the player's client, based on the current state of the episode.
      Parameters:
        `pieces` - The pieces still on the board. (A dense array). with nulls)
        `removedPieces` - If not null, these pieces will also be included into the generated Board object, with the flag dropped=true. This is what the GUI client wants.
        `moveableTo` - Specifies to which buckets each piece can be moved to. Coordinayed with "pieces"

  - ### Method Detail

    - #### xynum

          public static int xynum​(int x,
                                  int y)

      The position number for the point at (x,y)

    - #### findBucketId

          public static int findBucketId​(Board.Pos p)

      Which bucket is in this position?

    - #### addPiece

          public void addPiece​(Piece c)

    - #### removePiece

          public void removePiece​(Piece c)

    - #### getId

          public long getId()

    - #### setId

          public void setId​(long _id)

    - #### getName

          public String getName()

    - #### setName

          public void setName​(String _name)

    - #### getValue

          public Vector<Piece> getValue()

    - #### setValue

          public void setValue​(Vector<Piece> _value)

    - #### asBoardPieces

          public Piece[] asBoardPieces()

      Produces an array of pieces with N*N elements, with nulls for empty cells. Used in BoardDisplayService only.

    - #### persistNewBoard

          public long persistNewBoard()

      We aren't actually using SQL server to store boards, even though we have support for this

    - #### readBoard

          public static Board readBoard​(File f)
                                 throws IOException,
                                        ReflectiveOperationException

      Reads a board description from a JSON file
      Throws:
        `IOException`
        `ReflectiveOperationException`

    - #### readBoardFromString

          public static Board readBoardFromString​(String jsonText)
                                           throws IOException,
                                                  ReflectiveOperationException

      Throws:
        `IOException`
        `ReflectiveOperationException`

    - #### readBoard

          public static Board readBoard​(Reader r)
                                 throws IOException,
                                        ReflectiveOperationException

      Throws:
        `IOException`
        `ReflectiveOperationException`

    - #### checkShapesAndColors

          public void checkShapesAndColors​(ColorMap cm)
                                    throws IOException

      Checking that a board description does not include any colors or shapes that cannot be displayed
      Throws:
        `IOException`

    - #### scrubDropped

          public void scrubDropped()

      Removes the "dropped" field from all game pieces. This method can be used when an already-played board is to be reused (e.g. in a PredefinedBoardGameGenerator)