org.sidoh.wwf_api.game_state
Class WordsWithFriendsBoard

java.lang.Object
  extended by org.sidoh.wwf_api.game_state.Board
      extended by org.sidoh.wwf_api.game_state.WordsWithFriendsBoard
All Implemented Interfaces:
java.lang.Cloneable

public class WordsWithFriendsBoard
extends Board
implements java.lang.Cloneable

Implements the logic and layout of the WWF play board.


Nested Class Summary
protected static class WordsWithFriendsBoard.Builder
           
 
Nested classes/interfaces inherited from class org.sidoh.wwf_api.game_state.Board
Board.SlotBuilder
 
Field Summary
static int ALL_TILES_BONUS
          Bonus applied when all tiles are used
static java.lang.String BLANK_LETTER
          Character used to represent a blank tile
static int DIMENSIONS
          Size of the board
static java.util.Map<java.lang.Character,java.lang.Integer> TILE_VALUES
          A map going from tile character -> # of points that tile is worth
static java.util.List<TileBuilder> TILES
          The tiles in the bag at the start of a game.
static int TILES_PER_PLAYER
          Number of tiles each player has
 
Fields inherited from class org.sidoh.wwf_api.game_state.Board
size, storage
 
Constructor Summary
WordsWithFriendsBoard()
          Use default values.
WordsWithFriendsBoard(org.sidoh.wwf_api.types.game_state.BoardStorage storage)
           
 
Method Summary
 WordsWithFriendsBoard clone()
           
 AdjacentSlots getAdjacentSlots(int index)
          Get the slots adjacent to the specified slot.
 AdjacentSlots getAdjacentSlots(int row, int column)
          Get the slots adjacent to the specified slot
static int getColFromIndex(int index)
           
protected static int getIndexFromRowAndCol(int row, int col)
           
protected static int getLetterScore(org.sidoh.wwf_api.types.game_state.Slot slot, org.sidoh.wwf_api.types.game_state.Tile tile)
          Compute the score attributable to a single tile in a play, not counting word modifiers.
static int getLetterValue(java.lang.String letter)
          Returns the value of the provided tile.
static int getRowFromIndex(int index)
           
 org.sidoh.wwf_api.types.game_state.Slot getSlot(int index)
          Return the slot located at the provided location
 org.sidoh.wwf_api.types.game_state.Slot getSlot(int row, int column)
          Return the slot located at the provided location
protected static int getWordScore(int baseScore, java.util.List<org.sidoh.wwf_api.types.game_state.SlotModifier> modifiers)
          Apply word modifiers to a base score to determine the overall score.
protected  boolean hasAdjacentTiles(java.lang.Integer index, org.sidoh.wwf_api.types.game_state.WordOrientation orientation)
          Convenience method used to determine if a provided location has tiles placed next to it in a particular orientation (either vertical or horizontal)
protected static boolean isWordModifier(org.sidoh.wwf_api.types.game_state.SlotModifier mod)
           
 Move.Result move(Move move)
          Makes and scores move
protected static org.sidoh.wwf_api.types.game_state.WordOrientation opposite(org.sidoh.wwf_api.types.game_state.WordOrientation o)
          Convenience method for swapping horizontal/vertical.
protected  Move.Result playWord(java.util.List<org.sidoh.wwf_api.types.game_state.Tile> _tiles, int firstLetterRow, int firstLetterCol, org.sidoh.wwf_api.types.game_state.WordOrientation orientation, boolean placeTiles)
          Play a word on the board.
 Move.Result scoreMove(Move move)
          Scores a move without actually making it
 java.lang.String toString()
           
 
Methods inherited from class org.sidoh.wwf_api.game_state.Board
getSlotBuilders, getSlotSafe, getStorage, hasTiles, wordsWithFriendsBoard
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DIMENSIONS

public static final int DIMENSIONS
Size of the board

See Also:
Constant Field Values

BLANK_LETTER

public static final java.lang.String BLANK_LETTER
Character used to represent a blank tile

See Also:
Constant Field Values

TILES

public static final java.util.List<TileBuilder> TILES
The tiles in the bag at the start of a game. The first argument is the number of points that tile is worth. The second is the number of those tiles in the bag.


TILE_VALUES

public static final java.util.Map<java.lang.Character,java.lang.Integer> TILE_VALUES
A map going from tile character -> # of points that tile is worth


TILES_PER_PLAYER

public static final int TILES_PER_PLAYER
Number of tiles each player has

See Also:
Constant Field Values

ALL_TILES_BONUS

public static final int ALL_TILES_BONUS
Bonus applied when all tiles are used

See Also:
Constant Field Values
Constructor Detail

WordsWithFriendsBoard

public WordsWithFriendsBoard()
Use default values.


WordsWithFriendsBoard

public WordsWithFriendsBoard(org.sidoh.wwf_api.types.game_state.BoardStorage storage)
Parameters:
storage - the board
Method Detail

getAdjacentSlots

public AdjacentSlots getAdjacentSlots(int row,
                                      int column)
Get the slots adjacent to the specified slot

Parameters:
row -
column -
Returns:

getAdjacentSlots

public AdjacentSlots getAdjacentSlots(int index)
Get the slots adjacent to the specified slot.

Parameters:
index - the index of the tile. row and column are determined mathematically from the index
Returns:

clone

public WordsWithFriendsBoard clone()
Overrides:
clone in class java.lang.Object
Returns:

getSlot

public org.sidoh.wwf_api.types.game_state.Slot getSlot(int row,
                                                       int column)
Return the slot located at the provided location

Parameters:
row -
column -
Returns:

getSlot

public org.sidoh.wwf_api.types.game_state.Slot getSlot(int index)
Return the slot located at the provided location

Overrides:
getSlot in class Board
Parameters:
index -
Returns:

move

public Move.Result move(Move move)
Makes and scores move

Parameters:
move -
Returns:

scoreMove

public Move.Result scoreMove(Move move)
Scores a move without actually making it

Parameters:
move -
Returns:

playWord

protected Move.Result playWord(java.util.List<org.sidoh.wwf_api.types.game_state.Tile> _tiles,
                               int firstLetterRow,
                               int firstLetterCol,
                               org.sidoh.wwf_api.types.game_state.WordOrientation orientation,
                               boolean placeTiles)
Play a word on the board. No validiation is done to determine whether or not the play is legal or if the resulting words are in a particular dicitonary.

Parameters:
_tiles - the tiles to play
firstLetterRow - the row the first tile is played in
firstLetterCol - the column the first tile is played in
orientation - orientation of the play (either vertical or horizontal)
placeTiles - if true, modify the board state
Returns:
the result of the move. includes score, resulting words, etc.

hasAdjacentTiles

protected boolean hasAdjacentTiles(java.lang.Integer index,
                                   org.sidoh.wwf_api.types.game_state.WordOrientation orientation)
Convenience method used to determine if a provided location has tiles placed next to it in a particular orientation (either vertical or horizontal)

Parameters:
index - location in question
orientation - vertical/horizontal
Returns:
true if the provided location has any tiles next to it

getWordScore

protected static int getWordScore(int baseScore,
                                  java.util.List<org.sidoh.wwf_api.types.game_state.SlotModifier> modifiers)
Apply word modifiers to a base score to determine the overall score.

Parameters:
baseScore - score based only on tile scores (this includes non-word modifiers)
modifiers - list of word modifiers applying to a word
Returns:
score after modifiers are applied

getLetterScore

protected static int getLetterScore(org.sidoh.wwf_api.types.game_state.Slot slot,
                                    org.sidoh.wwf_api.types.game_state.Tile tile)
Compute the score attributable to a single tile in a play, not counting word modifiers.

Parameters:
slot - the slot the tile is to be placed in
tile - the tile to be played
Returns:
score earned by the tile

isWordModifier

protected static boolean isWordModifier(org.sidoh.wwf_api.types.game_state.SlotModifier mod)
Parameters:
mod - modifier in question
Returns:
true if the provided modifier is a word modifier

opposite

protected static org.sidoh.wwf_api.types.game_state.WordOrientation opposite(org.sidoh.wwf_api.types.game_state.WordOrientation o)
Convenience method for swapping horizontal/vertical. Since WordOrientation is a thrift type, we can't add this method there.

Parameters:
o -
Returns:

getRowFromIndex

public static int getRowFromIndex(int index)
Parameters:
index - a location on the board
Returns:
the row the location refers to

getColFromIndex

public static int getColFromIndex(int index)
Parameters:
index - a location on the board
Returns:
the column the location referrs to

getIndexFromRowAndCol

protected static int getIndexFromRowAndCol(int row,
                                           int col)
Parameters:
row -
col -
Returns:
the index of the specified location

getLetterValue

public static int getLetterValue(java.lang.String letter)
Returns the value of the provided tile. For instance, A -> 1.

Parameters:
letter -
Returns:

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
a printable representation of the board