Exemplo n.º 1
0
        "-r",
        "--rotations",
        type=int,
        default=0,
        help="number of 90 degree clockwise rotations to perform")
    parser.add_argument("-p",
                        "--pathfinding",
                        type=str2bool,
                        default=False,
                        help="whether solve the maze")
    args = parser.parse_args()

    rows = args.rows
    columns = args.columns
    algorithm = get_algorithm(args.algorithm, AVAILABLE_ALGORITHMS)
    exporter = get_exporter(args.exporter, AVAILABLE_EXPORTERS)
    rotations = args.rotations
    pathfinding = args.pathfinding
    print("Algorithm: {}\nRows: {}\ncolumns: {}\nExporter: {}".format(
        args.algorithm, rows, columns, args.exporter))
    print("90deg Rotations: {}\nPathfinding: {}".format(
        rotations, pathfinding))

    grid = DistanceGrid(rows, columns)
    algorithm.on(grid)

    for num in range(rotations):
        grid = cast(DistanceGrid, Rotator().on(grid))

    if pathfinding:
        start, end = LongestPath.calculate(grid)

DEFAULT_EXPORTER = "UnicodeExporter"
AVAILABLE_EXPORTERS = ["ASCIIExporter", "UnicodeExporter"]


if __name__ == "__main__":
    if len(args.all) < 3:
        print("Usage:\nPYTHONPATH=. python3 demos/terminal_demo.py <rows> <columns> <algorithm> ", end="")
        print("[--exporter=<exporter>] [--rotations=<rotations>] [--pathfinding]")
        print("Valid algorithms: {}".format("|".join([algorithm.__name__ for algorithm in ALGORITHMS])))
        print("Valid exporters: {}".format("|".join(AVAILABLE_EXPORTERS)))
        print("Rotations is an integer value measuring number of 90 degree clockwise rotations to perform")
        print("Pathfinding flag shows distances between cells")
        exit(1)
    exporter, exporter_name = get_exporter(AVAILABLE_EXPORTERS, DEFAULT_EXPORTER)
    rotations = get_rotations()
    pathfinding = get_pathfinding()
    rows = int(args.all[0])
    columns = int(args.all[1])
    algorithm = get_algorithm()
    print("Algorithm: {}\nRows: {}\ncolumns: {}\nExporter: {}".format(algorithm.__name__, rows, columns, exporter_name))
    print("90deg Rotations: {}\nPathfinding: {}".format(rotations, pathfinding))

    if pathfinding:
        grid = DistanceGrid(rows, columns)  # type: Union[Grid, DistanceGrid]
    else:
        grid = Grid(rows, columns)

    grid = algorithm.on(grid)
Exemplo n.º 3
0
    return grid


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Render a maze")
    parser.add_argument("rows", type=int, help="number of rows")
    parser.add_argument("columns", type=int, help="number of columns")
    parser.add_argument("algorithm", type=str, help="algorithm to use")
    parser.add_argument("-e", "--exporter", type=str, default=DEFAULT_EXPORTER, help="maze exporter to use")
    parser.add_argument("-f", "--filename", type=str, default=None, help="file name to use")
    args = parser.parse_args()

    rows = args.rows
    columns = args.columns
    algorithm = get_algorithm(args.algorithm, AVAILABLE_ALGORITHMS)
    exporter = cast(Wolf3DExporter, get_exporter(args.exporter, AVAILABLE_EXPORTERS))
    filename = strftime("%d%H%M%S", gmtime())

    print("Algorithm: {}\nRows: {}\ncolumns: {}\nExporter: {}".format(args.algorithm, rows, columns, args.exporter))

    valid_map = False
    while not valid_map:
        grid = ColoredGrid(rows, columns)
        algorithm.on(grid)
        valid_map = exporter.is_valid(grid)
        if not valid_map:
            print("Generated maze has no east/west linked ending cell. Recreating...")

    exporter.render(grid, filename=filename)

    print("Generated maze map has {} enemies".format(exporter.enemies_count))