示例#1
0
 def do_move(self):
     direction = model.get_random_move()
     # direction = model.get_expectimax_move(self.board)
     if model.move_exists(self.board):
         self.board = model.play_move(self.board, direction)
         self.update_grid_cells()           # redraw grid
         self.root.after(100, self.do_move)  # reschedule do_move in 0.1 second
     else:
         # game over, no reschedule
         if model.game_state(self.board) == 'win':
             self.root.title("You win!")
         else:
             self.root.title("You lose!")
         return
示例#2
0
    def do_move(self):
        start_time = time.time()
        direction = model.get_expectimax_move(self.board)
        end_time = time.time()
        print("Calculating move took: " + str(end_time - start_time) +
              " seconds.")

        if model.move_exists(self.board):
            self.board = model.play_move(self.board, direction)
            self.update_grid_cells()  # redraw grid
            self.root.after(100,
                            self.do_move)  # reschedule do_move in 0.1 second
        else:
            # game over, no reschedule
            if model.game_state(self.board) == 'win':
                self.root.title("You win!")
            else:
                self.root.title("You lose!")
            return