def greedy_action(self): """ :strategy: Choose the best action without considering opponent moves. """ if not self.root.state[self.colour]: return ("PASS", None) best_eval, best_action = -inf, None # TODO: Use TT to prevent recalculation for child in self.root.children: if child.action[0] == "EXIT": return child.action new_eval = speed_demon(child.state)[PLAYER_HASH[self.colour]] self.root.child_evaluations[child.action] = new_eval # ONLY select non-repetitive moves if new_eval > best_eval: best_eval = new_eval best_action = child.action self.root.fully_evaluated = True if best_action == None: print("The none error.") GameNode.debugger(self.root) return best_action
def __init__(self, colour): """ This method is called once at the beginning of the game to initialise your player. """ self.root = GameNode(create_initial_state(), None) self.kill = True
def action(self): """ This method is called at the beginning of each of your turns to request a choice of action from your program. Made it so greedy will always prefer exit moves """ if not self.root.state[self.colour]: return ("PASS", None) best_eval, best_action = -inf, None # TODO: Use TT to prevent recalculation for child in self.root.children: if child.action[0] == "EXIT": return child.action new_eval = speed_demon(child.state)[PLAYER_HASH[self.colour]] self.root.child_evaluations[child.action] = new_eval # ONLY select non-repetitive moves if new_eval > best_eval: best_eval = new_eval best_action = child.action if best_action == None: print("The none error.") GameNode.debugger(self.root) return best_action
def action(self): """ Returns an action given time constraints (55 seconds CPU) """ if not self.root.state[self.colour]: print("Thought no actions were available as colour {self.colour}") return ("PASS", None) if self.clock <= 70: start = process_time() if num_opponents_dead(self.root.state) == 1: action = self.run_2_player() if (action == None): print("run2") GameNode.debugger(self.root) elif num_opponents_dead(self.root.state) == 2: action = self.djikstra() if (action == None): print("dijk") GameNode.debugger(self.root) elif self.start_mid_game(): action = self.mid_game() if (action == None): print("mid") GameNode.debugger(self.root) else: action = self.early_game() if (action == None): print("earl") GameNode.debugger(self.root) self.clock += process_time() - start print(self.clock) else: action = self.greedy_action() if (action == None): print("greed") GameNode.debugger(self.root) return action
class TTPlayer: def __init__(self, colour): """ This method is called once at the beginning of the game to initialise your player. """ self.root = GameNode(create_initial_state(), None) self.kill = True @property def colour(self): return self.root.state['turn'] def debug(self): GameNode.debugger(self.root) def update(self, colour, action): """ This method is called at the end of every turn (including your player’s turns) to inform your player about the most recent, assumedly correct, action. """ # Steal root child with this state and overthrow self.root = self.root.update_root(action, kill=self.kill)
def debug(self): GameNode.debugger(self.root)