home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
logo
/
winlogo
/
lib
/
hanoi.lg
< prev
next >
Wrap
Text File
|
1992-07-22
|
1KB
|
54 lines
to hanoi :number
!
! Towers of Hanoi
! Meyer A. Billmers
! November, 1983
!
! This procedure plays a graphic version of the Towers of Hanoi puzzle
! The argument is the number of disks in the configuration.
!
! c.f. putdisk, towercnt,towerset, hanoihlpr
!
local "from
local "to
local "other
local "datfil
make "datfil openw "hanoi.dat
fileprint :datfil (sentence [Hanoi of ] :number [towers Started at: ] time)
! to change the starting and ending needles, change the next three assignments
make "from 1
make "to 3
make "other 2
cs
ht
! first we draw the table and the golden needles
pencolor 255 0 0
pu
setxy "-350 "-100
pd
setxy 350 "-100
pu
setx -240
pd
fd 250
pu
setxy "-15 "-100
pd
fd 250
pu
setxy 210 "-100
pd
fd 250
make "tower1 0
make "tower2 0
make "tower3 0
! draw the initial stack of disks. note that putdisk draws the
! "fixed up" towers.
repeat :number [putdisk :from :number - repcount + 1 "final; \
if :from = 1 [make "tower1 :tower1 + 1] \
[if :from = 2 [make "tower2 :tower2 + 1] [make "tower3 :tower3 + 1]]]
hanoihlpr :number :from :to :other
fileprint :datfil (sentence [Hanoi Ended at: ] time)
close :datfil
end