backgammon/bot.py

42 lines
1.1 KiB
Python

from cup import Cup
import random
class Bot:
def __init__(self, board, sym):
self.cup = Cup()
self.board = board
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 do_move(self, roll):
print(self.board.to_s())
print(self.board.find_legal_moves(self.sym, roll[0]))
moves_1 = self.board.find_legal_moves(self.sym,roll[0])
move = random.choice(moves_1)
print("{} was picked as move".format(move))
self.board.move_thing(self.sym, int(move[0]), int(move[1]))
print(self.board.to_s())
print(self.board.find_legal_moves(self.sym, roll[1]))
moves_2 = self.board.find_legal_moves(self.sym,roll[1])
move = random.choice(moves_2)
print("{} was picked as move".format(move))
self.board.move_thing(self.sym, int(move[0]), int(move[1]))