def pick_model_move(self, color): if self.model.Nfeat == 15: board_feature_planes = Features.make_feature_planes_stones_3liberties_4history_ko( self.board, color) Normalization.apply_featurewise_normalization_B( board_feature_planes) elif self.model.Nfeat == 21: board_feature_planes = Features.make_feature_planes_stones_4liberties_4history_ko_4captures( self.board, color).astype(np.float32) Normalization.apply_featurewise_normalization_C( board_feature_planes) else: assert False feature_batch = Symmetry.make_symmetry_batch(board_feature_planes) feed_dict = {self.feature_planes: feature_batch} logit_batch = self.sess.run(self.logits, feed_dict) move_logits = Symmetry.average_plane_over_symmetries( logit_batch, self.model.N) softmax_temp = 1.0 move_probs = softmax(move_logits, softmax_temp) # zero out illegal moves for x in xrange(self.model.N): for y in xrange(self.model.N): ind = self.model.N * x + y if not self.board.play_is_legal(x, y, color): move_probs[ind] = 0 sum_probs = np.sum(move_probs) if sum_probs == 0: return Move.Pass() # no legal moves, pass move_probs /= sum_probs # re-normalize probabilities pick_best = True if pick_best: move_ind = np.argmax(move_probs) else: move_ind = sample_from(move_probs) move_x = move_ind / self.model.N move_y = move_ind % self.model.N self.last_move_probs = move_probs.reshape((self.board.N, self.board.N)) return Move(move_x, move_y)
def pick_book_move(self, color): if self.book: book_move = Book.get_book_move(self.board, self.book) if book_move: print "playing book move", book_move return Move(book_move[0], book_move[1]) print "no book move" else: print "no book" return None
def generate_move(self, color, cleanup=False): self.push_state() if channel_from_color(color) == gvg.player_channel: self.board = go_board.switch_player_perspec(self.board) move = self.pick_move(color) if move.is_play(): go_board.make_move(self.board, [move.x, move.y], gvg.bot_channel, gvg.player_channel) go_board.show_board(self.board) return Move(move.x, move.y)
def pick_model_move(self, color): # If asked to make a move for enemy player, switch perspective as if we are them if channel_from_color(color) == gvg.player_channel: self.board = go_board.switch_player_perspec(self.board) enc_board = go_board.get_encoded_board(self.board) pred = np.asarray(self.model.predict(enc_board. \ reshape(1, gvg.board_size, gvg.board_size, gvg.enc_board_channels))). \ reshape(gvg.board_size * gvg.board_size) prob_board = np.array( self.model.predict( go_board.get_encoded_board( self.board.reshape( gvg.board_size, gvg.board_size, gvg.board_channels)).reshape(1, 19, 19, 20))).reshape( (gvg.board_size, gvg.board_size)) self.last_move_probs = prob_board move = go_learn.predict_move(self.board, self.model, prob_board=prob_board) return Move(move[0], move[1])
def pick_move(self, color): for x in xrange(self.board.N): for y in xrange(self.board.N): if self.board.play_is_legal(x, y, color): return Move(x, y) return Move.Pass()
def pick_move(self, color): x,y = choose_move_alphabeta(self.board, self.policy, self.value, depth=3) return Move(x,y)