Exemplo n.º 1
0
 def __init__(self):
     self.board = ChessBoard()
     self.view = ChessView(self)
     self.view.showMsg("Red")
     self.view.draw_board(self.board)
     self.player_is_red = True
     self.ai = AI()
Exemplo n.º 2
0
    def __init__(self, in_ai_count, in_ai_function, in_play_playout, in_delay, in_end_delay, batch_size, search_threads,
                 processor, num_gpus, res_block_nums, human_color = "b"):
        self.human_color = human_color
        self.current_player = "w"
        self.players = {}
        self.players[self.human_color] = "human"
        ai_color = "w" if self.human_color == "b" else "b"
        self.players[ai_color] = "AI"

        ChessGame.board = ChessBoard(self.human_color == 'b')
        self.view = ChessView(self, board=ChessGame.board)
        self.view.showMsg("Loading Models...")    #"Red"    player_color
        self.view.draw_board(self.board)
        ChessGame.game_mode = in_ai_count
        self.ai_function = in_ai_function
        self.play_playout = in_play_playout
        self.delay = in_delay
        self.end_delay = in_end_delay

        self.win_rate = {}
        self.win_rate['w'] = 0.0
        self.win_rate['b'] = 0.0

        self.view.root.update()
        self.cchess_engine = cchess_main(playout=self.play_playout, in_batch_size=batch_size, exploration=False, in_search_threads=search_threads,
                                         processor=processor, num_gpus=num_gpus, res_block_nums=res_block_nums, human_color=human_color)
Exemplo n.º 3
0
class ChessGame:

    board = ChessBoard()
    player_is_red = True
    def __init__(self):
        self.view = ChessView(self)
        self.view.showMsg("Red")
        self.view.draw_board(self.board)

    def start(self):
        self.view.start()

    def callback(self, event):
        print event.x, event.y
        rx, ry = real_coord(event.x), real_coord(event.y)
        if self.board.select(rx, ry, self.player_is_red):
            self.player_is_red = not self.player_is_red
            self.view.showMsg("Red" if self.player_is_red else "Green")
        self.view.draw_board(self.board)
Exemplo n.º 4
0
    def __init__(self,
                 mode=1,
                 dis=0,
                 showMove=True,
                 showSearch=False,
                 showGUI=True,
                 saveInfo=False):
        self.board = ChessBoard()
        self.Player_Side = False
        self.GameMode = mode
        self.distribution = dis

        self.ai_0 = AI()
        self.ai_1 = AI()

        self.ShowMoveInfo = showMove
        self.ShowSearchInfo = showSearch
        self.ShowGraphUI = showGUI
        self.SaveInfo = saveInfo

        self.view = ChessView(self)
Exemplo n.º 5
0
 def __init__(self):
     self.view = ChessView(self)
     self.view.showMsg("Red")
     self.view.draw_board(self.board)
Exemplo n.º 6
0
class ChessGame:
    def __init__(self):
        self.board = ChessBoard()
        self.view = ChessView(self)
        self.view.showMsg("Red")
        self.view.draw_board(self.board)
        self.player_is_red = True
        self.ai = AI()

    def start(self):
        self.view.start()

    def callback(self, event):
        rx, ry = Tools.real_coord(event.x), Tools.real_coord(event.y)
        if self.board.select(rx, ry, self.player_is_red):
            self.player_is_red = not self.player_is_red
            self.view.showMsg("Green")
        self.view.draw_board(self.board)

        if not self.player_is_red:
            # the round of AI
            list_step = self.ai.find_next_step(self.board, 2, sys.maxsize)
            self.board.select(list_step[1][0][0], list_step[1][0][1],
                              self.player_is_red)
            self.board.select(list_step[1][0][0] + list_step[1][0][2],
                              list_step[1][0][1] + list_step[1][0][3],
                              self.player_is_red)
            self.player_is_red = not self.player_is_red
            self.view.showMsg("Red")
            self.view.draw_board(self.board)
Exemplo n.º 7
0
 def setSceneAndView(self):
     self.view = ChessView()
Exemplo n.º 8
0
class ChessGame:

    board = None    #ChessBoard()
    cur_round = 1
    game_mode = 1  # 0:HUMAN VS HUMAN 1:HUMAN VS AI 2:AI VS AI
    time_red = []
    time_green = []

    def __init__(self, in_ai_count, in_ai_function, in_play_playout, in_delay, in_end_delay, batch_size, search_threads,
                 processor, num_gpus, res_block_nums, human_color = "b"):
        self.human_color = human_color
        self.current_player = "w"
        self.players = {}
        self.players[self.human_color] = "human"
        ai_color = "w" if self.human_color == "b" else "b"
        self.players[ai_color] = "AI"

        ChessGame.board = ChessBoard(self.human_color == 'b')
        self.view = ChessView(self, board=ChessGame.board)
        self.view.showMsg("Loading Models...")    #"Red"    player_color
        self.view.draw_board(self.board)
        ChessGame.game_mode = in_ai_count
        self.ai_function = in_ai_function
        self.play_playout = in_play_playout
        self.delay = in_delay
        self.end_delay = in_end_delay

        self.win_rate = {}
        self.win_rate['w'] = 0.0
        self.win_rate['b'] = 0.0

        self.view.root.update()
        self.cchess_engine = cchess_main(playout=self.play_playout, in_batch_size=batch_size, exploration=False, in_search_threads=search_threads,
                                         processor=processor, num_gpus=num_gpus, res_block_nums=res_block_nums, human_color=human_color)

    def player_is_red(self):
        return self.current_player == "w"

    def start(self):
        # below added by Fei Li
        self.view.showMsg("Red")
        if self.game_mode == 1:
            print ('-----Round %d-----' % self.cur_round)
            if self.players["w"] == "AI":
                self.win_rate['w'] = self.perform_AI()
                self.view.draw_board(self.board)
                self.change_player()
        elif self.game_mode == 2:
            print('-----Round %d-----' % self.cur_round)
            self.win_rate['w'] = self.perform_AI()
            self.view.draw_board(self.board)

        self.view.start()

    def disp_mcts_msg(self):
        self.view.showMsg("MCTS Searching...")

    def callback(self, event):
        if self.game_mode == 1 and self.players[self.current_player] == "AI":
            return
        if self.game_mode == 2:
            return
        rx, ry = real_coord(event.x), real_coord(event.y)
        # print(rx, ry)
        change, coord = self.board.select(rx, ry, self.player_is_red())
        if self.view.print_text_flag == True:
            self.view.print_text_flag = False
            self.view.can.create_image(0, 0, image=self.view.img, anchor=tkinter.NW)
        self.view.draw_board(self.board)
        if self.check_end():
            self.view.root.update()
            self.quit()
            return
        if change:
            if self.cur_round == 1 and self.human_color == 'w':
                self.view.showMsg("MCTS Searching...")

            self.win_rate[self.current_player] = self.cchess_engine.human_move(coord, self.ai_function)
            if self.check_end():
                self.view.root.update()
                self.quit()
                return
            performed = self.change_player()
            if performed:
                self.view.draw_board(self.board)
                if self.check_end():
                    self.view.root.update()
                    self.quit()
                    return
                self.change_player()


    # below added by Fei Li

    def quit(self):
        time.sleep(self.end_delay)
        self.view.quit()

    def check_end(self):
        ret, winner = self.cchess_engine.check_end()
        if ret == True:
            if winner == "b":
                self.view.showMsg('*****Green Wins at Round %d*****' % self.cur_round)
                self.view.root.update()
            elif winner == "w":
                self.view.showMsg('*****Red Wins at Round %d*****' % self.cur_round)
                self.view.root.update()
            elif winner == "t":
                self.view.showMsg('*****Draw at Round %d*****' % self.cur_round)
                self.view.root.update()
        return ret

    def _check_end(self, board):
        red_king = False
        green_king = False
        pieces = board.pieces
        for (x, y) in pieces.keys():
            if pieces[x, y].is_king:
                if pieces[x, y].is_red:
                    red_king = True
                else:
                    green_king = True
        if not red_king:
            self.view.showMsg('*****Green Wins at Round %d*****' % self.cur_round)
            self.view.root.update()
            return True
        elif not green_king:
            self.view.showMsg('*****Red Wins at Round %d*****' % self.cur_round)
            self.view.root.update()
            return True
        elif self.cur_round >= 200:
            self.view.showMsg('*****Draw at Round %d*****' % self.cur_round)
            self.view.root.update()
            return True
        return False

    def change_player(self):
        self.current_player = "w" if self.current_player == "b" else "b"
        if self.current_player == "w":
            self.cur_round += 1
            print ('-----Round %d-----' % self.cur_round)
        red_msg = " ({:.4f})".format(self.win_rate['w'])
        green_msg = " ({:.4f})".format(self.win_rate['b'])
        sorted_move_probs = self.cchess_engine.get_hint(self.ai_function, True, self.disp_mcts_msg)
        # print(sorted_move_probs)
        self.view.print_all_hint(sorted_move_probs)
        # self.move_images.append(tkinter.PhotoImage(file="images/OOS.gif"))
        # self.can.create_image(board_coord(x), board_coord(y), image=self.move_images[-1])

        self.view.showMsg("Red" + red_msg + " Green" + green_msg if self.current_player == "w" else "Green" + green_msg + " Red" + red_msg)
        self.view.root.update()
        # if self.game_mode == 0:
        #     return False
        if self.game_mode == 1:
            if self.players[self.current_player] == "AI":
                self.win_rate[self.current_player] = self.perform_AI()
                return True
            return False
        elif self.game_mode == 2:
            # if self.current_player == "w":
            #     self.human_win_rate = self.perform_AI()
            # else:
            self.win_rate[self.current_player] = self.perform_AI()
            return True
        return False

    def perform_AI(self):
        print ('...AI is calculating...')
        START_TIME = time.clock()
        move, win_rate = self.cchess_engine.select_move(self.ai_function)
        time_used = time.clock() - START_TIME
        print ('...Use %fs...' % time_used)
        if self.current_player == "w":
            self.time_red.append(time_used)
        else:
            self.time_green.append(time_used)
        if move is not None:
            self.board.move(move[0], move[1], move[2], move[3])
        return win_rate

    # AI VS AI mode
    def game_mode_2(self):
        self.change_player()
        self.view.draw_board(self.board)
        self.view.root.update()
        if self.check_end():
            return True
        return False
Exemplo n.º 9
0
class ChessGame:

    Distribution_Info = [
        "Standard Opening", "Single Rook Kill", "Pawn eat pawn passing by"
    ]
    Game_Mode_Info = ["Human vs Human", "Human vs AI", "AI vs AI"]

    def __init__(self,
                 mode=1,
                 dis=0,
                 showMove=True,
                 showSearch=False,
                 showGUI=True,
                 saveInfo=False):
        self.board = ChessBoard()
        self.Player_Side = False
        self.GameMode = mode
        self.distribution = dis

        self.ai_0 = AI()
        self.ai_1 = AI()

        self.ShowMoveInfo = showMove
        self.ShowSearchInfo = showSearch
        self.ShowGraphUI = showGUI
        self.SaveInfo = saveInfo

        self.view = ChessView(self)

    def Set(self,
            mode=1,
            dis=0,
            showMove=True,
            showSearch=False,
            showGUI=True,
            saveInfo=False,
            savePath=r".\Records",
            ai_name_0="MinMaxSearch",
            use_pos_0=False,
            depth_0=3,
            ai_name_1="MinMaxSearch",
            depth_1=3,
            use_pos_1=False):
        self.GameMode = mode
        self.distribution = dis
        self.ShowMoveInfo = showMove
        self.ShowSearchInfo = showSearch
        self.ShowGraphUI = showGUI
        self.SaveInfo = saveInfo
        self.SavePath = savePath
        self.SaveFileName = ""
        if ai_name_0 == "MinMaxSearch":
            ai_0 = MinMaxSearchAI(depth_0, True, use_pos_0)
        else:
            ai_0 = RandomMoveAI()
        if ai_name_1 == "MinMaxSearch":
            ai_1 = MinMaxSearchAI(depth_1, True, use_pos_1)
        else:
            ai_1 = RandomMoveAI()
        self.SetAI(ai_0, ai_1)

    def SetGame(self, mode=1, dis=0):
        self.GameMode = mode
        self.distribution = dis

    def SetInfo(self,
                showMove=True,
                showSearch=False,
                showGUI=True,
                saveInfo=False):
        self.ShowMoveInfo = showMove
        self.ShowSearchInfo = showSearch
        self.ShowGraphUI = showGUI
        self.SaveInfo = saveInfo

    def SetAI(self, ai_0, ai_1):
        self.ai_0 = ai_0
        self.ai_1 = ai_1

    def start(self):

        timeInfo = time.strftime('%Y-%m-%d %H:%M:%S')
        timeLabel = time.strftime('%Y-%m-%d-%H-%M-%S')

        self.SaveFileName = timeLabel + ".txt"

        Msg = timeInfo + " " \
              + ChessGame.Game_Mode_Info[self.GameMode] + " " \
              + ChessGame.Distribution_Info[self.distribution] + "\n"
        Msg_AI = ""
        if self.GameMode == 1:
            Msg_AI += str(self.ai_0) + "\n"
        elif self.GameMode == 2:
            Msg_AI += str(self.ai_0) + "\n"
            Msg_AI += str(self.ai_1) + "\n"

        print Msg + Msg_AI,
        if self.SaveInfo:
            self.SaveData(Msg + Msg_AI)

        self.board.Board_Initialization(self.distribution)

        if self.GameMode == 2:
            if not self.ShowGraphUI:
                self.Game_AIvAI_Auto(self.ai_0, self.ai_1)

        self.view.showMsg("Chess")
        self.view.draw_board(self.board)
        self.view.start()

    def callback(self, event):
        rx, ry = real_coord(event.x), real_coord(800 - event.y)
        self.Game(rx, ry, self.GameMode)

    def Move_Info(self, move_info):
        game_info = {
            0: "",
            1: " #",
            2: " #",
            3: " Stalemate",
            4: " Draw",
            5: " Perpetual check"
        }
        return "(" + str(self.board.Round) + "):" + move_info \
        + game_info[self.board.Status] \
        + ("; " if self.Player_Side else ";\n")

    def SaveData(self, info):
        fileName = self.SavePath + r'\chess-' + self.SaveFileName
        with open(fileName, 'a') as data:
            data.write(info)

    def Game(self, x, y, mode=0):
        if mode == 0:
            self.Game_PvP(x, y)
        elif mode == 1:
            self.Game_PvAI(x, y)
        elif mode == 2:
            self.Game_AIvAI(self.ai_0, self.ai_1)
        else:
            raise Exception("Invalid game mode: " + str(mode))

    def Game_PvP(self, rx, ry):
        if self.board.Status != 0:
            return
        move_info = self.board.select(rx, ry, self.Player_Side)
        if move_info != "":
            self.view.showMsg(
                "White turn" if self.Player_Side else "Black turn")
            self.Player_Side = not self.Player_Side
            self.board.Round += 1
            self.board.UpdateStatu()
            if self.ShowMoveInfo:
                print self.Move_Info(move_info),
                if self.SaveInfo:
                    self.SaveData(self.Move_Info(move_info))
        self.view.draw_board(self.board)

    def Game_PvAI(self, rx, ry):
        if self.board.Status != 0:
            return
        move_info = self.board.select(rx, ry, self.Player_Side)
        self.view.draw_board(self.board)
        if move_info != "":
            self.view.showMsg(
                "White turn" if self.Player_Side else "Black turn")
            self.Player_Side = not self.Player_Side
            self.board.Round += 1
            self.board.UpdateStatu()
            if self.ShowMoveInfo:
                print self.Move_Info(move_info),
                if self.SaveInfo:
                    self.SaveData(self.Move_Info(move_info))
            self.view.draw_board(self.board)

            if self.board.Status != 0:
                return

            move, msg = self.ai_0.Play(self.board, self.Player_Side)
            self.board.select(move[0][0], move[0][1], self.Player_Side)
            move_info = self.board.select(move[1][0], move[1][1],
                                          self.Player_Side)
            self.view.showMsg(
                "White turn" if self.Player_Side else "Black turn")
            self.Player_Side = not self.Player_Side
            self.board.Round += 1
            self.board.UpdateStatu()
            if self.ShowSearchInfo:
                print msg,
                if self.SaveInfo:
                    self.SaveData(msg + " ")
            if self.ShowMoveInfo:
                print self.Move_Info(move_info),
                if self.SaveInfo:
                    self.SaveData(self.Move_Info(move_info))
            self.view.draw_board(self.board)

    def Game_AIvAI(self, ai_0, ai_1):
        if self.board.Status != 0:
            return
        if self.Player_Side == False:
            ai_0.Clear()
            move, msg = ai_0.Play(self.board, self.Player_Side)
        else:
            ai_1.Clear()
            move, msg = ai_1.Play(self.board, self.Player_Side)
        self.board.select(move[0][0], move[0][1], self.Player_Side)
        move_info = self.board.select(move[1][0], move[1][1], self.Player_Side)
        self.view.showMsg("White turn" if self.Player_Side else "Black turn")
        self.Player_Side = not self.Player_Side
        self.board.Round += 1
        self.board.UpdateStatu()
        if self.ShowSearchInfo:
            print msg,
            if self.SaveInfo:
                self.SaveData(msg + " ")
        if self.ShowMoveInfo:
            print self.Move_Info(move_info),
            if self.SaveInfo:
                self.SaveData(self.Move_Info(move_info))
        self.view.draw_board(self.board)

    def Game_AIvAI_Auto(self, ai_0, ai_1):
        while self.board.Status == 0:
            ai_0.Clear()
            move, msg = ai_0.Play(self.board, self.Player_Side)
            self.board.select(move[0][0], move[0][1], self.Player_Side)
            move_info = self.board.select(move[1][0], move[1][1],
                                          self.Player_Side)
            self.view.showMsg(
                "White turn" if self.Player_Side else "Black turn")
            self.Player_Side = not self.Player_Side
            self.board.Round += 1
            self.board.UpdateStatu()
            if self.ShowSearchInfo:
                print msg,
                if self.SaveInfo:
                    self.SaveData(msg + " "),
            if self.ShowMoveInfo:
                print self.Move_Info(move_info),
                if self.SaveInfo:
                    self.SaveData(self.Move_Info(move_info))

            if self.board.Status != 0:
                self.SaveData("\n")
                print ""
                break

            ai_1.Clear()
            move, msg = ai_1.Play(self.board, self.Player_Side)
            self.board.select(move[0][0], move[0][1], self.Player_Side)
            move_info = self.board.select(move[1][0], move[1][1],
                                          self.Player_Side)
            self.view.showMsg(
                "White turn" if self.Player_Side else "Black turn")
            self.Player_Side = not self.Player_Side
            self.board.Round += 1
            self.board.UpdateStatu()
            if self.ShowSearchInfo:
                print msg,
                if self.SaveInfo:
                    self.SaveData(msg + " ")
            if self.ShowMoveInfo:
                print self.Move_Info(move_info),
                if self.SaveInfo:
                    self.SaveData(self.Move_Info(move_info))

        print self.board
        print self.board.Status
        if self.SaveInfo:
            self.SaveData(str(self.board) + "\n")
            self.SaveData(str(self.board.Status) + "\n")
Exemplo n.º 10
0
class ChessGame:

    board = None    #ChessBoard()
    cur_round = 1
    game_mode = 1  # 0:HUMAN VS HUMAN 1:HUMAN VS AI 2:AI VS AI
    time_red = []
    time_green = []

    def __init__(self, in_ai_count, in_ai_function, in_play_playout, in_delay, in_end_delay, batch_size, search_threads,
                 processor, num_gpus, res_block_nums, human_color = "b"):
        self.human_color = human_color
        self.current_player = "w"
        self.players = {}
        self.players[self.human_color] = "human"
        ai_color = "w" if self.human_color == "b" else "b"
        self.players[ai_color] = "AI"

        ChessGame.board = ChessBoard(self.human_color == 'b')
        self.view = ChessView(self, board=ChessGame.board)
        self.view.showMsg("Loading Models...")    #"Red"    player_color
        self.view.draw_board(self.board)
        ChessGame.game_mode = in_ai_count
        self.ai_function = in_ai_function
        self.play_playout = in_play_playout
        self.delay = in_delay
        self.end_delay = in_end_delay

        self.win_rate = {}
        self.win_rate['w'] = 0.0
        self.win_rate['b'] = 0.0

        self.view.root.update()
        self.cchess_engine = cchess_main(playout=self.play_playout, in_batch_size=batch_size, exploration=False, in_search_threads=search_threads,
                                         processor=processor, num_gpus=num_gpus, res_block_nums=res_block_nums, human_color=human_color)

    def player_is_red(self):
        return self.current_player == "w"

    def start(self):
        # below added by Fei Li
        self.view.showMsg("Red")
        if self.game_mode == 1:
            print ('-----Round %d-----' % self.cur_round)
            if self.players["w"] == "AI":
                self.win_rate['w'] = self.perform_AI()
                self.view.draw_board(self.board)
                self.change_player()
        elif self.game_mode == 2:
            print('-----Round %d-----' % self.cur_round)
            self.win_rate['w'] = self.perform_AI()
            self.view.draw_board(self.board)

        self.view.start()

    def disp_mcts_msg(self):
        self.view.showMsg("MCTS Searching...")

    def callback(self, event):
        if self.game_mode == 1 and self.players[self.current_player] == "AI":
            return
        if self.game_mode == 2:
            return
    
        if flag==0:
            rx, ry = real_coord(event.x), real_coord(event.y)
            change, coord = self.board.select(rx,ry, self.player_is_red())
        if flag==1:
            
            wav_num = 0
            r = sr.Recognizer()
        #启用麦克风
            mic = sr.Microphone()
            print ('录音中...')
            with mic as source:
            #降噪
                r.adjust_for_ambient_noise(source)
                mp3 = r.listen(source)
#        with open(f"00{wav_num}.wav", "wb") as f:
            with open(f"00{wav_num}.wav", "wb") as f:
            #将麦克风录到的声音保存为wav文件
                f.write(mp3.get_wav_data(convert_rate=16000))
            print('录音结束,识别中...')
            s3 = audio.audio_baidu(f"00{wav_num}.wav")
            wav_num += 1
            print(s3)
            change, coord = True,s3
            
#            s4=audio.s3
#            {
#            location = input("Your move: ")
#            if isinstance(location, str):  # for python3
#                location = [int(n, 10) for n in location.split(",")]
#            list=tuple(location) 
#            print (list)
#            }这个花括号是表示坐标的形式
#            s4=(7,9,6,7)
#            change, coord = True,list
            print (change,coord)# chessboard.py
        if self.view.print_text_flag == True:
            self.view.print_text_flag = False
            self.view.can.create_image(0, 0, image=self.view.img, anchor=tkinter.NW)
        self.view.draw_board(self.board)
        if self.check_end():
            self.view.root.update()
            self.quit()
            return
        if change:
            if self.cur_round == 1 and self.human_color == 'w':
                self.view.showMsg("MCTS Searching...")

            self.win_rate[self.current_player] = self.cchess_engine.human_move(coord, self.ai_function)
            if self.check_end():
                self.view.root.update()
                self.quit()
                return
            performed = self.change_player()
            if performed:
                self.view.draw_board(self.board)
                if self.check_end():
                    self.view.root.update()
                    self.quit()
                    return
                self.change_player()


    # below added by Fei Li

    def quit(self):
        time.sleep(self.end_delay)
        self.view.quit()

    def check_end(self):
        ret, winner = self.cchess_engine.check_end()
        if ret == True:
            if winner == "b":
                self.view.showMsg('*****Green Wins at Round %d*****' % self.cur_round)
                self.view.root.update()
            elif winner == "w":
                self.view.showMsg('*****Red Wins at Round %d*****' % self.cur_round)
                self.view.root.update()
            elif winner == "t":
                self.view.showMsg('*****Draw at Round %d*****' % self.cur_round)
                self.view.root.update()
        return ret

    def _check_end(self, board):
        red_king = False
        green_king = False
        pieces = board.pieces
        for (x, y) in pieces.keys():
            if pieces[x, y].is_king:
                if pieces[x, y].is_red:
                    red_king = True
                else:
                    green_king = True
        if not red_king:
            self.view.showMsg('*****Green Wins at Round %d*****' % self.cur_round)
            self.view.root.update()
            return True
        elif not green_king:
            self.view.showMsg('*****Red Wins at Round %d*****' % self.cur_round)
            self.view.root.update()
            return True
        elif self.cur_round >= 200:
            self.view.showMsg('*****Draw at Round %d*****' % self.cur_round)
            self.view.root.update()
            return True
        return False

    def change_player(self):
        self.current_player = "w" if self.current_player == "b" else "b"
        if self.current_player == "w":
            self.cur_round += 1
            print ('-----Round %d-----' % self.cur_round)
        red_msg = " ({:.4f})".format(self.win_rate['w'])
        green_msg = " ({:.4f})".format(self.win_rate['b'])
        sorted_move_probs = self.cchess_engine.get_hint(self.ai_function, True, self.disp_mcts_msg)
        # print(sorted_move_probs)
        self.view.print_all_hint(sorted_move_probs)
        # self.move_images.append(tkinter.PhotoImage(file="images/OOS.gif"))
        # self.can.create_image(board_coord(x), board_coord(y), image=self.move_images[-1])

        self.view.showMsg("Red" + red_msg + " Green" + green_msg if self.current_player == "w" else "Green" + green_msg + " Red" + red_msg)
        self.view.root.update()
        # if self.game_mode == 0:
        #     return False
        if self.game_mode == 1:
            if self.players[self.current_player] == "AI":
                self.win_rate[self.current_player] = self.perform_AI()
                return True
            return False
        elif self.game_mode == 2:
            # if self.current_player == "w":
            #     self.human_win_rate = self.perform_AI()
            # else:
            self.win_rate[self.current_player] = self.perform_AI()
            return True
        return False

    def perform_AI(self):
        print ('...AI is calculating...')
        START_TIME = time.clock()
        move, win_rate = self.cchess_engine.select_move(self.ai_function)
        time_used = time.clock() - START_TIME
        print ('...Use %fs...' % time_used)
        if self.current_player == "w":
            self.time_red.append(time_used)
        else:
            self.time_green.append(time_used)
        if move is not None:
            self.board.move(move[0], move[1], move[2], move[3])
        return win_rate

    # AI VS AI mode
    def game_mode_2(self):
        self.change_player()
        self.view.draw_board(self.board)
        self.view.root.update()
        if self.check_end():
            return True
        return False