[plt-scheme] hangman problem
Hello Everyone,
i a a newbie who is trying to find his way through the
"jungle of programming" by using the HTDP map. This time in sectio-6 i ran
into a problem in understanding the "crucial ways" the map represents.
I have solved the "pre-hangman problems" (i.e. ex 6.7.1 - .2 & .3) . both
programes execute without any error, but when i try to play "hangman" game
using both of them i get an error:
-------------------------
ERROR:
The teachpack file /usr/lib/plt/teachpack/htdp/hangman.ss did not load
properly.
teachpack: export of stop from "/usr/lib/plt/teachpack/htdp/hangman.ss"
conflicts with already existing definitions
------------------------------------
I have drscheme version209 running on debian "sarge".
may you help me?
;; -------------here is the programme-----------
(define-struct word (s1 s2 s3))
;;a word is a structure: (make-word s s s), where s s & s are symbols.
#|
;; reveal : word word letter -> 3l-word
;; to produce a word dependent on & from given 3 different arguments
;; (define (reveal chosen-word status-word letter-guessed)..)
;; examples
(reveal (make-word 't'e'a) (make-word '_'e'_) 'u)
;; expected value
(make-word '_'e'_)
(reveal (make-word 't'e'a) (make-word 't'_'_) 'a)
;; expected value
(make-word 't_'a)
(reveal (make-word 'a'l'l) (make-word '_'_'_) 'l)
;; expected value
(make-word '_'l'l)
TEMPLATE:
(define (process-reveal word1 word2 letter)
...(word-s1 word1)...(word-s1 word2)...
...(word-s2 word1)...(word-s2 word2)...
...(word-s3 word1)...(word-s3 word2)...)
|#
(define (reveal word-chosen word-status a-letter)
(cond
[(test-all3 word-chosen word-status a-letter) (create-full word-chosen
word-status a-letter)]
[(test-12 word-chosen word-status a-letter) (create-12 word-chosen
word-status a-letter)]
[(test-23 word-chosen word-status a-letter) (create-23 word-chosen
word-status a-letter)]
[(test-13 word-chosen word-status a-letter) (create-13 word-chosen
word-status a-letter)]
[(symbol=? (word-s1 word-chosen) a-letter) (create-word-s1 word-chosen
word-status a-letter)]
[(symbol=? (word-s2 word-chosen) a-letter) (create-word-s2 word-chosen
word-status a-letter)]
[(symbol=? (word-s3 word-chosen) a-letter) (create-word-s3 word-chosen
word-status a-letter)]
[else word-status]))
(define (test-all3 word1 word2 a-letter)
(and (symbol=? (word-s1 word1) a-letter)
(symbol=? (word-s2 word1) a-letter)
(symbol=? (word-s3 word1) a-letter)))
(define (create-full word1 word2 a-letter)
(make-word a-letter
a-letter
a-letter))
(define (test-12 word1 word2 a-letter)
(and (symbol=? (word-s1 word1) a-letter)
(symbol=? (word-s2 word1) a-letter)))
(define (test-23 word1 word2 a-letter)
(and (symbol=? (word-s3 word1) a-letter)
(symbol=? (word-s2 word1) a-letter)))
(define (test-13 word1 word2 a-letter)
(and (symbol=? (word-s1 word1) a-letter)
(symbol=? (word-s3 word1) a-letter)))
(define (create-12 word-chosen word-status a-letter)
(make-word a-letter
a-letter
(word-s3 word-status)))
(define (create-23 word-chosen word-status a-letter)
(make-word (word-s1 word-status)
a-letter
a-letter))
(define (create-13 word-chosen word-status a-letter)
(make-word a-letter
(word-s2 word-status)
a-letter))
(define (create-word-s1 word-chosen word-status a-letter)
(make-word a-letter
(word-s2 word-status)
(word-s3 word-status)))
(define (create-word-s2 word-chosen word-status a-letter)
(make-word (word-s1 word-status)
a-letter
(word-s3 word-status)))
(define (create-word-s3 word-chosen word-status a-letter)
(make-word (word-s1 word-status)
(word-s2 word-status)
a-letter))
#|
;; tests
(reveal (make-word 't'e'a) (make-word '_'e'_) 'u)
;; expected value =
(make-word '_'e'_)
(reveal (make-word 't'e'a) (make-word 't'_'_) 'a)
;; expected value = (make-word 't'_'a)
(reveal (make-word 'a'l'l) (make-word '_'_'_) 'l)
;; expected value = (make-word '_'l'l)
(reveal (make-word 'l'l'l) (make-word '_'_'_) 'l)
;; expected value = (make-word 'l'l'l)
(reveal (make-word 'a'l'l) (make-word '_'_'_) 'p)
;; expected value = (make-word '_'_'_)
|#
;;-----------------------------------------------------------------------------------------
;; draw-next-part : symbol -> true
;; to draw the given symbol on the canvs in "hangman" style
(define START (make-posn 10 10))
(define END-1 (make-posn 50 10))
(define END-2 (make-posn (posn-x END-1) 20))
(define HEAD-RADIUS 10)
(define HEAD-DIA (* 2 HEAD-RADIUS))
(define HEIGHT 50)
(define (draw-next-part a-symbol)
(cond
[(symbol=? 'right-leg a-symbol) (draw-right-leg a-symbol)]
[(symbol=? 'left-leg a-symbol) (draw-left-leg a-symbol)]
[(symbol=? 'left-arm a-symbol) (draw-left-arm a-symbol)]
[(symbol=? 'right-arm a-symbol) (draw-right-arm a-symbol)]
[(symbol=? 'body a-symbol) (draw-body a-symbol)]
[(symbol=? 'head a-symbol) (draw-head a-symbol)]
[(symbol=? 'noose a-symbol) (draw-noose a-symbol)]
[else 'No-match]))
(define (draw-noose a-sym)
(and (draw-solid-line START END-1)
(draw-solid-line END-1 END-2)))
(define (draw-head a-sym)
(draw-circle (make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-RADIUS)) HEAD-RADIUS
'black))
(define (draw-body a-sym)
(draw-solid-line (make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-DIA))
(make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-DIA HEIGHT)) 'black))
(define (draw-right-arm a-sym)
(draw-solid-line (make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-DIA HEAD-DIA))
(make-posn (+ (posn-x END-2) (- HEIGHT HEAD-DIA))
(+ (posn-y END-2) HEAD-DIA))))
(define (draw-left-arm a-sym)
(draw-solid-line (make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-DIA HEAD-DIA))
(make-posn (- (posn-x END-2) (- HEIGHT HEAD-DIA))
(+ (posn-y END-2) HEAD-DIA))))
(define (draw-right-leg a-symbol)
(draw-solid-line (make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-DIA HEIGHT))
(make-posn (+ (posn-x END-2) (- HEIGHT HEAD-RADIUS))
(+ (posn-y END-2) (+ HEIGHT HEAD-DIA
HEAD-DIA)))))
(define (draw-left-leg a-symbol)
(draw-solid-line (make-posn (posn-x END-2)
(+ (posn-y END-2) HEAD-DIA HEIGHT))
(make-posn (- (posn-x END-2) (- HEIGHT HEAD-DIA))
(+ (posn-y END-2) HEIGHT HEAD-DIA HEAD-DIA))))
#|
creation of this HANGMAN was inspired from TRAFFIC-LIGHT (fig. 8) which is
an an excellent
example of using 'global definitions' for specifying & computing constants.
and what? every part of the HANGMAN-body is in perfect sync with the other.
(draw-noose 'kl)
(draw-head 'lk)
(draw-body 'l)
(draw-right-arm 'l)
(draw-left-arm 'l)
(draw-right-leg 'l)
(draw-left-leg 'l) |#
;; test
(hangman make-word reveal draw-next-part)
;;------------ end of programme --------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20060112/b979f96a/attachment.html>