def draw_info(batch, window_width, window_height, upper_grid_coord, state): turn = GoGame.get_turn(state) turn_str = 'B' if turn == BLACK else 'W' prev_player_passed = GoGame.get_prev_player_passed(state) game_ended = GoGame.get_game_ended(state) info_label = "Turn: {}\nPassed: {}\nGame: {}".format( turn_str, prev_player_passed, "OVER" if game_ended else "ONGOING") pyglet.text.Label(info_label, font_name='Helvetica', font_size=11, x=window_width - 20, y=window_height - 20, anchor_x='right', anchor_y='top', color=(0, 0, 0, 192), batch=batch, width=window_width / 2, align='right', multiline=True) # Areas black_area, white_area = GoGame.get_areas(state) pyglet.text.Label("{}B | {}W".format(black_area, white_area), font_name='Helvetica', font_size=16, x=window_width / 2, y=upper_grid_coord + 80, anchor_x='center', color=(0, 0, 0, 192), batch=batch, width=window_width, align='center')
def get_winning(self): """ :return: Who's currently winning, regardless if the game is over """ black_area, white_area = GoGame.get_areas(self.state) area_difference = black_area - white_area if area_difference > 0: return 1 elif area_difference == 0: return 0.5 else: assert area_difference < 0 return 0
def get_reward(self): ''' Return reward based on reward_method. heuristic: black total area - white total area real: 0 for in-game move, 1 for winning, 0 for losing, 0.5 for draw, from black player's perspective. Winning and losing based on the Area rule Also known as Trump Taylor Scoring Area rule definition: https://en.wikipedia.org/wiki/Rules_of_Go#End ''' if self.reward_method == RewardMethod.REAL: return self.get_winner() elif self.reward_method == RewardMethod.HEURISTIC: black_area, white_area = GoGame.get_areas(self.state) area_difference = black_area - white_area if self.game_ended(): return (1 if area_difference > 0 else -1) * self.size**2 return area_difference else: raise Exception("Unknown Reward Method")