home *** CD-ROM | disk | FTP | other *** search
- # PPUZZLE.TPI
- # by Kent Peterson 10/30/93
-
- defstr board$
- "ABCDEFGHIJKLMNOP" board$ store
-
- define display
- 0 0 locate
- " 1|" print$
- board$ fetch dup$ 4 left$ print$ cr
- " 2|" print$
- dup$ 5 4 mid$ print$ cr
- " 3|" print$
- dup$ 9 4 mid$ print$ cr
- " 4|" print$
- 4 right$ print$ cr
- " -+----" print$ cr
- " |5678" print$ cr
- enddef
-
- define move ( n -- )
- # Changes the board in one of 8 ways
- case 1 of
- 2 3 4 1 5 6 7 8 9 10 11 12 13 14 15 16
- endof
- 2 of
- 1 2 3 4 6 7 8 5 9 10 11 12 13 14 15 16
- endof
- 3 of
- 1 2 3 4 5 6 7 8 10 11 12 9 13 14 15 16
- endof
- 4 of
- 1 2 3 4 5 6 7 8 9 10 11 12 14 15 16 13
- endof
- 5 of
- 5 2 3 4 9 6 7 8 13 10 11 12 1 14 15 16
- endof
- 6 of
- 1 6 3 4 5 10 7 8 9 14 11 12 13 2 15 16
- endof
- 7 of
- 1 2 7 4 5 6 11 8 9 10 15 12 13 14 3 16
- endof
- 8 of
- 1 2 3 8 5 6 7 12 9 10 11 16 13 14 15 4
- endof
- endcase
- ""
- 16 do
- board$ fetch 1 mid$ swap$ +$
- loop
- board$ store
- enddef
-
- define getmove ( -- move )
- "12345678" 27 chr$ +$
- begin inkey$ len instr *
- dup if dup drop$ endif drop$
- until
- enddef
-
- cls
- randomize
- 1 10 locate "Shuffling..." print$
- 10 do display 8 random move loop
- 1 10 locate "Use the keys" print$
- 2 10 locate "1-8 to put the" print$
- 3 10 locate "puzzle back into" print$
- 4 10 locate "alphabetical order." print$
- 5 10 locate "Press [ESC] to exit." print$
- begin
- display
- getmove
- dup 9 = if bye
- else move endif
- 0 until
-