def genmove(self, game_state, player): self.move_num += 1 dist = self.bot.gen_probdist(game_state, player) result = gtp_states.Move_generator_result() if dist is not None: move = np.unravel_index(np.argmax(dist), dist.shape) result.move = move logging.debug("%s valid moves\n%s"%(self, utils.dist_stats(dist))) logging.debug("%s move %d: playing %s"%(self, self.move_num, gomill.common.format_vertex(move))) else: result.pass_move = True logging.debug("%s move %d: playing pass"%(self, self.move_num)) return result
def genmove(self, game_state, player): self.move_num += 1 dist = self.bot.gen_probdist(game_state, player) result = gtp_states.Move_generator_result() if dist is not None: move = np.unravel_index(np.argmax(dist), dist.shape) result.move = move logging.debug("%s valid moves\n%s" % (self, utils.dist_stats(dist))) logging.debug( "%s move %d: playing %s" % (self, self.move_num, gomill.common.format_vertex(move))) else: result.pass_move = True logging.debug("%s move %d: playing pass" % (self, self.move_num)) return result
def test_bot(): logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.DEBUG) player = DistWrappingMaxPlayer(RandomDistBot()) class State: pass s = State() b = gomill.boards.Board(3) s.board = b b.play(1, 1, "b") b.play(0, 1, "b") logging.debug("\n"+gomill.ascii_boards.render_board(b)) mv = player.genmove(s, 'w').move b.play(mv[0], mv[1], 'w') logging.debug("\n"+gomill.ascii_boards.render_board(b)) logging.debug("best move is " + gomill.common.format_vertex(mv)) logging.debug("\n" + str(player.bot.last_dist)) logging.debug(utils.dist_stats(player.bot.last_dist))
def test_bot(): logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s', level=logging.DEBUG) player = DistWrappingMaxPlayer(RandomDistBot()) class State: pass s = State() b = gomill.boards.Board(3) s.board = b b.play(1, 1, "b") b.play(0, 1, "b") logging.debug("\n" + gomill.ascii_boards.render_board(b)) mv = player.genmove(s, 'w').move b.play(mv[0], mv[1], 'w') logging.debug("\n" + gomill.ascii_boards.render_board(b)) logging.debug("best move is " + gomill.common.format_vertex(mv)) logging.debug("\n" + str(player.bot.last_dist)) logging.debug(utils.dist_stats(player.bot.last_dist))
def gen_probdist(self, game_state, player): """ Generates a correct move probability distribution for the next move, using the gen_probdist_raw(). Correct means that it zeroes out probability of playing incorrect move, such as move forbidden by ko, suicide and occupied points. Stores the dist and the player. :return: a numpy array of floats of shape (board.side, board.side), or None for pass the array is normalized to 1 """ dist = self.gen_probdist_raw(game_state, player) if dist is not None: correct_moves = analyze_board.board2correct_move_mask( game_state.board, player) if game_state.ko_point: correct_moves[game_state.ko_point[0]][ game_state.ko_point[1]] = 0 # compute some debugging stats of the incorrect moves first incorrect_dist = (1 - correct_moves) * dist logging.debug("%s incorrect moves\n%s" % (self, utils.dist_stats(incorrect_dist))) # keep only correct moves dist = correct_moves * dist s = dist.sum() if s > 0.0: dist = dist / dist.sum() else: logging.debug("No valid moves, PASSING.") dist = None self.last_dist = dist self.last_player = player return self.last_dist
def gen_probdist(self, game_state, player): """ Generates a correct move probability distribution for the next move, using the gen_probdist_raw(). Correct means that it zeroes out probability of playing incorrect move, such as move forbidden by ko, suicide and occupied points. Stores the dist and the player. :return: a numpy array of floats of shape (board.side, board.side), or None for pass the array is normalized to 1 """ dist = self.gen_probdist_raw(game_state, player) if dist is not None: correct_moves = analyze_board.board2correct_move_mask(game_state.board, player) if game_state.ko_point: correct_moves[game_state.ko_point[0]][game_state.ko_point[1]] = 0 # compute some debugging stats of the incorrect moves first incorrect_dist = (1 - correct_moves) * dist logging.debug("%s incorrect moves\n%s"%(self, utils.dist_stats(incorrect_dist))) # keep only correct moves dist = correct_moves * dist s = dist.sum() if s > 0.0: dist = dist / dist.sum() else: logging.debug("No valid moves, PASSING.") dist = None self.last_dist = dist self.last_player = player return self.last_dist
def dist_stats(self, top=3): if self.last_dist is not None: return utils.dist_stats(self.last_dist, top) return ''