keithgw / wingspan

A Wingspan AI that uses reinforcement learning to learn to play the wingspan board game.
2 stars 1 forks source link

refactor the play loop to allow play from a phase within a turn #53

Open keithgw opened 7 months ago

keithgw commented 7 months ago

For the simulator in MCTS to playout a game from an arbitrary game state, it will need to start from a phase within a turn. Currently, the way the play loop works is that it gets the current player, has the player take a full turn, the game state ends the turn, then the loop continues with the next player until the game is over. This allows a game to start from the beginning of an arbitrary player's turn, but not within their turn.

Instead, the game state should maintain the current player and phase of the game, then the play method will request that the current player take an action from the current game state. The result of the player taking an action should update the game state accordingly. Here is an example:

def play(self):
    # Main game loop
    while not self.game_state.is_game_over():
        current_player_idx = self.game_state.get_current_player()
        self.render(current_player_idx) #TODO: make optional
        current_player = self.players[current_player_idx]
        phase = self.game_state.get_phase()

        if phase == 'choose_action':
            action = current_player.choose_action()
            self.game_state = self.game_state.choose_action(action)
        elif phase == 'choose_a_bird_to_play':
            bird = current_player.choose_a_bird_to_play()
            self.game_state = self.game_state.choose_a_bird_to_play(bird)
        elif phase == 'choose_a_bird_to_draw':
            bird = current_player.choose_a_bird_to_draw()
            self.game_state = self.game_state.choose_a_bird_to_draw(bird)

    # Game is over, give a game summary
    self.render_game_summary() #TODO: make optional