LOGO-L> Re: missing procedure for HANOI demo 
Author Message
 LOGO-L> Re: missing procedure for HANOI demo

Your problem in MSWLogo is with KEYP, it is not supported.

Instead of the program "driving" the "user".
Let the "user" "drive" the program.

KEYBOARDON (the focus must be on the graphics screen)
MOUSEON

Are much more powerful to communicate with the user.

This is not a good example of MOUSEON.

to go
.
.
.
make "HaltGame "False
MOUSEON [make "HaltGame "True] [] [] [] []
.
.
.
end

to hanio
.
.
.
if :HaltGame [throw "toplevel]
.
.
.
end

Here is your code modified to to run under MSWLogo

TO 3STICKS
PU SETPENSIZE [27 27]
SETY -150 SETX -400 PD SETX 400
SETPENSIZE [4 4]
SETX 260  FD 360 BK 360 SETX 0 FD 360 BK 360
SETX -260 FD 360 BK 360 PU
SETXY -70 240 PD LABEL [THE TOWERS OF HANOI] PU
SETXY -285 -205 PD LABEL [START] PU
SETXY -35 -205 PD LABEL [SPARE] PU
SETXY 250 -205 PD LABEL [GOAL]PU
SETXY -260 -150
END

TO ADD :STICK
MOVETO :STICK
FD 30
PENPAINT
DISQ :THIS
MAKE :STICK SE :THIS :DSK
END

TO COLOR :N
OP ITEM :N [[7 0 0] [6 0 0] [3 0 0] [5 0 0] [4 0 0] [12 0 0] [2 0 0]
     [1 0 0] [29 0 0] [10 0 0] [11 0 0] [13 0 0] [7 0 0] [14 0 0] [15 0
0]]
END

TO DESCRIP
CT TS
SETCURSOR [30 2] PR [THE TOWER OF HANOI]
SETCURSOR [25 5] PR [The puzzle begins with a "tower "]
SETCURSOR [25 6] PR [of discs arranged in order of size]
SETCURSOR [25 7] PR [with the largest at the bottom and]
SETCURSOR [25 10] PR [The task is to move them one by one]
SETCURSOR [25 11] PR [from the Start pole to the Goal one]
SETCURSOR [25 12] PR [without placing a larger disc on a]
SETCURSOR [25 13] PR [a smaller one]
SETCURSOR [25 18] PR [Number of disks ? :]
SETCURSOR [25 19] Pr [ ( 10 maximum )]
SETCURSOR [55 18] make "num rw
SETCURSOR [25 20] pr [input delay factor ? :]
SETCURSOR [25 21] pr [ ( 1 , 2 , 3 , 30..)]
SETCURSOR [55 20] make "delay rw pr :delay
END

TO DISKS :SMALL :BIG
IF :SMALL > :BIG [SETY -150 STOP]
IF :BIG = :NUM [FD 20] FD 10
PENPAINT
DISQ :BIG
DISKS :SMALL :BIG - 1
END

TO DISQ :SIZE
SETPC COLOR :SIZE
MAKE "SIZE :SIZE * :FACT
SETPENSIZe [27 27]
LT 90
FD :SIZE
BK :SIZE * 2
FD :SIZE  
RT 90
SETPENSIZE [4 4]
FD 20
MAKE "CC FIRST BUTFIRST PEN
IF :CC = "ERASE [SETPC [3 0 0] PENPAINT BK 28]
PU
END

TO ELIM :STICK
MOVETO :STICK
MAKE "THIS FIRST :DSK
PENERASE
DISQ :THIS
MAKE :STICK BF :DSK
END

TO GO
CT CS SETPC [3 0 0]
DESCRIP
MAKE "FACT 122/ :NUM
CS FS
3STICKS
DISKS 1 :NUM
MAKE "CO 0
MAKE "S2 []
MAKE "S3 []
MAKE "S1 SEQUENCE :NUM
HT
HANOI :NUM "S1 "S2 "S3
CT
PR (SE [IT TOOK] :CO [MOVES FOR] :NUM "DISCS)
WAIT 30
;PR [Press a key to play , or esc to quit]
;MAKE "DUMMY RC
;IF :DUMMY = CHAR 27 [CS HT CT STOP]
if Not YesNoBox [] [Again?] [CS HT CT STOP]
GO
END

TO HANOI :NUM :START :SPARE :GOAL
IF :NUM = 0 [STOP]
HANOI :NUM - 1 :START :GOAL :SPARE
WAIT :DELAY
MOVE.ONE :START :GOAL
;if keyp [throw "toplevel]
;Let user use halt button to stop
WAIT :DELAY
HANOI :NUM - 1 :SPARE :START :GOAL
END

TO MOVE.ONE :FROM :TO
MAKE "CO :CO + 1
ELIM :FROM
ADD :TO
END

TO MOVETO :STICK
SETX (BF :STICK) * 260 - 520
MAKE "DSK THING :STICK
SETY 30 * (COUNT :DSK) - 150
END

TO sequence :N
MAKE "T 1
REPEAT :N - 1 [MAKE "T SE :T 1 + LAST :T]
OP :T
END

Quote:

> ;hellow George Mills
> ;Hello Olga Tuzova
> ;Here is the code of the sequence procedure;yes I put it in my library
> ;it simply outputs a list of numbers starting from 1 to :n.
> ;My problems with the HANOI code was not due to colours;since I
> ;tried RGB colours, then I ommited colours altogether. when I tried
> ;it I ommited also setcursor and the like.
> ;Thanks for your kind and helpful suggestions.
> ;Best Regards.
> ;Mhelhefni
> ;--------------------------------------------------------
> TO sequence :N
> MAKE "T 1
> REPEAT :N - 1 [MAKE "T SE :T 1 + LAST :T]
> OP :T
> END
> bury "sequence
> ;--------------------------------------------------------

--
===============================================================
George Mills

http://www.*-*-*.com/
The www page contains some very powerful educational software.
Our single most important investment is our kids.
---------------------------------------------------------------





Tue, 14 Mar 2000 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. LOGO-L> missing procedure for HANOI demo

2. LOGO-L> Logo procedure problem

3. LOGO-L> Re: Demo-program

4. LOGO-L> Demo-program

5. LOGO-L> projectile demo

6. LOGO-L> without multi-turtles demo

7. LOGO-L> Re: DEMO

8. LOGO-L> Naming Super Procedure by MAIN

9. LOGO-L> cloning procedures

10. LOGO-L> launch : parallel running of procedures

11. LOGO-L> library procedures

 

 
Powered by phpBB® Forum Software