2018-03-09 20:02:41 +00:00
|
|
|
from board import Board
|
2018-03-09 13:19:31 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Player:
|
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, sym):
|
|
|
|
self.sym = sym
|
|
|
|
|
|
|
|
|
|
|
|
def get_sym(self):
|
|
|
|
return self.sym
|
|
|
|
|
2018-05-13 21:54:13 +00:00
|
|
|
def calc_move_sets(self, from_board, roll, player):
|
|
|
|
board = from_board
|
|
|
|
sets = []
|
|
|
|
total = 0
|
|
|
|
for r in roll:
|
|
|
|
# print("Value of r:",r)
|
|
|
|
sets.append([Board.calculate_legal_states(board, player, [r,0]), r])
|
|
|
|
total += r
|
|
|
|
sets.append([Board.calculate_legal_states(board, player, [total,0]), total])
|
2018-05-18 12:55:10 +00:00
|
|
|
print(sets)
|
2018-05-13 21:54:13 +00:00
|
|
|
return sets
|
|
|
|
|
|
|
|
|
2018-05-18 12:55:10 +00:00
|
|
|
def tmp_name(self, from_board, to_board, roll, player, total_moves, is_quad = False):
|
2018-05-13 21:54:13 +00:00
|
|
|
sets = self.calc_move_sets(from_board, roll, player)
|
|
|
|
return_board = from_board
|
|
|
|
for idx, board_set in enumerate(sets):
|
|
|
|
|
|
|
|
board_set[0] = list(board_set[0])
|
2018-05-18 12:55:10 +00:00
|
|
|
# print(to_board)
|
|
|
|
# print(board_set)
|
2018-05-13 21:54:13 +00:00
|
|
|
if to_board in board_set[0]:
|
|
|
|
total_moves -= board_set[1]
|
|
|
|
# if it's not the sum of the moves
|
2018-05-18 12:55:10 +00:00
|
|
|
if idx < (4 if is_quad else 2):
|
2018-05-13 21:54:13 +00:00
|
|
|
roll[idx] = 0
|
|
|
|
else:
|
|
|
|
roll = [0,0]
|
|
|
|
return_board = to_board
|
|
|
|
break
|
|
|
|
return total_moves, roll, return_board
|
|
|
|
|
|
|
|
def make_human_move(self, board, roll):
|
2018-05-18 12:55:10 +00:00
|
|
|
is_quad = roll[0] == roll[1]
|
|
|
|
total_moves = roll[0] + roll[1] if not is_quad else int(roll[0])*4
|
|
|
|
if is_quad:
|
|
|
|
roll = [roll[0]]*4
|
|
|
|
|
2018-05-13 21:54:13 +00:00
|
|
|
while total_moves != 0:
|
|
|
|
while True:
|
|
|
|
print("You have {roll} left!".format(roll=total_moves))
|
|
|
|
move = input("Pick a move!\n")
|
|
|
|
pot_move = move.split("/")
|
|
|
|
if len(pot_move) == 2:
|
|
|
|
try:
|
|
|
|
pot_move[0] = int(pot_move[0])
|
|
|
|
pot_move[1] = int(pot_move[1])
|
|
|
|
move = pot_move
|
|
|
|
break;
|
|
|
|
except TypeError:
|
|
|
|
print("The correct syntax is: 2/5 for a move from index 2 to 5.")
|
|
|
|
|
|
|
|
to_board = Board.apply_moves_to_board(board, self.get_sym(), move)
|
2018-05-18 12:55:10 +00:00
|
|
|
total_moves, roll, board = self.tmp_name(board, to_board, list(roll), self.get_sym(), total_moves, is_quad)
|
2018-05-13 21:54:13 +00:00
|
|
|
print(Board.pretty(board))
|
|
|
|
return board
|