backgammon/eval.py

30 lines
906 B
Python
Raw Permalink Normal View History

2018-03-14 13:02:19 +00:00
from board import Board
import numpy as np
import pubeval
class Eval:
@staticmethod
def make_random_move(board, sym, roll):
legal_moves = Board.calculate_legal_states(board, sym, roll)
return random.choice(list(legal_moves))
# TODO: Test this, the score results should be deterministic
@staticmethod
def make_pubeval_move(board, sym, roll):
2018-03-14 19:42:09 +00:00
legal_moves = Board.calculate_legal_states(board, sym, roll)
2018-03-20 20:51:58 +00:00
# print("Board:", board)
# print("Length:",len(board))
2018-03-14 19:42:09 +00:00
moves_and_scores = [ ( board,
pubeval.eval(False, Board.board_features_to_pubeval(board, sym)))
for board
in legal_moves ]
2018-03-14 13:02:19 +00:00
scores = [ x[1] for x in moves_and_scores ]
best_move_pair = moves_and_scores[np.array(scores).argmax()]
2018-03-14 19:42:09 +00:00
2018-03-14 13:02:19 +00:00
return best_move_pair
2018-03-14 19:42:09 +00:00