core.Game module

class Game[source]

Main object, registers the Board and the Players.

Variables:
  • boardAR (BoardAndRules) – Reference to the main BoardAndRules instance
  • and player2 (player1) – References to the players
  • and nextPlayer (lastPlayer) – References to player1 and player2, are exchanged between the turns
  • movements (list of Movement) – the chronological list of Movement() played
  • states (list of BoardStates) – the chronological list of BoardStates()
  • turn (int) – The present turn of the game, initialised at 0, first turn must be 1 (modified in start() )
  • movements – the list of all the Movements made
  • states – the list of the different BoardState of the game
  • winner (Player or None) – Defined by BoardAndRules.thereIsAWinner(), stays None is there is none
  • interactionLevel (InteractionLevel) – used to define the level of printed outputs

Warning

movements and states must be updated by boardAR.play()

reset()[source]

Resets the game for a new game

Resets turn, movements, sates, winner, next and last player Calls boardAR.reset()

start()[source]

Plays a game until it is over, i.e. there is a winner or the game is even

How it is working:

As long as the game is not over (ie self.turn < 9 and thereIsAWinner == False) there is a loop where:

  • turn is incremented,
  • nextPlayer.play() is called and then next and last player are inverted,
  • if wanted, the board is printed.

When it is over, meth:.Player.endOfGame() of player1 and player2 is called - if wanted, the result is printed.