backgammon/human.py

40 lines
1.2 KiB
Python
Raw Normal View History

2018-02-13 13:38:49 +00:00
from board import Board
2018-02-07 15:27:03 +00:00
class Human:
2018-02-13 13:38:49 +00:00
def __init__(self, sym):
2018-02-05 21:31:34 +00:00
self.sym = sym
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-13 13:38:49 +00:00
def do_move(self, board, roll):
print(Board.pretty(board))
print("Human: ",roll,"-"*20)
print(Board.find_legal_moves(board,self.sym,roll[0]))
2018-02-05 21:31:34 +00:00
print("What to do with the first roll?")
cmds_1 = input().split(",")
2018-02-13 13:38:49 +00:00
while not Board.is_move_valid(board, roll[0], self.sym, cmds_1):
2018-02-05 21:31:34 +00:00
print("Invalid move, try again.")
cmds_1 = input().split(",")
2018-02-13 13:38:49 +00:00
new_board = Board.move_thing(board, self.sym, int(cmds_1[0]), int(cmds_1[1]))
2018-02-05 21:31:34 +00:00
2018-02-13 13:38:49 +00:00
print(Board.pretty(board))
print(Board.find_legal_moves(new_board, self.sym,roll[1]))
2018-02-05 21:31:34 +00:00
print("What to do with the second roll?")
cmds_2 = input().split(",")
2018-02-13 13:38:49 +00:00
while not Board.is_move_valid(new_board, roll[1], self.sym, cmds_2):
2018-02-05 21:31:34 +00:00
print("Invalid move")
cmds_2 = input().split(",")
2018-02-13 13:38:49 +00:00
return Board.move_thing(new_board, self.sym, int(cmds_2[0]), int(cmds_2[1]))
2018-02-05 21:31:34 +00:00