multi_chess_ai.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:Chess-AI 作者: lamesjim 项目源码 文件源码
def prompt_user(self):
        self.computer.print_board()
        while self.game.status < 2:
            user_move = raw_input("Make a move: ")
            while user_move not in self.game.get_moves() and user_move != "ff":
                user_move = raw_input("Please enter a valid move: ")
            if user_move == "ff":
                break;
            self.game.apply_move(user_move)
            start_time = time.time()
            self.computer.print_board()
            print("\nCalculating...\n")
            if self.game.status < 2:
                current_state = str(self.game)
                computer_move = self.computer.ab_make_move(current_state)
                PIECE_NAME = {'p': 'Pawn', 'b': 'Bishop', 'n': 'Knight', 'r': 'Rook', 'q': 'Queen', 'k': 'King'}
                print("Computer moved " + PIECE_NAME[self.game.board.get_piece(self.game.xy2i(computer_move[:2]))] + " at " + computer_move[:2] + " to " + computer_move[2:])
                self.game.apply_move(computer_move)
            self.computer.print_board()
            print("Elapsed time in sec: {time}".format(time=time.time() - start_time))
        user_move = raw_input("Game over. Play again? y/n: ")
        if user_move.lower() == "y":
            self.game = Game()
            self.computer.game = self.game
            self.prompt_user()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号