Exemplo n.º 1
0
def generate_moves(board: Board, color: str, dice: Dice, verbose=False):
    root = MoveNode(color + " " + str(dice), board_after=board, deep=0)
    get_moves(color, dice.getDistances(), board.farthestBack(color), root)

    min_die = min(dice.getDice())
    max_die = max(dice.getDice())
    depth = 0
    used_dict = {min_die: set(), max_die: set()}
    moves_dict = {}
    for move in PreOrderIter(root):
        deep = move.deep
        if deep > depth:
            depth = deep

        if deep not in moves_dict:
            moves_dict[deep] = {move}
        else:
            moves_dict[deep].add(move)

        if depth == 1:
            used_dict[move.die].add(move)

    if depth == 1 and used_dict[min_die] and used_dict[max_die]:
        moves = used_dict[max_die]
    else:
        moves = moves_dict[depth]

    if verbose:
        print(board)
        print(dice)
        print(moves)

    return moves
Exemplo n.º 2
0
    def apply(self, board: Board):
        if getRelativePointLocation(self.color, self.start) > self.die:
            raise IllegalMoveException("Move cannot be made given the die value " + str(self.die))
        elif getRelativePointLocation(self.color, self.start) < self.die:
            if board.farthestBack(self.color) != self.start:
                raise IllegalMoveException(
                    "You must move the farthest back piece off that you can with die " + str(self.die))

        scratch = board.__deepcopy__()

        # VALID MOVEMENT
        scratch.removeFromLocation(self.color, self.start)
        scratch.moveOff(self.color)

        return scratch