Closed keithgw closed 7 months ago
Implement a State and Policy class, for example:
class State:
def __init__(self, game_board, phase):
self.game_board = game_board
self.phase = phase
class Policy:
def __call__(self, state):
if state.phase == 'choose_action':
return self._policy_choose_action(state.game_board)
elif state.phase == 'choose_bird':
return self._policy_choose_bird(state.game_board)
def _policy_choose_action(self, game_board):
# Return probabilities for the actions 'play_a_bird', 'gain_food', 'draw_a_card'
pass
def _policy_choose_bird(self, game_board):
# Return probabilities for the actions 'choose_from_tray', 'choose_from_deck'
pass
Then, the bots choice methods can look like:
import numpy as np
class BotPlayer(Player):
def __init__(self):
super().__init__()
self.policy = None # Load learned policy here
def _choose_a_bird_to_draw(self, bird_deck, tray):
# Convert the current game state to a format that your policy can understand
state = self._get_state(bird_deck, tray)
# Use the policy to get the probabilities of each action
action_probs = self.policy(state)
# Choose an action according to the probabilities
action = np.random.choice(len(action_probs), p=action_probs)
# Convert the action back to a bird
chosen_bird = self._action_to_bird(action, bird_deck, tray)
return chosen_bird
methods to modify for AI player:
_choose_action
This should follow the agent's policy_choose_a_bird_to_play
This should follow the agent's policydraw_a_bird
This should follow a similar pattern to play a bird, where the choosing is separate from the actual drawing.