mirror of
https://github.com/rfivet/uemacs.git
synced 2025-04-22 02:42:18 -04: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
|
# either maze.cmd, sharpmaz.cmd or floodmaz.cmd
|
||||||
execute-file floodmaz.cmd
|
execute-file floodmaz.cmd
|
||||||
|
|
||||||
set %meml $curline # save entrance location
|
set %dotc &asc "•" # alternatively use "."
|
||||||
set %memc $curcol
|
set $curchar %dotc
|
||||||
set %x &add %memc 1
|
set %x &add $curcol 1
|
||||||
set %y %meml
|
set %y $curline
|
||||||
end-of-line
|
end-of-line
|
||||||
set %stopcol &sub $curcol 1
|
set %stopcol &sub $curcol 1
|
||||||
|
|
||||||
|
# X-Y offset for absolute direction: east, south, west, north
|
||||||
set %DX0 1
|
set %DX0 1
|
||||||
set %DY0 0
|
set %DY0 0
|
||||||
set %DX1 0
|
set %DX1 0
|
||||||
@ -20,53 +21,41 @@ set %DY2 0
|
|||||||
set %DX3 0
|
set %DX3 0
|
||||||
set %DY3 -1
|
set %DY3 -1
|
||||||
|
|
||||||
set %dotc &asc "•" # alternatively use "."
|
set %absD 0 # absolute direction: looking EAST
|
||||||
|
|
||||||
!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
|
|
||||||
!while &les %x %stopcol
|
!while &les %x %stopcol
|
||||||
set %nD &mod &add %D 3 4 # Can go left?
|
# try move on left, right or front
|
||||||
run peep
|
set %relD 3 # 3, 0, 1, 2 == left, front, right, back
|
||||||
!if ¬ %res
|
!while ¬ &equ %relD 2
|
||||||
set %nD %D # Can go straight?
|
set %newD &mod &add %absD %relD 4
|
||||||
run peep
|
set %offX &ind &cat "%DX" %newD
|
||||||
!if ¬ %res
|
set %offY &ind &cat "%DY" %newD
|
||||||
set %nD &mod &add %D 1 4 # Can go right?
|
set %nx &add %x %offX
|
||||||
run peep
|
set %ny &add %y %offY
|
||||||
!if ¬ %res
|
set $curline %ny
|
||||||
set %D &mod &add %D 2 4 # Go back!
|
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
|
!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
|
||||||
!endif
|
set %relD &mod &add %relD 1 4
|
||||||
|
!endwhile
|
||||||
|
# else turn around
|
||||||
|
set %absD &mod &add %absD 2 4 # face back!
|
||||||
|
:moveon
|
||||||
!endwhile
|
!endwhile
|
||||||
set $curline %meml
|
|
||||||
set $curcol %memc
|
set $curline %y
|
||||||
|
set $curcol %x
|
||||||
unmark-buffer
|
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
|
# 6 set $seed
|
||||||
# either maze.cmd or sharpmaz.cmd
|
# either maze.cmd or sharpmaz.cmd
|
||||||
@ -8,39 +8,9 @@ set %thisbuf $cbufname
|
|||||||
set %meml $curline
|
set %meml $curline
|
||||||
set %memc $curcol
|
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 $curline 1
|
||||||
set $curcol 0
|
set $curcol 0
|
||||||
run pushxy #push stop position
|
!gosub pushxy #push stop position
|
||||||
set %x 1
|
set %x 1
|
||||||
set $curline 4
|
set $curline 4
|
||||||
set $curcol %x
|
set $curcol %x
|
||||||
@ -51,16 +21,25 @@ set %NC &asc "█"
|
|||||||
set %cc $curcol
|
set %cc $curcol
|
||||||
set %ll $curline
|
set %ll $curline
|
||||||
set $curcol &add %cc 1
|
set $curcol &add %cc 1
|
||||||
run probe
|
!gosub probe
|
||||||
set $curcol &add %cc -1
|
set $curcol &add %cc -1
|
||||||
run probe
|
!gosub probe
|
||||||
set $curline &add %ll 1
|
set $curline &add %ll 1
|
||||||
set $curcol %cc
|
set $curcol %cc
|
||||||
run probe
|
!gosub probe
|
||||||
set $curline &add %ll -1
|
set $curline &add %ll -1
|
||||||
set $curcol %cc
|
set $curcol %cc
|
||||||
run probe
|
!gosub probe
|
||||||
run 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
|
||||||
!endwhile
|
!endwhile
|
||||||
|
|
||||||
set $curline %meml
|
set $curline %meml
|
||||||
@ -70,3 +49,19 @@ unmark-buffer
|
|||||||
select-buffer %thisbuf
|
select-buffer %thisbuf
|
||||||
unmark-buffer
|
unmark-buffer
|
||||||
delete-buffer stack
|
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
|
set $line %spaces
|
||||||
next-line
|
next-line
|
||||||
|
|
||||||
!store check
|
|
||||||
!if ¬ &equ $curchar 32
|
|
||||||
set %v &add %v %inc
|
|
||||||
!endif
|
|
||||||
set %inc &tim %inc 2
|
|
||||||
!endm
|
|
||||||
|
|
||||||
!while &less $curline %el
|
!while &less $curline %el
|
||||||
set $curcol 1
|
set $curcol 1
|
||||||
!while &less $curcol %ec
|
!while &less $curcol %ec
|
||||||
@ -29,15 +22,15 @@ next-line
|
|||||||
set %v 0
|
set %v 0
|
||||||
set %inc 1
|
set %inc 1
|
||||||
previous-line
|
previous-line
|
||||||
run check
|
!gosub check
|
||||||
next-line
|
next-line
|
||||||
backward-character
|
backward-character
|
||||||
run check
|
!gosub check
|
||||||
2 forward-character
|
2 forward-character
|
||||||
run check
|
!gosub check
|
||||||
next-line
|
next-line
|
||||||
backward-character
|
backward-character
|
||||||
run check
|
!gosub check
|
||||||
previous-line
|
previous-line
|
||||||
# alternatively use single width "╳╵╴┘╶└─┴╷│┐┤┌├┬┼"
|
# alternatively use single width "╳╵╴┘╶└─┴╷│┐┤┌├┬┼"
|
||||||
set $curchar &asc &mid "╳╹╸┛╺┗━┻╻┃┓┫┏┣┳╋" &add %v 1 1
|
set $curchar &asc &mid "╳╹╸┛╺┗━┻╻┃┓┫┏┣┳╋" &add %v 1 1
|
||||||
@ -51,3 +44,11 @@ beginning-of-file
|
|||||||
set $line %old
|
set $line %old
|
||||||
set $curline %meml
|
set $curline %meml
|
||||||
set $curcol %memc
|
set $curcol %memc
|
||||||
|
!return
|
||||||
|
|
||||||
|
:check
|
||||||
|
!if ¬ &equ $curchar 32
|
||||||
|
set %v &add %v %inc
|
||||||
|
!endif
|
||||||
|
set %inc &tim %inc 2
|
||||||
|
!return
|
||||||
|
Loading…
x
Reference in New Issue
Block a user