from cup import Cup import numpy as np import tensorflow as tf from network import Network from board import Board import random class RestoreBot: def __init__(self, sym): self.cup = Cup() self.sym = sym self.graph = tf.Graph() with self.graph.as_default(): self.session = tf.Session(graph = self.graph) self.network = Network(self.session) self.network.restore_model() def roll(self): print("{} rolled: ".format(self.sym)) roll = self.cup.roll() print(roll) return roll def switch(self,cur): return -1 if cur == 1 else 1 def get_sym(self): return self.sym def make_move(self, board, sym, roll): # print(Board.pretty(board)) legal_moves = Board.calculate_legal_states(board, sym, roll) legal_list = list(legal_moves) move_scores = [ self.network.eval_state(np.array(move).reshape(1,26)) for move in legal_list ] print("Found the best state, being:", np.array(move_scores).argmax()) return legal_list[np.array(move_scores).argmax()] # return random.choice(list(legal_moves))