home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
elan
/
demo
/
hanoi.eln
< prev
next >
Wrap
Text File
|
1987-08-18
|
2KB
|
86 lines
PROC think (INT CONST a):
sleep (random (0, a))
ENDPROC think;
PROC spaces (INT CONST n):
put (n * " ")
ENDPROC spaces;
PROC showstack (ROW 3 INT CONST s):
INT VAR i, j;
FOR i FROM 1 UPTO 3
REP
locate (i, 0);
put (text (i, 1));
FOR j FROM 1 UPTO stack [i]
REP
locate (i, j);
put (disk (depth - j + 1))
ENDREP;
FOR j FROM stack [i] + 1 UPTO depth
REP
locate (i, j);
put (nodisk (depth))
ENDREP
ENDREP
ENDPROC showstack;
PROC report (INT CONST a, TEXT CONST msg):
line;
put (msg);
put ("=");
put (a)
ENDPROC report;
TEXT PROC nodisk (INT CONST width):
width * left + width * " " + pillar + width * " "
ENDPROC nodisk;
PROC move tower (INT CONST height, from, to, via):
IF height > 0
THEN
move tower (height - 1, from, via, to);
move piece (height, from, to);
move tower (height - 1, via, to, from)
FI
ENDPROC move tower;
PROC move piece (INT CONST number, from, to):
locate (from, stack [from]);
put (nodisk (number));
stack [from] DECR 1;
stack [to] INCR 1;
locate (to, stack [to]);
put (disk (number));
think (delay)
ENDPROC move piece;
PROC locate (INT CONST a, b):
cursor (36 + 2 * (a - 2) * depth + a, 20 - b)
ENDPROC locate;
PROC indent (INT CONST indentation):
line;
spaces (indentation)
ENDPROC indent;
TEXT PROC disk (INT CONST width):
(width - 1) * left + (width - 1) * disk elem + disk center + (width - 1) * disk elem
ENDPROC disk;
program:
LET left = ""6"";
LET disk elem = ""220"";
LET disk center = ""220"";
LET pillar = ""186"";
LET depth = 9;
LET delay = 2;
report (depth, "Depth");
report (delay, "delay");
ROW 3 INT VAR stack :: [depth, 0, 0];
showstack (stack);
move tower (depth, 1, 2, 3);
cursor (1, 21).