backgammon/bot.py

29 lines
614 B
Python
Raw Normal View History

from cup import Cup
2018-02-13 13:38:49 +00:00
from board import Board
import random
class Bot:
2018-02-13 13:38:49 +00:00
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))