def player_loop(self): """ Main loop for the minimax next move search. :return: """ # Generate game tree object first_msg = self.receiver() # Initialize your minimax model model = self.initialize_model(initial_data=first_msg) while True: msg = self.receiver() # Create the root node of the game tree node = Node(message=msg, player=0) self.start_time = time() # Possible next moves: "stay", "left", "right", "up", "down" best_move = self.search_best_next_move(model=model, initial_tree_node=node) end_time = time() # print('time', end_time - start_time, file= sys.stderr) # Execute next action self.sender({ "action": best_move, "search_time": end_time - self.start_time })
def player_loop(self): """ Main loop for the minimax next move search. :return: """ # Generate game tree object first_msg = self.receiver() # Initialize your minimax model model = self.initialize_model(initial_data=first_msg) #printerr("first message: " + str(first_msg)) while True: msg = self.receiver() #printerr("-----------------------------------") #printerr("message: " + str(first_msg) + '\n') # Create the root node of the game tree node = Node(message=msg, player=0) #printerr("initial node: " + str(node) + '\n') # Possible next moves: "stay", "left", "right", "up", "down" best_move = self.search_best_next_move( model=model, initial_tree_node=node) #printerr("best move: " + str(best_move) + '\n') # Execute next action self.sender({"action": best_move, "search_time": None})
def update_specific(self, msg): msg = self.build_minimax_msg(msg) if self.current_player == 0: self.sender(msg) self.time_sent = time() else: initial_tree_node = Node(message=msg, player=1) self.action = self.minimax_agent_opponent.next_move(initial_tree_node)
def player_loop(self): """ Main loop for the minimax next move search. :return: """ # Generate game tree object first_msg = self.receiver() # Initialize your minimax model model = self.initialize_model(initial_data=first_msg) #printerr("first message: " + str(first_msg)) #if step==1: # return (step % N_FISH, random.randint(0, N_SPECIES - 1)) #mstats = {'stay':0.0,'up':0.0,'down':0.0,'left':0.0,'right':0.0} #nmoves = 1.0 while True: msg = self.receiver() #printerr("-----------------------------------") #printerr("message: " + str(first_msg) + '\n') # Create the root node of the game tree node = Node(message=msg, player=0) #printerr("initial node: " + str(node) + '\n') # Possible next moves: "stay", "left", "right", "up", "down" best_move = self.search_best_next_move(model=model, initial_tree_node=node) #mstats[best_move] += 1 ''' if nmoves % 5== 0: printerr("Stay: " + str(mstats.get('stay') / nmoves)) printerr("Up: " + str(mstats.get('up')/nmoves)) printerr("Down: " + str(mstats.get('down')/nmoves)) printerr("Left: " + str(mstats.get('left')/nmoves)) printerr("Right: " + str(mstats.get('right')/nmoves)) nmoves += 1 ''' # Execute next action self.sender({"action": best_move, "search_time": None})
def player_loop(self): """ Main loop for the minimax next move search. :return: """ # Generate game tree object first_msg = self.receiver() """ first_msg { 'fish0': {'score': 11, 'type': 3}, 'fish1': {'score': 2, 'type': 1}, ... 'fish5': {'score': -10, 'type': 4}, 'game_over': False } """ # Initialize your minimax model #model = self.initialize_model(initial_data=first_msg) while True: msg = self.receiver( ) # contains caught_fish, hooks/fish positions, score ect self.start_time = time() # Create the root node of the game tree node = Node(message=msg, player=0) # Possible next moves: "stay", "left", "right", "up", "down" for max_depth in range(1, 5): _, best_move, found = self.search_best_next_move( curr_node=node, depth=max_depth, player=0, alpha=-999999, beta=999999) if found: break # Execute next action self.sender({"action": best_move, "search_time": None})
def player_loop(self): """ Main loop for the minimax next move search. :return: """ # Generate game tree object first_msg = self.receiver() # Initialize your minimax model #model = self.initialize_model(initial_data=first_msg) while True: msg = self.receiver() # Create the root node of the game tree node = Node(message=msg, player=0) ##first node is created # Possible next moves: "stay", "left", "right", "up", "down" best_move = self.search_best_next_move( initial_tree_node=node) ##send that root node to search_best_next_move() # Execute next action self.sender({"action": best_move, "search_time": None})