backgammon/eval.py

41 lines
1.3 KiB
Python
Raw Permalink Normal View History

2018-03-14 13:02:19 +00:00
from board import Board
import numpy as np
import pubeval
import dumbeval
2018-03-14 13:02:19 +00:00
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)
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
@staticmethod
def make_dumbeval_move(board, sym, roll):
legal_moves = Board.calculate_legal_states(board, sym, roll)
moves_and_scores = [ ( board,
dumbeval.eval(False, Board.board_features_to_pubeval(board, sym)))
for board
in legal_moves ]
scores = [ x[1] for x in moves_and_scores ]
best_move_pair = moves_and_scores[np.array(scores).argmax()]
return best_move_pair
2018-03-14 19:42:09 +00:00