Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def stockfish(self):
return Stockfish()
def test_stockfish_constructor_with_custom_params(self):
stockfish = Stockfish(parameters={"Skill Level": 1})
assert stockfish.get_parameters() == {
"Write Debug Log": "false",
"Contempt": 0,
"Min Split Depth": 0,
"Threads": 1,
"Ponder": "false",
"Hash": 16,
"MultiPV": 1,
"Skill Level": 1,
"Move Overhead": 30,
"Minimum Thinking Time": 20,
"Slow Mover": 80,
"UCI_Chess960": "false",
}
def get_groundtruth(self):
feature_batch = []
targets_batch = []
board_positions = self.get_board_position()
shuffle(board_positions)
print("done shuffling")
print("generating evaluations on {} board positions...".format(len(board_positions)))
# stockfish = Stockfish()
for index, board_position in enumerate(board_positions):
print(index)
stockfish = Stockfish()
feature_batch.append(board_to_feature(board_position))
targets_batch.append(stockfish.stockfish_eval(board_position, 10))
stockfish.kill_me()
feature_arr = np.asarray(feature_batch)
targets_arr = np.asarray(targets_batch)
np.save('features.txt', feature_arr)
np.save('values.txt', targets_arr)
def pretrain(model):
feature_batch = []
targets_batch = []
board_positions = get_board_position()
shuffle(board_positions)
print("Pretraining on {} board positions...".format(len(board_positions)))
stockfish = Stockfish()
for batch in range(Config.PRETRAIN_EPOCHS):
for index, board_position in enumerate(board_positions):
if (index + 1) % Config.minibatch_size != 0:
feature_batch.append(board_to_feature(board_position))
targets_batch.append(stockfish.stockfish_eval(board_position, 10))
else:
feature_batch = torch.FloatTensor(feature_batch)
targets_batch = Variable(torch.FloatTensor(targets_batch))
do_backprop(feature_batch, targets_batch, model)
feature_batch = []
targets_batch = []
print("Completed batch {} of {}".format(batch, Config.PRETRAIN_EPOCHS))