mirror of
https://github.com/rfivet/uemacs.git
synced 2025-01-11 02:36:40 -05:00
Test maze scripts using subroutines instead of stored procedures. (Avoid leftover buffers after execution).
This commit is contained in:
parent
296f0af96c
commit
81d6f76c78
87
blindmaz.cmd
87
blindmaz.cmd
@ -4,13 +4,14 @@
|
||||
# either maze.cmd, sharpmaz.cmd or floodmaz.cmd
|
||||
execute-file floodmaz.cmd
|
||||
|
||||
set %meml $curline # save entrance location
|
||||
set %memc $curcol
|
||||
set %x &add %memc 1
|
||||
set %y %meml
|
||||
set %dotc &asc "•" # alternatively use "."
|
||||
set $curchar %dotc
|
||||
set %x &add $curcol 1
|
||||
set %y $curline
|
||||
end-of-line
|
||||
set %stopcol &sub $curcol 1
|
||||
|
||||
# X-Y offset for absolute direction: east, south, west, north
|
||||
set %DX0 1
|
||||
set %DY0 0
|
||||
set %DX1 0
|
||||
@ -20,53 +21,41 @@ set %DY2 0
|
||||
set %DX3 0
|
||||
set %DY3 -1
|
||||
|
||||
set %dotc &asc "•" # alternatively use "."
|
||||
|
||||
!store peep
|
||||
set %OX &ind &cat "%DX" %nD
|
||||
set %OY &ind &cat "%DY" %nD
|
||||
set %nx &add %x %OX
|
||||
set %ny &add %y %OY
|
||||
set $curline %ny
|
||||
set $curcol %nx
|
||||
!if &or &equ $curchar 32 &equ $curchar %dotc
|
||||
!if &equ $curchar 32
|
||||
set %C %dotc
|
||||
!else
|
||||
set %C &asc " " # erase when backtracking (or highlight)
|
||||
!endif
|
||||
set %D %nD
|
||||
set $curchar %C
|
||||
set $curline %y
|
||||
set $curcol %x
|
||||
set $curchar %C
|
||||
set %x &add %nx %OX
|
||||
set %y &add %ny %OY
|
||||
set $curline %y
|
||||
set $curcol %x
|
||||
set %res TRUE
|
||||
!else
|
||||
set %res FALSE
|
||||
!endif
|
||||
update-screen
|
||||
!endm
|
||||
|
||||
set %D 0 # looking EAST
|
||||
set %absD 0 # absolute direction: looking EAST
|
||||
!while &les %x %stopcol
|
||||
set %nD &mod &add %D 3 4 # Can go left?
|
||||
run peep
|
||||
!if ¬ %res
|
||||
set %nD %D # Can go straight?
|
||||
run peep
|
||||
!if ¬ %res
|
||||
set %nD &mod &add %D 1 4 # Can go right?
|
||||
run peep
|
||||
!if ¬ %res
|
||||
set %D &mod &add %D 2 4 # Go back!
|
||||
# try move on left, right or front
|
||||
set %relD 3 # 3, 0, 1, 2 == left, front, right, back
|
||||
!while ¬ &equ %relD 2
|
||||
set %newD &mod &add %absD %relD 4
|
||||
set %offX &ind &cat "%DX" %newD
|
||||
set %offY &ind &cat "%DY" %newD
|
||||
set %nx &add %x %offX
|
||||
set %ny &add %y %offY
|
||||
set $curline %ny
|
||||
set $curcol %nx
|
||||
!if &or &equ $curchar 32 &equ $curchar %dotc
|
||||
!if &equ $curchar 32
|
||||
set %C %dotc
|
||||
!else
|
||||
set %C &asc " " # erase (or highlight) when backtracking
|
||||
!endif
|
||||
set %absD %newD
|
||||
set $curchar %C
|
||||
set $curline %y
|
||||
set $curcol %x
|
||||
set $curchar %C
|
||||
set %x &add %nx %offX
|
||||
set %y &add %ny %offY
|
||||
update-screen
|
||||
!goto moveon
|
||||
!endif
|
||||
!endif
|
||||
set %relD &mod &add %relD 1 4
|
||||
!endwhile
|
||||
# else turn around
|
||||
set %absD &mod &add %absD 2 4 # face back!
|
||||
:moveon
|
||||
!endwhile
|
||||
set $curline %meml
|
||||
set $curcol %memc
|
||||
|
||||
set $curline %y
|
||||
set $curcol %x
|
||||
unmark-buffer
|
||||
|
69
floodmaz.cmd
69
floodmaz.cmd
@ -1,4 +1,4 @@
|
||||
## floodmaz.cmd -- solve maze by painting right wall
|
||||
## floodmaz.cmd -- solve maze by painting wall on the right
|
||||
|
||||
# 6 set $seed
|
||||
# either maze.cmd or sharpmaz.cmd
|
||||
@ -8,39 +8,9 @@ set %thisbuf $cbufname
|
||||
set %meml $curline
|
||||
set %memc $curcol
|
||||
|
||||
!store pushxy # push x y
|
||||
set %x $curcol
|
||||
set %y $curline
|
||||
select-buffer stack
|
||||
beginning-of-file
|
||||
insert-string %x
|
||||
newline
|
||||
insert-string %y
|
||||
newline
|
||||
select-buffer %thisbuf
|
||||
!endm
|
||||
|
||||
!store popxy # pop x y
|
||||
select-buffer stack
|
||||
beginning-of-file
|
||||
set %x $line
|
||||
1 kill-to-end-of-line
|
||||
set %y $line
|
||||
1 kill-to-end-of-line
|
||||
select-buffer %thisbuf
|
||||
set $curline %y
|
||||
set $curcol %x
|
||||
!endm
|
||||
|
||||
!store probe
|
||||
!if ¬ &or &equ $curchar %NC &equ $curchar 32
|
||||
run pushxy
|
||||
!endif
|
||||
!endm
|
||||
|
||||
set $curline 1
|
||||
set $curcol 0
|
||||
run pushxy #push stop position
|
||||
!gosub pushxy #push stop position
|
||||
set %x 1
|
||||
set $curline 4
|
||||
set $curcol %x
|
||||
@ -51,16 +21,25 @@ set %NC &asc "█"
|
||||
set %cc $curcol
|
||||
set %ll $curline
|
||||
set $curcol &add %cc 1
|
||||
run probe
|
||||
!gosub probe
|
||||
set $curcol &add %cc -1
|
||||
run probe
|
||||
!gosub probe
|
||||
set $curline &add %ll 1
|
||||
set $curcol %cc
|
||||
run probe
|
||||
!gosub probe
|
||||
set $curline &add %ll -1
|
||||
set $curcol %cc
|
||||
run probe
|
||||
run popxy
|
||||
!gosub probe
|
||||
# pop x y
|
||||
select-buffer stack
|
||||
beginning-of-file
|
||||
set %x $line
|
||||
1 kill-to-end-of-line
|
||||
set %y $line
|
||||
1 kill-to-end-of-line
|
||||
select-buffer %thisbuf
|
||||
set $curline %y
|
||||
set $curcol %x
|
||||
!endwhile
|
||||
|
||||
set $curline %meml
|
||||
@ -70,3 +49,19 @@ unmark-buffer
|
||||
select-buffer %thisbuf
|
||||
unmark-buffer
|
||||
delete-buffer stack
|
||||
!return
|
||||
|
||||
:probe
|
||||
!if ¬ &or &equ $curchar %NC &equ $curchar 32
|
||||
:pushxy # push x y
|
||||
set %x $curcol
|
||||
set %y $curline
|
||||
select-buffer stack
|
||||
beginning-of-file
|
||||
insert-string %x
|
||||
newline
|
||||
insert-string %y
|
||||
newline
|
||||
select-buffer %thisbuf
|
||||
!endif
|
||||
!return
|
||||
|
23
sharpmaz.cmd
23
sharpmaz.cmd
@ -15,13 +15,6 @@ set %old $line
|
||||
set $line %spaces
|
||||
next-line
|
||||
|
||||
!store check
|
||||
!if ¬ &equ $curchar 32
|
||||
set %v &add %v %inc
|
||||
!endif
|
||||
set %inc &tim %inc 2
|
||||
!endm
|
||||
|
||||
!while &less $curline %el
|
||||
set $curcol 1
|
||||
!while &less $curcol %ec
|
||||
@ -29,15 +22,15 @@ next-line
|
||||
set %v 0
|
||||
set %inc 1
|
||||
previous-line
|
||||
run check
|
||||
!gosub check
|
||||
next-line
|
||||
backward-character
|
||||
run check
|
||||
!gosub check
|
||||
2 forward-character
|
||||
run check
|
||||
!gosub check
|
||||
next-line
|
||||
backward-character
|
||||
run check
|
||||
!gosub check
|
||||
previous-line
|
||||
# alternatively use single width "╳╵╴┘╶└─┴╷│┐┤┌├┬┼"
|
||||
set $curchar &asc &mid "╳╹╸┛╺┗━┻╻┃┓┫┏┣┳╋" &add %v 1 1
|
||||
@ -51,3 +44,11 @@ beginning-of-file
|
||||
set $line %old
|
||||
set $curline %meml
|
||||
set $curcol %memc
|
||||
!return
|
||||
|
||||
:check
|
||||
!if ¬ &equ $curchar 32
|
||||
set %v &add %v %inc
|
||||
!endif
|
||||
set %inc &tim %inc 2
|
||||
!return
|
||||
|
Loading…
Reference in New Issue
Block a user