Skip to content

Commit

Permalink
Test maze scripts using subroutines instead of stored procedures. (Av…
Browse files Browse the repository at this point in the history
…oid leftover buffers after execution).
  • Loading branch information
rfivet committed Sep 8, 2021
1 parent 296f0af commit 81d6f76
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 97 deletions.
87 changes: 38 additions & 49 deletions blindmaz.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 &not %res
set %nD %D # Can go straight?
run peep
!if &not %res
set %nD &mod &add %D 1 4 # Can go right?
run peep
!if &not %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 &not &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 changes: 32 additions & 37 deletions floodmaz.cmd
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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 &not &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
Expand All @@ -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
Expand All @@ -70,3 +49,19 @@ unmark-buffer
select-buffer %thisbuf
unmark-buffer
delete-buffer stack
!return

:probe
!if &not &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 changes: 12 additions & 11 deletions sharpmaz.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,22 @@ set %old $line
set $line %spaces
next-line

!store check
!if &not &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
!if &not &equ $curchar 32
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
Expand All @@ -51,3 +44,11 @@ beginning-of-file
set $line %old
set $curline %meml
set $curcol %memc
!return

:check
!if &not &equ $curchar 32
set %v &add %v %inc
!endif
set %inc &tim %inc 2
!return

0 comments on commit 81d6f76

Please sign in to comment.