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_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()