core.BoardAndRules module

class BoardAndRules(game)[source]

Represents the rules of the game, saves the present state of the game and checks that the players follow the rules.

Variables:
  • game (Game) – A reference to the game.
  • boardS (BoardState) – Represents the present physical board.
extractLines()[source]

Extracts the 8 lines than can be completed:

  • 3 vertical: left -> right,
  • 3 horizontal: up -> down,
  • 2 diagonal: 11->33 & 31->13.
Returns:The list of lines
Return type:list of list
getBoard()[source]
Returns:a copy of the self.board that will not be updated when a new movement is made
Return type:BoardState
play(mvt)[source]

Verifies that the movement of the player follows the rules and writes it on the board.

Also sets Movement.turn and registers the movement in the list Game.movements Registers boardS in Game.states

Parameters:mvt (Movement) – The Movement the player wants to play
Returns:True if the movement is possible, else False
Return type:bool
reset()[source]

Resets the state for a new game

thereIsAWinner()[source]

Sets Game.winner if there is one.

Returns:True if there is a winner (ie if 3 dots are aligned), else False
Return type:bool