Exemple #1
0
  def take(self, state):
    """Changes the state of the cell to taken by either player.

    Allows the caller to change the state of this cell to any state defined
    in the board.state module (except for State.EMPTY). If the specified state
    is not defined in the baord.state module, or the state is State.EMPTY,
    this will raise an exception to be hadled by the caller.

    Args:
      state: Any state defined in the board.State module.

    Raises:
      IllegalStateChangeException: Raised if the caller tries to change the
        state on a taken cell, changes the state to empty, or if the state is
        not a known state.
    """
    logging.debug('Attempting to change state from %s to %s',
                  self.state, state)
    if self.state != State.EMPTY:
      raise IllegalStateChangeException('Cannot change state of taken cell.')
    elif state == State.EMPTY:
      raise IllegalStateChangeException('Cannot take with empty state')
    elif State.is_def(state):
      self.state = state
    else:
      raise IllegalStateChangeException('State %s is undefined' % state)
Exemple #2
0
 def testIsDefWithValidStates(self):
  self.assertTrue(State.is_def(State.TAKEN_X))
  self.assertTrue(State.is_def(State.TAKEN_O))
  self.assertFalse(State.is_def('foo_player'))