| \ is shown below. |
\ is shown below. |
| |
|
| \ program is ANS FORTH with environmental dependency of case-insensitiv |
\ program is ANS FORTH with environmental dependency of case-insensitiv |
| \ source. Tested with gforth and bigFORTH |
\ source. Tested with gforth, bigFORTH and pfe |
| |
|
| \ really uses "dump" terminal: No PAGE, no AT-XY to speed things up |
\ bell (7) is replaced with "Wuff!" ;-) |
| \ Even bell (7) is replaced with "Wuff!" ;-) |
|
| \ (this is a german joke) |
\ (this is a german joke) |
| \ I don't like the keyboard interpreting CASE-statement either, but |
\ I don't like the keyboard interpreting CASE-statement either, but |
| \ was to lazy to use a table. |
\ was to lazy to use a table. |
| here mazes rot 1 ?DO @ LOOP ! |
here mazes rot 1 ?DO @ LOOP ! |
| 0 , 0 , here >maze ! 0 , ; |
0 , 0 , here >maze ! 0 , ; |
| : count-$ ( addr u -- n ) 0 rot rot |
: count-$ ( addr u -- n ) 0 rot rot |
| bounds ?DO I c@ [char] $ = - LOOP ; |
over + swap ?DO I c@ [char] $ = - LOOP ; |
| : m: ( "string" -- ) \ add a level line (top first!) |
: m: ( "string" -- ) \ add a level line (top first!) |
| -1 parse tuck 2dup count-$ >maze @ 1 cells - +! |
-1 parse tuck 2dup count-$ >maze @ 1 cells - +! |
| here swap move dup allot |
here swap move dup allot |
| |
|
| : .maze ( -- ) \ display maze |
: .maze ( -- ) \ display maze |
| 0 0 at-xy .score |
0 0 at-xy .score |
| cr maze-field bounds |
cr maze-field over + swap |
| DO I /maze type cr /maze chars +LOOP ; |
DO I /maze type cr /maze chars +LOOP ; |
| |
|
| : find-soko ( -- n ) |
: find-soko ( -- n ) |
| |
|
| : play-rule ( addr1 u1 addr2 u2 offset -- flag ) |
: play-rule ( addr1 u1 addr2 u2 offset -- flag ) |
| >r 2swap r@ apply-rule? |
>r 2swap r@ apply-rule? |
| IF r> apply-rule! true ELSE rdrop 2drop false THEN ; |
IF r> apply-rule! true ELSE r> drop 2drop false THEN ; |
| |
|
| \ player may move up, down, left and right |
\ player may move up, down, left and right |
| |
|
| S" &." S" .&" r@ play-rule IF r> soko +! EXIT THEN |
S" &." S" .&" r@ play-rule IF r> soko +! EXIT THEN |
| S" &* " S" .&$" r@ play-rule |
S" &* " S" .&$" r@ play-rule |
| IF r> soko +! 1 rocks +! -1 score +! EXIT THEN |
IF r> soko +! 1 rocks +! -1 score +! EXIT THEN |
| -1 moves +! rdrop ; |
-1 moves +! r> drop ; |
| |
|
| 1 move: soko-right |
1 move: soko-right |
| -1 move: soko-left |
-1 move: soko-left |
| [char] C OF soko-right false ENDOF |
[char] C OF soko-right false ENDOF |
| |
|
| [char] q OF true ENDOF |
[char] q OF true ENDOF |
| ENDCASE |
false swap ENDCASE |
| UNTIL ; |
UNTIL ; |
| |
|
| \ start game with "sokoban" |
\ start game with "sokoban" |
| |
|
| : sokoban ( -- ) |
: sokoban ( -- ) |
| 1 level IF play-loop ." Game finished!" THEN ; |
page 1 level IF play-loop ." Game finished!" THEN ; |
| |
|
| 001 new-maze |
001 new-maze |
| m: ##### |
m: ##### |