backgammon/hooman.py

45 lines
1.1 KiB
Python

from cup import Cup
class Human:
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 "X" if cur == "O" else "O"
def do_move(self, roll):
print(self.board.to_s())
cur_state = self.board.get_state()
print("What to do with the first roll?")
cmds_1 = input().split(",")
while not self.board.check_move(cmds_1, self.sym, roll[0]):
print("Invalid move, try again.")
cmds_1 = input().split(",")
self.board.move_thing(self.sym, int(cmds_1[0]), int(cmds_1[1]))
print("What to do with the second roll?")
cmds_2 = input().split(",")
while not self.board.check_move(cmds_2, self.sym, roll[1]):
print("Invalid move")
cmds_2 = input().split(",")
self.board.move_thing(self.sym, int(cmds_2[0]), int(cmds_2[1]))