backgammon/human.py

54 lines
1.4 KiB
Python
Raw Normal View History

2018-02-05 21:31:34 +00:00
from cup import Cup
class Human:
global cup
cup = Cup()
2018-02-07 14:31:05 +00:00
def __init__(self, board, sym, network):
2018-02-05 21:31:34 +00:00
self.cup = Cup()
2018-02-07 14:31:05 +00:00
self.network = network
2018-02-05 21:31:34 +00:00
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
2018-02-05 21:31:34 +00:00
def get_sym(self):
return self.sym
2018-02-05 21:31:34 +00:00
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[1]))
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]))