Alexander Munch-Hansen
926a331df0
again and it is possible to play against the ai. There is no flag for this yet, so this has to be added.
65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
from board import Board
|
|
|
|
|
|
class Player:
|
|
|
|
|
|
def __init__(self, sym):
|
|
self.sym = sym
|
|
|
|
|
|
def get_sym(self):
|
|
return self.sym
|
|
|
|
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])
|
|
return sets
|
|
|
|
|
|
def tmp_name(self, from_board, to_board, roll, player, total_moves):
|
|
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])
|
|
print(to_board)
|
|
print(board_set)
|
|
if to_board in board_set[0]:
|
|
total_moves -= board_set[1]
|
|
# if it's not the sum of the moves
|
|
if idx < 2:
|
|
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):
|
|
total_moves = roll[0] + roll[1] if roll[0] != roll[1] else int(roll[0])*4
|
|
move = ""
|
|
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)
|
|
total_moves, roll, board = self.tmp_name(board, to_board, list(roll), self.get_sym(), total_moves)
|
|
print(Board.pretty(board))
|
|
return board |