def run_match(self): done = False i = 0 history = [] # player_actions = [1, 169,13, 168, 15, 167, 26, 166, 28, 165, 40, 0] player_actions = [0, 1, 166, 13] while True: # Get player player_color = i % 2 + 1 if player_color == 1: player = self.p1 else: player = self.p2 self.env.set_player_color(player_color) # Get Player action # Todo Check for out of memory and other errors try: # a_t = self.get_action(player) a_t = player_actions[i] except TimedOutExc as e: print("took too long") a_t = goSim._pass_action(self.board_size) # Check if action is legal or not self.env.render() print(a_t) is_legal_action = self.env.is_legal_action(self.obs_t, a_t, player_color) print(is_legal_action) print() print() print() # Take action self.obs_t, r_t, done, info, cur_score = self.env.step(a_t) # self.env.render() # print(self.obs_t) history.append(str(player_color) + ': ' + str(a_t)) if done: if cur_score > 0: # White i.e. player 2 wins winner = "P2" elif cur_score < 0: # Black i.e. player 1 wins winner = "P1" else: # Draw winner = "DRAW" with open(self.match_folder + '/actions.csv', 'w') as fw: for entry in history: fw.write(entry + '\n') fw.close() return winner, cur_score # Book Keeping i += 1 self.env.close()
def run_match(self): done = False i = 0 history = [] while True: # Get player player_color = i % 2 + 1 if player_color == 1: player = self.p1 else: player = self.p2 # print("!!!!!!!!!!!!") # print(self.env.state.color) # print(self.env.player_color) self.env.set_player_color(player_color) # print(self.env.state.color) # print(self.env.player_color) # print("!!!!!!!!!!!!") # Get Player action # Todo Check for out of memory and other errors try: a_t = self.get_action(player) # print(self.env.state.color) except TimedOutExc as e: print("took too long") a_t = goSim._pass_action(self.board_size) # Take action # print(self.env.state.color) # print(self.env.player_color) self.obs_t, a_t, r_t, done, info, cur_score = self.env.step(a_t) # print(self.env.state.color) # print("yyyyyyyyyyyyyy$$$$$$$$$$$$$$") self.env.render() self.opponent_action = a_t history.append(str(player_color) + ': ' + str(a_t)) if done: if cur_score > 0: # White i.e. player 2 wins winner = "P2" elif cur_score < 0: # Black i.e. player 1 wins winner = "P1" else: # Draw winner = "DRAW" with open(self.match_folder + '/actions.csv', 'w') as fw: for entry in history: fw.write(entry + '\n') fw.close() return winner, cur_score # Book Keeping i += 1 self.env.close()
print("!!!!!!!!!!!!") >>>>>>> fe170cc3d45ff7dc266c9dacb5186c0bf5ace4ed # Get Player action # Todo Check for out of memory and other errors try: a_t = self.get_action(player) <<<<<<< HEAD # print(self.env.state.color) ======= print(self.env.state.color) >>>>>>> fe170cc3d45ff7dc266c9dacb5186c0bf5ace4ed except TimedOutExc as e: print("took too long") a_t = goSim._pass_action(self.board_size) # Take action # print(self.env.state.color) # print(self.env.player_color) self.obs_t, a_t, r_t, done, info, cur_score = self.env.step(a_t) <<<<<<< HEAD # print(self.env.state.color) # print("yyyyyyyyyyyyyy$$$$$$$$$$$$$$") ======= print(self.env.state.color) print("yyyyyyyyyyyyyy$$$$$$$$$$$$$$") >>>>>>> fe170cc3d45ff7dc266c9dacb5186c0bf5ace4ed self.env.render() self.opponent_action = a_t history.append(str(player_color) + ': ' + str(a_t))
def run_match(self): done = False i = 0 winner = None cur_score = None with open(self.match_folder + '/actions.csv', 'w') as fw: fw.write('BLACK, ' + str(self.p1_name) + '\n') fw.write('WHITE, ' + str(self.p2_name) + '\n\n') fw.write('p1_action, p2_action, score, time, RAM, GPU_mem' + '\n') while True: # Get player player_color = i % 2 + 1 if player_color == 1: player = self.p1 else: player = self.p2 self.env.set_player_color(player_color) # Get Player action # Todo Check for out of memory and other errors time_taken = None try: st = time.time() a_t = self.get_action(player) time_taken = time.time() - st except TimedOutExc as e: print("took too long") a_t = goSim._pass_action(self.board_size) time_taken = 5 # Take action self.obs_t, a_t, r_t, done, info, cur_score = self.env.step( a_t) self.env.render() self.opponent_action = a_t pid = os.getpid() py = psutil.Process(pid) memoryUse = py.memory_info()[0] / 2.**30 if player_color == 1: fw.write( str(a_t) + ', , ' + str(cur_score) + ', ' + str(round(time_taken, 3)) + ', ' + str(round(memoryUse, 3)) + ', ' + str(round(GPUtil.getGPUs()[self.gpu_id].memoryUsed, 3)) + '\n') else: fw.write( ' , ' + str(a_t) + ', ' + str(cur_score) + ', ' + str(round(time_taken, 3)) + ', ' + str(round(memoryUse, 3)) + ', ' + str(round(GPUtil.getGPUs()[self.gpu_id].memoryUsed, 3)) + '\n') if done: if cur_score > 0: # White i.e. player 2 wins winner = self.p2_name elif cur_score < 0: # Black i.e. player 1 wins winner = self.p1_name else: # Draw winner = -1 break # Book Keeping i += 1 self.env.close() fw.close() return winner, cur_score