Exemple #1
0
def add_information(maze, program_state):
    passable = mazedef.get_passable_relative_direction(
        maze, program_state["x"], program_state["y"], program_state["direction"], mazedef.can_pass_through
    )
    if passable[FRONT]:
        program_state["logs"].append("".join(["[    ", "Front is passable", "]"]))
    else:
        program_state["logs"].append("".join(["[    ", "Front is not passable", "]"]))

    if passable[BACK]:
        program_state["logs"].append("".join(["[    ", "Back is passable", "]"]))
    else:
        program_state["logs"].append("".join(["[    ", "Back is not passable", "]"]))

    if passable[LEFT]:
        program_state["logs"].append("".join(["[    ", "Left is passable", "]"]))
    else:
        program_state["logs"].append("".join(["[    ", "Left is not passable", "]"]))

    if passable[RIGHT]:
        program_state["logs"].append("".join(["[    ", "Right is passable", "]"]))
    else:
        program_state["logs"].append("".join(["[    ", "Right is not passable", "]"]))

    if program_state["x"] == maze["start_x"] and program_state["y"] == maze["start_y"]:
        program_state["logs"].append("".join(["[    ", "At entrance", "]"]))
Exemple #2
0
def is_decision(maze, program_state):
    passable = mazedef.get_passable_relative_direction(
        maze, program_state["x"], program_state["y"], program_state["direction"], mazedef.can_pass_through
    )
    num_exit = sum(passable)
    if num_exit > 2:
        return True
    if program_state["x"] == maze["start_x"] and program_state["y"] == maze["start_y"]:
        return True
    return False
Exemple #3
0
def move_in_this_direction(maze, traverser):
    time_required = 1
    passable = mazedef.get_passable_relative_direction(maze, traverser["x"], traverser["y"], traverser["direction"], mazedef.can_pass_through)
    direction = traverser["direction"]
    if passable[FRONT]:
        direction = traverser["direction"]
    else:
        if passable[LEFT] and passable[RIGHT]:
            return False, 0
        elif passable[LEFT]:
            direction = mazedef.get_direction_of(LEFT, direction)
        elif passable[RIGHT]:
            direction = mazedef.get_direction_of(RIGHT, direction)
        else:
            return False, 0

    traverser["direction"] = direction
    direction_mod_x, direction_mod_y = mazedef.get_direction_mod(traverser["direction"])
    target_pos_x, target_pos_y = traverser["x"] + direction_mod_x, traverser["y"] + direction_mod_y
    kime_required = mazedef.move_to(maze, target_pos_x, target_pos_y, traverser)
    return True, time_required