class Player: def __init__(self, player): """ Called once at the beginning of a game to initialise this player. Set up an internal representation of the game state. The parameter player is the string "upper" (if the instance will play as Upper), or the string "lower" (if the instance will play as Lower). """ if player == "upper": self.us = "UPPER" self.opponent = "LOWER" else: self.us = "LOWER" self.opponent = "UPPER" empty_start = {'s': [], 'p': [], 'r': []} self.own_board = Board(empty_start, empty_start, 9, 9, 0, None) self.ai = SillyMoveChooserAI(self.us) def action(self): """ Called at the beginning of each turn. Based on the current state of the game, select an action to play this turn. """ # put your code here return self.ai.choose_next_move(self.own_board) def update(self, opponent_action, player_action): """ Called at the end of each turn to inform this player of both players' chosen actions. Update your internal representation of the game state. The parameter opponent_action is the opponent's chosen action, and player_action is this instance's latest chosen action. """ if self.us == "UPPER": self.own_board = self.own_board.apply_turn2( player_action, opponent_action) else: self.own_board = self.own_board.apply_turn2( opponent_action, player_action) print("AFTER UPDATE:") print(self.own_board)
def __init__(self, player): """ Called once at the beginning of a game to initialise this player. Set up an internal representation of the game state. The parameter player is the string "upper" (if the instance will play as Upper), or the string "lower" (if the instance will play as Lower). """ if player == "upper": self.us = "UPPER" self.opponent = "LOWER" else: self.us = "LOWER" self.opponent = "UPPER" empty_start = {'s': [], 'p': [], 'r': []} self.own_board = Board(empty_start, empty_start, 9, 9, 0, None) self.ai = MCTSNode(self.own_board, self.us, None, None)
def part1_to_part2(board): thrown_uppers = {'s': [], 'p': [], 'r': []} thrown_lowers = {'s': [], 'p': [], 'r': []} for key, value in board.items(): if value == "R": thrown_uppers['r'].append(key) elif value == "S": thrown_uppers['s'].append(key) elif value == "P": thrown_uppers['p'].append(key) elif value == "r": thrown_lowers['r'].append(key) elif value == "s": thrown_lowers['s'].append(key) elif value == "p": thrown_lowers['p'].append(key) return Board(thrown_uppers, thrown_lowers, 0, 0, 0, None)
class Player: def __init__(self, player): """ Called once at the beginning of a game to initialise this player. Set up an internal representation of the game state. The parameter player is the string "upper" (if the instance will play as Upper), or the string "lower" (if the instance will play as Lower). """ if player == "upper": self.us = "UPPER" self.opponent = "LOWER" else: self.us = "LOWER" self.opponent = "UPPER" empty_start = {'s': [], 'p': [], 'r': []} self.own_board = Board(empty_start, empty_start, 9, 9, 0, None) self.ai = MCTSNode(self.own_board, self.us, None, None) def action(self): """ Called at the beginning of each turn. Based on the current state of the game, select an action to play this turn. """ # book learnt moves #if self.own_board.turn <= 4: # return self.opening(self.us, self.own_board.turn) # put your code here num_sims = len(self.ai.simultaneous_moves) * 8 if self.us == "UPPER": node = self.ai.best_action(num_sims) return node.last_action[0] else: node = self.ai.best_action(num_sims) return node.last_action[1] return move def update(self, opponent_action, player_action): """ Called at the end of each turn to inform this player of both players' chosen actions. Update your internal representation of the game state. The parameter opponent_action is the opponent's chosen action, and player_action is this instance's latest chosen action. """ if self.us == "UPPER": self.own_board = self.own_board.apply_turn2( player_action, opponent_action) # Make a new root node with the updated board. This is the AI for the next move self.ai = MCTSNode(self.own_board, self.us, None, None) else: self.own_board = self.own_board.apply_turn2( opponent_action, player_action) # Make a new root node with the updated board. This is the AI for the next move self.ai = MCTSNode(self.own_board, self.us, None, None) #print("AFTER UPDATE:") #print(self.own_board) # put your code here """ opening moves hardcoded """ """