Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Maze-solving/Red/maze-solving.red
Normal file
25
Task/Maze-solving/Red/maze-solving.red
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
Red ["Maze solver"]
|
||||
|
||||
do %mazegen.red
|
||||
print [
|
||||
"start:" start: random size - 1x1
|
||||
"end:" end: random size - 1x1
|
||||
]
|
||||
isnew?: function [pos] [not find visited pos]
|
||||
open?: function [pos d] [
|
||||
o: pos/y * size/x + pos/x + 1
|
||||
0 = pick walls/:o d
|
||||
]
|
||||
expand: function [pos][
|
||||
either any [
|
||||
all [pos/x > 0 isnew? p: pos - 1x0 open? p 1]
|
||||
all [pos/x < (size/x - 1) isnew? p: pos + 1x0 open? pos 1]
|
||||
all [pos/y > 0 isnew? p: pos - 0x1 open? p 2]
|
||||
all [pos/y < (size/y - 1) isnew? p: pos + 0x1 open? pos 2]
|
||||
][append visited p insert path p][remove path]
|
||||
path/1
|
||||
]
|
||||
path: reduce [start]
|
||||
visited: []
|
||||
until [end = expand path/1]
|
||||
print reverse path
|
||||
Loading…
Add table
Add a link
Reference in a new issue