backgammon/restore_bot.py

33 lines
1.0 KiB
Python
Raw Normal View History

2018-03-04 16:35:36 +00:00
from cup import Cup
import numpy as np
import tensorflow as tf
from network import Network
from board import Board
import random
2018-03-06 10:06:38 +00:00
class RestoreBot:
2018-03-04 16:35:36 +00:00
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)
2018-03-06 12:04:47 +00:00
self.network.restore_model()
2018-03-04 16:35:36 +00:00
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)
2018-03-06 12:04:47 +00:00
moves_and_scores = [ (move, self.network.eval_state(np.array(move).reshape(1,26))) for move in legal_moves ]
scores = [ x[1] for x in moves_and_scores ]
best_move = moves_and_scores[np.array(scores).argmax()][0]
#print("Found the best state, being:", np.array(move_scores).argmax())
return best_move
2018-03-04 16:35:36 +00:00
# return random.choice(list(legal_moves))