core.BoardState module

class BoardState(hash=None)[source]

Represents the physical board.

Variables:state (3-list (line) of 3-list (column)) – The state of the board: initialised with “0”: [[0, 0, 0], [0, 0, 0], [0, 0, 0]] uses player.order to put “1” or “2” where the players play.
Parameters:hash (int, optional) – If hash is in **kwargs, it will be used to fill the board, default is None.

Examples

emptyB = BoardState() fullB = BoardState(hash=122121121)

__eq__(other)[source]
Returns:True if self.state and other.state are equal
Return type:bool
__hash__()[source]
Returns:An integer created by the concatenation of all the cases
Return type:int

Examples

[[0, 1, 2], [3, 4, 5], [6, 7, 8]] returns 12345678

Warning

First 0 is gone!

__len__()[source]
Returns:the turn of the board: counts the 0 and deduces the turn T = 9 - nb(0)
Return type:int
__repr__()[source]
Returns:3 lines representing the board (plus one line above and one under) with X and O instead of 1 and 2
Return type:string
copy()[source]
Returns:A new identical copy of BoardState (useful for storage)
Return type:BoardState
reset()[source]

Reset self.state for a new game: to [[0, 0, 0], [0, 0, 0], [0, 0, 0]]

unhash(theHash)[source]