def interpret_game(path): game_data = read_game_file(path) white_queen = Queen(game_data['white_queen'], Team.WHITE, monkey_stack=game_data['stack']) black_queen = Queen(game_data['black_queen'], Team.BLACK, monkey_stack=game_data['stack']) board = Board(cols=game_data['cols'], rows=game_data['rows']) board.add_entity(white_queen) board.add_entity(black_queen) board.draw() for command in game_data['moves']: board.play_command(command) return board
MC = MonteCarloTree(current_player, game_interface, None) iterations = 1000 c = 0 while iterations > 0: print(iterations) if iterations % 2000 == 0: print("processing machine coup ... %i/10" % c) c += 1 MC.tree_search() iterations -= 1 best_coup = next_coup(MC) game_interface.make_play(best_coup) # board_copy = board.copy_state() # play = make_play(board_copy, current_player, last_move) # board.play_command(Command(play[0], play[1])) # last_move = (play[0], play[1]) else: while True: try: command = get_command(board) board.play_command(command) last_move = \ (Vec2I(command.get_from().x, command.get_from().y), command.get_to().x, command.get_to().y) break except GameException as e: print('Wrong move: {}'.format(e)) time.sleep(3) if board.get_winner() is not None: print(board.get_winner())
display = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('Monkey Queen') window = UI(game) window.open_window() window.draw() if game_from_file: while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) elif event.type == pygame.KEYUP: if len(command_queue) > 0: move = command_queue.pop(0) game.play_command(move) else: command_queue = queue.Queue() move_log = [ ] # All moves are registered here so they can be saved in a game file thread = threading.Thread(target=command_thread, args=(command_queue, game)) thread.start() while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) if not command_queue.empty(): command = command_queue.get() try: move_log.append(command)