From 488481b1e530374f5a31a856ee758823d81a068d Mon Sep 17 00:00:00 2001 From: Dilawar Singh Date: Mon, 15 Nov 2021 14:49:29 +0530 Subject: [PATCH] Added first version. --- examples/S99_more/maze/maze.txt | 138 +++++++++++++++++++++++++++ examples/S99_more/maze/maze_solve.py | 58 +++++++++++ 2 files changed, 196 insertions(+) create mode 100644 examples/S99_more/maze/maze.txt create mode 100644 examples/S99_more/maze/maze_solve.py diff --git a/examples/S99_more/maze/maze.txt b/examples/S99_more/maze/maze.txt new file mode 100644 index 00000000..efd4c4fe --- /dev/null +++ b/examples/S99_more/maze/maze.txt @@ -0,0 +1,138 @@ +-0.5 -0.5 -0.5 9.5 +-0.5 9.5 9 9.5 +9.5 -0.5 9.5 9.5 +0 -0.5 9.5 -0.5 +0.49999999999999994 -0.5 0.5 0.5 +0.5 1.5 -0.5 1.5 +-0.5 1.5 0.5 1.5 +0.5 2.5 -0.5 2.5 +-0.5 2.5 0.5 2.5 +0.5 4.5 -0.5 4.5 +-0.5 4.5 0.5 4.5 +0.49999999999999994 5.5 0.5 6.5 +0.5 7.5 -0.5 7.5 +-0.5 7.5 0.5 7.5 +0.49999999999999994 7.5 0.5 8.5 +1.5 -0.5 1.5 0.5 +0.5000000000000001 0.5 0.4999999999999999 -0.5 +1.5 1.5 0.5 1.5 +0.5 1.5 1.5 1.5 +1.5 1.5 1.5 2.5 +1.5 5.5 0.5 5.5 +1.5 6.5 0.5 6.5 +1.5 5.5 1.5 6.5 +0.5 5.5 1.5 5.5 +0.5000000000000001 6.5 0.4999999999999999 5.5 +0.5 6.5 1.5 6.5 +0.5000000000000001 8.5 0.4999999999999999 7.5 +1.5 7.5 1.5 8.5 +1.5 0.5 1.5 -0.5 +2.5 2.5 1.5 2.5 +1.5 2.5 1.5 1.5 +2.5 3.5 1.5 3.5 +2.5 2.5 2.5 3.5 +1.5 2.5 2.5 2.5 +1.5 3.5 2.5 3.5 +2.5 3.5 2.5 4.5 +1.5 6.5 1.5 5.5 +1.5 8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 3.5 5.5 3.5 +5.5 4.5 5.5 3.5 +5.5 3.5 6.5 3.5 +6.5 5.5 5.5 5.5 +5.5 5.5 6.5 5.5 +6.5 7.5 5.5 7.5 +5.5 7.5 5.5 6.5 +5.5 7.5 6.5 7.5 +7.5 -0.5 7.5 0.5 +6.5 0.5 6.5 -0.5 +6.5 1.5 6.5 0.5 +7.5 0.5 7.5 1.5 +7.5 2.5 6.5 2.5 +7.5 3.5 6.5 3.5 +6.5 2.5 7.5 2.5 +6.5 3.5 7.5 3.5 +7.5 6.5 7.5 7.5 +7.5 7.5 7.5 8.5 +8.5 -0.5 8.5 0.5 +7.5 0.5 7.5 -0.5 +8.5 0.49999999999999994 7.5 0.5000000000000001 +7.5 1.5 7.5 0.5 +7.5 0.5 8.5 0.5 +8.5 2.5 8.5 3.5 +8.5 4.5 7.5 4.5 +8.5 3.5 8.5 4.5 +7.5 4.5 8.5 4.5 +7.5 7.5 7.5 6.5 +8.5 8.5 7.5 8.5 +7.5 8.5 7.5 7.5 +7.5 8.5 8.5 8.5 +8.5 8.5 8.5 9.5 +8.5 0.5 8.5 -0.5 +9.5 1.5 8.5 1.5 +8.5 1.5 9.5 1.5 +9.5 2.5 8.5 2.5 +8.5 3.5 8.5 2.5 +8.5 2.5 9.5 2.5 +8.5 4.5 8.5 3.5 +9.5 5.5 8.5 5.5 +8.5 5.5 9.5 5.5 +8.5 9.5 8.5 8.5 diff --git a/examples/S99_more/maze/maze_solve.py b/examples/S99_more/maze/maze_solve.py new file mode 100644 index 00000000..dd08aad9 --- /dev/null +++ b/examples/S99_more/maze/maze_solve.py @@ -0,0 +1,58 @@ +# +# Solve a maze using brute force +# + +__author__ = "Dilawar Singh" +__email__ = "dilawar.s.rajput@gmail.com" + +import math +import smoldyn +from pathlib import Path + + +def get_axis(line): + x0, y0, x1, y1 = line + theta = math.atan2(y1 - y0, x1 - x0) + if math.isclose(theta, 0.0) or math.isclose(theta, math.pi): + return "+y" + return "+x" + + +def add_maze(s, mazefile): + panels = [] + offset = 1.5 + scale = 10 + with open(mazefile, "r") as f: + for i, l in enumerate(f.read().strip().split("\n")): + line = [scale * (offset + float(x)) for x in l.split()] + axis = get_axis(line) + x0, y0, x1, y1 = line + r = s.addRectangle( + corner=[x0, y0], + dimensions=[max((x1 - x0), (y1 - y0))], + axis=axis, + name=f"r{i}", + ) + panels.append(r) + # close the entry notch + r = s.addRectangle( + corner=[10, 10], + dimensions=[30], + axis="+y", + name=f"rrr", + ) + panels.append(r) + return panels + + +s = smoldyn.Simulation(low=[0, 0], high=[120, 120]) +A = s.addSpecies("A", difc=2, color="blue") +A.addToSolution(1000, pos=[15, 15]) + +panels = add_maze(s, Path(__file__).parent / "maze.txt") +maze = s.addSurface("maze", panels=panels) +maze.setAction("front", [A], "reflect") +maze.setAction("back", [A], "reflect") +maze.setStyle("both", thickness=1, color='red') +s.addGraphics("opengl", iter=50) +s.run(3000, dt=0.01)