backgammon/hooman.py

48 lines
1.3 KiB
Python
Raw Normal View History

2018-02-05 21:31:34 +00:00
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())
2018-02-05 22:36:32 +00:00
print(self.board.find_legal_moves(self.sym,roll[0]))
2018-02-05 21:31:34 +00:00
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]))
2018-02-05 21:31:34 +00:00
print(self.board.to_s())
print(self.board.find_legal_moves(self.sym,roll[0]))
2018-02-05 21:31:34 +00:00
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]))