# Path: betago/processor.py
# class SevenPlaneProcessor(GoDataProcessor):
#     '''
#     Implementation of a Go data processor, using seven planes of 19x19 values to represent the position of
#     a go board, as explained below.
# 
#     This closely reflects the representation suggested in Clark, Storkey:
#     http://arxiv.org/abs/1412.3409
#     '''
# 
#     def __init__(self, data_directory='data', num_planes=7, consolidate=True, use_generator=False):
#         super(SevenPlaneProcessor, self).__init__(data_directory=data_directory,
#                                                   num_planes=num_planes,
#                                                   consolidate=consolidate,
#                                                   use_generator=use_generator)
# 
#     def feature_and_label(self, color, move, go_board, num_planes):
#         '''
#         Parameters
#         ----------
#         color: color of the next person to move
#         move: move they decided to make
#         go_board: represents the state of the board before they moved
# 
#         Planes we write:
#         0: our stones with 1 liberty
#         1: our stones with 2 liberty
#         2: our stones with 3 or more liberties
#         3: their stones with 1 liberty
#         4: their stones with 2 liberty
#         5: their stones with 3 or more liberties
#         6: simple ko
#         '''
#         row, col = move
#         enemy_color = go_board.other_color(color)
#         label = row * 19 + col
#         move_array = np.zeros((num_planes, go_board.board_size, go_board.board_size))
#         for row in range(0, go_board.board_size):
#             for col in range(0, go_board.board_size):
#                 pos = (row, col)
#                 if go_board.board.get(pos) == color:
#                     if go_board.go_strings[pos].liberties.size() == 1:
#                         move_array[0, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() == 2:
#                         move_array[1, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() >= 3:
#                         move_array[2, row, col] = 1
#                 if go_board.board.get(pos) == enemy_color:
#                     if go_board.go_strings[pos].liberties.size() == 1:
#                         move_array[3, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() == 2:
#                         move_array[4, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() >= 3:
#                         move_array[5, row, col] = 1
#                 if go_board.is_simple_ko(color, pos):
#                     move_array[6, row, col] = 1
#         return move_array, label


import argparse
import os
from keras.callbacks import ModelCheckpoint
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Conv2D, MaxPooling2D
from betago.processor import SevenPlaneProcessor
from __future__ import print_function





parser = argparse.ArgumentParser()
parser.add_argument('--bot-name', default='new_bot')
parser.add_argument('--epochs', type=int, default=5)
parser.add_argument('--sample-size', type=int, default=1000)
args = parser.parse_args()

here = os.path.dirname(os.path.abspath(__file__))
model_zoo = os.path.join(here, '..', 'model_zoo')
weight_file = os.path.join(model_zoo, args.bot_name + '_weights.hd5')
checkpoint_file_pattern = os.path.join(model_zoo, args.bot_name + '_epoch_{epoch}.hd5')
model_file = os.path.join(model_zoo, args.bot_name + '_model.yml')

batch_size = 128

nb_classes = 19 * 19  # One class for each position on the board
go_board_rows, go_board_cols = 19, 19  # input dimensions of go board
nb_filters = 32  # number of convolutional filters to use
nb_pool = 2  # size of pooling area for max pooling
nb_conv = 3  # convolution kernel size

# SevenPlaneProcessor loads seven planes (doh!) of 19*19 data points, so we need 7 input channels

# Path: betago/processor.py
# class SevenPlaneProcessor(GoDataProcessor):
#     '''
#     Implementation of a Go data processor, using seven planes of 19x19 values to represent the position of
#     a go board, as explained below.
# 
#     This closely reflects the representation suggested in Clark, Storkey:
#     http://arxiv.org/abs/1412.3409
#     '''
# 
#     def __init__(self, data_directory='data', num_planes=7, consolidate=True, use_generator=False):
#         super(SevenPlaneProcessor, self).__init__(data_directory=data_directory,
#                                                   num_planes=num_planes,
#                                                   consolidate=consolidate,
#                                                   use_generator=use_generator)
# 
#     def feature_and_label(self, color, move, go_board, num_planes):
#         '''
#         Parameters
#         ----------
#         color: color of the next person to move
#         move: move they decided to make
#         go_board: represents the state of the board before they moved
# 
#         Planes we write:
#         0: our stones with 1 liberty
#         1: our stones with 2 liberty
#         2: our stones with 3 or more liberties
#         3: their stones with 1 liberty
#         4: their stones with 2 liberty
#         5: their stones with 3 or more liberties
#         6: simple ko
#         '''
#         row, col = move
#         enemy_color = go_board.other_color(color)
#         label = row * 19 + col
#         move_array = np.zeros((num_planes, go_board.board_size, go_board.board_size))
#         for row in range(0, go_board.board_size):
#             for col in range(0, go_board.board_size):
#                 pos = (row, col)
#                 if go_board.board.get(pos) == color:
#                     if go_board.go_strings[pos].liberties.size() == 1:
#                         move_array[0, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() == 2:
#                         move_array[1, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() >= 3:
#                         move_array[2, row, col] = 1
#                 if go_board.board.get(pos) == enemy_color:
#                     if go_board.go_strings[pos].liberties.size() == 1:
#                         move_array[3, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() == 2:
#                         move_array[4, row, col] = 1
#                     elif go_board.go_strings[pos].liberties.size() >= 3:
#                         move_array[5, row, col] = 1
#                 if go_board.is_simple_ko(color, pos):
#                     move_array[6, row, col] = 1
#         return move_array, label


# Path: examples/train_generator.py
import argparse
import os
from keras.callbacks import ModelCheckpoint
from keras.models import Sequential
from keras.layers.core import Dense, Dropout, Activation, Flatten
from keras.layers.convolutional import Conv2D, MaxPooling2D
from betago.processor import SevenPlaneProcessor

from __future__ import print_function





parser = argparse.ArgumentParser()
parser.add_argument('--bot-name', default='new_bot')
parser.add_argument('--epochs', type=int, default=5)
parser.add_argument('--sample-size', type=int, default=1000)
args = parser.parse_args()

here = os.path.dirname(os.path.abspath(__file__))
model_zoo = os.path.join(here, '..', 'model_zoo')
weight_file = os.path.join(model_zoo, args.bot_name + '_weights.hd5')
checkpoint_file_pattern = os.path.join(model_zoo, args.bot_name + '_epoch_{epoch}.hd5')
model_file = os.path.join(model_zoo, args.bot_name + '_model.yml')

batch_size = 128

nb_classes = 19 * 19  # One class for each position on the board
go_board_rows, go_board_cols = 19, 19  # input dimensions of go board
nb_filters = 32  # number of convolutional filters to use
nb_pool = 2  # size of pooling area for max pooling
nb_conv = 3  # convolution kernel size

# SevenPlaneProcessor loads seven planes (doh!) of 19*19 data points, so we need 7 input channels

processor = SevenPlaneProcessor(use_generator=True)