以下のFORTHのソースコードの解説にも書かれているように、並列処理を巧みに使って迷路を探索している。一つ一つのセルは、その周囲の状態しか「見えない」ので、平面的な迷路の広がりを知ることは不可能だ。それにもかかわらず、一定のルールを繰り返すことにより、出発点から到達点へのルートを探し当てることができるのが興味深い。
MAZE.EXP -- By Dave Hiebeler, July 1989
This is a simple parallel recursive maze-solving algorithm.
I'm pretty sure that it won't work for certain classes of
mazes, such as when there is a loop on the path between start
and finish and the loop is symmetric with respect to distance
around both sides. But this program will solve mazes without
loops, and with loops that are asymmetric, at least the ones
I've tested.
It might be possible to make it work for the other kinds of
mazes; I'm not sure about that though. This is just a prototype
I threw together one morning.
NEW-EXPERIMENT CAM-A N/VONN &/CENTERS
\ OPEN-PATTERN MAZELBL.PAT 0 FILE>PL IRGB.map
: WALLSUM NORTHS 1 = 1 AND SOUTHS 1 = 1 AND EASTS 1 = 1 AND
WESTS 1 = 1 AND + + + ;
: GOODSUM NORTHS 3 = 1 AND SOUTHS 3 = 1 AND EASTS 3 = 1 AND
WESTS 3 = 1 AND + + + ;
: MAZERULE
CENTERS 3 = NORTHS 2 = SOUTHS 2 = EASTS 2 = WESTS 2 = OR OR
OR AND GOODSUM 1 = AND IF 2 >PLNA ELSE
CENTERS 2 = IF
2 >PLNA ELSE
CENTERS 0=
IF GOODSUM { 0 3 2 2 2 } >PLNA
ELSE WALLSUM 3 = &CENTERS 0 = CENTERS 3 = AND AND
IF 2 >PLNA ELSE CENTERS >PLNA THEN THEN
THEN THEN ;
MAKE-TABLE MAZERULE
CAM-B N/VONN
: STAY
CENTERS >PLNB ;
MAKE-TABLE STAY
: MYCMAP
ALPHA BETA BETA' OR OR >GREEN
ALPHA ALPHA' AND BETA BETA' OR OR >BLUE
ALPHA ALPHA' AND BETA BETA' OR OR >INTEN
ALPHA ALPHA' AND BETA BETA' OR OR >RED ;
: MAZE-CMAP
MAKE-CMAP MYCMAP ; ALIAS C
OPEN-PATTERN BIGMAZE.PAT
0 FILE>PL 1 FILE>PL 2 FILE>PL 3 FILE>PL
MAKE-CMAP MYCMAP
: RUNIT
300 IDLES
0 FILE>PL 1 FILE>PL 2 FILE>PL 3 FILE>PL
MAKE-CMAP MYCMAP
30 IDLES
1400 0 DO NEXT-STEP LOOP
30 IDLES ; ALIAS G
2VARIABLE STP
1000. STP 2!
: Q TIB 256 BLANK
STP 2@ (UD.) TIB 200 + SWAP CMOVE 256 #TIB !
32 CREATE-FILE ;
: W
STP 2@ (UD.) TIB 200 + SWAP CMOVE 256 #TIB !
OPEN-PATTERN ;
: R 0 4 IMAGE>FILE STP 2@ 1. D+ STP 2! NEXT-STEP ;
: Z Q 13 >IN ! W 24 >IN ! R 35 >IN ! ;
: ST200 200 0 DO Z STP 2@ D. LOOP ;
コメントする