def main():
    sf = SolverFactory()
    all_files = glob.glob('examples/*.png')
    if not os.path.exists('astar'):
        os.mkdir('astar')
    if not os.path.exists('breadthfirst'):
        os.mkdir('breadthfirst')
    for input_file in all_files:
        solve(sf, 'astar','breadthfirst', input_file)
예제 #2
0
def main():
    sf = SolverFactory()
    parser = argparse.ArgumentParser()
    parser.add_argument("-m", "--method", nargs='?', const=sf.Default, default=sf.Default,
                        choices=sf.Choices)
    parser.add_argument("input_file")
    parser.add_argument("output_file")
    args = parser.parse_args()

    solve(sf, args.method, args.input_file, args.output_file)
예제 #3
0
def solve_maze(input_image_path, solve_method):
    image = Image.open(input_image_path)

    image_width = image.size[0]
    image_height = image.size[1]

    # Obtain a list of image pixel data where we only fetch the R (in RGB) values (signified by band index 0)
    # We're not interested in any particular band as we're working solely with black and white
    # This means we only expect 0 or 255 as values, anything else is invalid as per business rules
    maze_pixel_data = list(image.getdata(0))

    # Construct the maze, which will create a model for the playingfield, including all squares and their neighbours
    maze = Maze(image_width, image_height, maze_pixel_data)

    # Construct the solver based on the input method
    solveFactory = SolverFactory()
    solver = solveFactory.create(solve_method)

    # Solve the maze and return the result
    return solver.solve(maze)
예제 #4
0
def main():
    sf = SolverFactory()
    parser = argparse.ArgumentParser()
    parser.add_argument("-m",
                        "--method",
                        nargs='?',
                        const=sf.Default,
                        default=sf.Default,
                        choices=sf.Choices)
    parser.add_argument("input_file")
    # parser.add_argument("output_file")
    args = parser.parse_args()

    filename, file_extension = os.path.splitext(args.input_file)
    output = "{}-{}-solved-{}{}".format(
        filename, args.method,
        datetime.now().strftime("%d%m%YT%H%M%S"), file_extension)

    # solve(sf, args.method, args.input_file, args.output_file)
    solve(sf, args.method, args.input_file, output)
예제 #5
0
def profile():
    for m in methods:
        for i in inputs:
            with tempfile.NamedTemporaryFile(suffix='.png') as tmp:
                solve(SolverFactory(), m, "examples/%s.png" % i, tmp.name)
예제 #6
0
 def test_default(self):
     sf = SolverFactory()
     solve(sf, sf.Default, "examples/normal.png", tempfile.mkstemp())
예제 #7
0
import numpy as np
from PIL import Image
import time
from mazes import Maze
from factory import SolverFactory

# Read command line arguments - the python argparse class is convenient here.
import argparse
sf = SolverFactory()
parser = argparse.ArgumentParser()
parser.add_argument("-m",
                    "--method",
                    nargs='?',
                    const=sf.Default,
                    default=sf.Default,
                    choices=sf.Choices)
parser.add_argument("input_file")
parser.add_argument("output_file")
args = parser.parse_args()

method = args.method

# Load Image
print("Loading Image")
im = Image.open(args.input_file)

# Create the maze (and time it) - for many mazes this is more time consuming than solving the maze
print("Creating Maze")
t0 = time.time()
maze = Maze(im)
t1 = time.time()