backgammon/bot.py
Anders Ladefoged 275689c002 Bot reimplemented with new representation.
Fixed bug where black could not bear off.
More tests written.
2018-02-22 14:01:28 +01:00

29 lines
614 B
Python

from cup import Cup
from board import Board
import random
class Bot:
def __init__(self, sym):
self.cup = Cup()
self.sym = sym
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)
return random.choice(list(legal_moves))