def display_char(self, index, lastmove_highlight): move = utils.peek_stack(self._ops) if move is not None: was_last_move = (index == move) if self._matrix[index] == Player.FIRST: if was_last_move and lastmove_highlight: return 'X' return 'x' elif self._matrix[index] == Player.SECOND: if was_last_move and lastmove_highlight: return 'O' return 'o' return ' '
def display_char(self, index, lastmove_highlight): move = utils.peek_stack(self._ops) if move is not None: was_last_move = (index == move) if bitops.get_bit(self.bitstrings[0], index): if was_last_move and lastmove_highlight: return 'X' return 'x' elif bitops.get_bit(self.bitstrings[1], index): if was_last_move and lastmove_highlight: return 'O' return 'o' return ' '
def compute_game_state(self): last_move = utils.peek_stack(self._ops) if last_move is not None: if self.chain_length(last_move, -1, 0) + self.chain_length(last_move, 1, 0) >= self._win_chain_length + 1 \ or self.chain_length(last_move, -1, 1) + self.chain_length(last_move, 1, -1) >= self._win_chain_length + 1 \ or self.chain_length(last_move, 1, 1) + self.chain_length(last_move, -1, -1) >= self._win_chain_length + 1 \ or self.chain_length(last_move, 0, 1) + self.chain_length(last_move, 0, -1) >= self._win_chain_length + 1: self._game_state = GameState.WON return if len(self._ops) == self._size**2: self._game_state = GameState.DRAW return self._game_state = GameState.NOT_OVER
def get_last_move(self): return utils.peek_stack(self._ops)