import mcts, uuid, os import json __all__ = ['store', 'load'] SIZE = mcts.board_size() KOMI = 7.5 # Format for games: # games = [game] # game = (moves, <score>) # moves = ['B'|'W', <move>, search_count] # search_count = [int] def store(filename, games): tmp_fname = '{}.{}'.format(filename, str(uuid.uuid4())) f = open(tmp_fname, 'w') for moves, score in games: f.write('Game: {} {} {} {}\n'.format(SIZE, KOMI, len(moves), score)) for m in moves: f.write('{} {} |'.format(m[0], m[1])) assert len(m[2]) == SIZE * SIZE + 1, '{} != {}'.format( m[2], SIZE * SIZE + 1) for count in m[2]: f.write(' {}'.format(count)) f.write('\n') f.close() os.rename(tmp_fname, filename)
#!/usr/bin/env python3 import random, sys, glob import numpy as np import mcts import tensorflow as tf __all__ = ['Network'] size = mcts.board_size() def keras_residual_block(input_layer): v = tf.keras.layers.ZeroPadding2D( padding=1, data_format='channels_first')(input_layer) v = tf.keras.layers.Conv2D( 128, 3, data_format='channels_first', kernel_regularizer=tf.keras.regularizers.l2(1.e-4))(v) v = tf.keras.layers.LeakyReLU(0.01)(v) v = tf.keras.layers.ZeroPadding2D(padding=1, data_format='channels_first')(v) v = tf.keras.layers.Conv2D( 128, 3, data_format='channels_first', kernel_regularizer=tf.keras.regularizers.l2(1.e-4))(v) merged = tf.keras.layers.Add()([input_layer, v]) return tf.keras.layers.LeakyReLU(0.01)(merged)