Package connectfour.core
Class BitBoard
java.lang.Object
connectfour.core.BitBoard
- All Implemented Interfaces:
Board
An immutable implementation of the Board interface that uses bit-shifting to
store the whole board state in two longs. It takes up very little memory and
most of its operations are very fast.
- Author:
- Finn Voichick
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancanPlay(int column)Determines if it is legal for the current player to play a piece in the given column.createNextBoard(int column)Creates a new Board object that contains one additional piece.booleanget(BoardLocation location)Gets the player who has played at the given location.Gets the player who is currently up to play.longgetKey()Gets a key that uniquely identifies this board.intGets the number of turns that have been played since the start of the game.Gets a set of columns that are valid plays for the current player.Gets the player who has won the game.inthashCode()booleanisFull()Determines whether or not this board is completely full.toString()Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface connectfour.core.Board
isGameOngoing, isGameOver
-
Constructor Details
-
BitBoard
public BitBoard()Constructs an empty BitBoard, with no pieces on the board. -
BitBoard
Constructs a BitBoard with the moves represented by the given string. The moves are represented as described by Pascal Pons here: http://blog.gamesolver.org/solving-connect-four/02-test-protocol/- Parameters:
moves- a string representing the moves that have been played so far
-
-
Method Details
-
get
Description copied from interface:BoardGets the player who has played at the given location. If nobody has played at the given location, this method returns empty. -
getCurrentPlayer
Description copied from interface:BoardGets the player who is currently up to play. This will be the opponent of the player who has just played.- Specified by:
getCurrentPlayerin interfaceBoard- Returns:
- the player whose turn it is
-
canPlay
public boolean canPlay(int column)Description copied from interface:BoardDetermines if it is legal for the current player to play a piece in the given column. A column is a legal play if it is not full. -
getValidPlays
Description copied from interface:BoardGets a set of columns that are valid plays for the current player. In other words, this set contains all integers for which theBoard.canPlay(int)method would return true.- Specified by:
getValidPlaysin interfaceBoard- Returns:
- the set of all valid moves for the current player
-
createNextBoard
Description copied from interface:BoardCreates a new Board object that contains one additional piece. The current player of this next board will be the opponent of the current board.- Specified by:
createNextBoardin interfaceBoard- Parameters:
column- the column in which to play- Returns:
- the new board
-
getWinner
Description copied from interface:BoardGets the player who has won the game. If nobody has won, empty is returned. -
getTurnsPlayed
public int getTurnsPlayed()Description copied from interface:BoardGets the number of turns that have been played since the start of the game. For an empty board, this will return 0. If one player has played, this will return 1. In other words, this is equivalent to the number of pieces on the board.- Specified by:
getTurnsPlayedin interfaceBoard- Returns:
- the number of turns that have been played since the start of the game
-
isFull
public boolean isFull()Description copied from interface:BoardDetermines whether or not this board is completely full. A board is full if each of its columns is full, andBoard.getValidPlays()would return an empty set. -
getKey
public long getKey()Gets a key that uniquely identifies this board.- Returns:
- a unique long representing this board
-
toString
-
equals
-
hashCode
public int hashCode()
-