コード例 #1
0
ファイル: Game.py プロジェクト: techlover10/PentAI
    def play(self, r, c):
        if r < 0 or r > 18 or c < 0 or c > 18:
            print("Invalid position specified!")
            print("Player " + str(self.current_turn) + "'s turn!")
            return

        if not self.board.spot_empty(r, c):
            print("Position is occupied!")
            print("Player " + str(self.current_turn) + "'s turn!")
            return

        self.past_board = deepcopy(self.board)

        self.board.play(self.current_turn, r, c)

        self.board_verify()  # Verify the current board

        if Logic.check_win(self.board, r, c, self.current_turn):
            print("Player " + str(self.current_turn) + ' wins!')
            self.winner = self.current_turn
            other_player = 1 if self.current_turn is 2 else 2
            if self.agents[other_player] and self.agents[
                    other_player].is_learning:
                self.agents[other_player].update_heuristic_vals(self.board,
                                                                self.winner,
                                                                win=True)
            print("Game ended.")
            self.has_win = True
            return

        self.current_turn = 2 if self.current_turn is 1 else 1
        if not self.run_game():
            print("Player " + str(self.current_turn) + "'s turn!")