[plt-scheme] thanks, but help again

From: Connor Ferguson (psfreak at linkline.com)
Date: Mon Mar 29 21:27:11 EST 2004

Sorry for the delay. Things have been really hectic for me the past few
days.

Ok, here are my data definitions for UFO and shot/f

;; a UFO is a shape
;; (make-ufo p l w c)
;; where p is a posn, l is a number, w is a number
;; and c is a symbol

;; a shot is a stucture
;;(make-shot start l w col)
;; where start is a posn (the position of the AUP)
;; l is a number, w is a number, and col is a symbol

;; a shot/f is either
;; a shot or;
;; false

Like Matthias said, I altered hit-shot? so that there are no numbers, only
constants.

;; hit-shot? : shot/f ufo -> boolean
(define (hit-shot? shot/f ufo)
  (cond     
    [ (boolean? shot/f) false]
    [ else     
     (cond     
       [ (and (>= (+ (posn-x (ufo-nw ufo)) (ufo-len ufo))
                 (posn-x (shot-posn shot/f)))
             (>= (+ (posn-x (ufo-nw ufo)) (ufo-len ufo)
                 (+ (posn-x (shot-posn shot/f)) (shot-l shot/f))
             (<= (posn-x (ufo-nw ufo))
                 (+ (posn-x (shot-posn shot/f)) (shot-l shot/f))
             (>= (posn-y (ufo-nw ufo))
                 (posn-y (shot-posn shot/f)))
             (>= (posn-y (ufo-nw ufo))
                 (+ (posn-y (shot-posn shot/f)) (shot-w shot/f)))) true]
       [ else false])]))

I had been testing the program only by running it in the context of the
game, but that is not something I should not do, so I formulated these
tests.

(hit-shot? (make-shot (make-posn 10 10) 2 5 'red)
     (make-ufo (make-posn 10 10) 22 4 'green))
= false

(hit-shot? (make-shot (make-posn 30 30) 2 5 'red)
                (make-ufo (make-posn 10 10) 22 4 'green))
= false

(hit-shot? (make-shot (make-posn 100 100) 2 5 'red)
                (make-ufo (make-posn 10 10) 22 4 'green))
= false

Clearly, these examples demonstrate the problem I¹m having. Basically,
everything I put into the program is evaluating to false.

Thank you for helping and sorry for taking so long to respond.

-Connor

on 3/24/04 5:40 PM, Matthias Felleisen at matthias at ccs.neu.edu wrote:

> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> 
> P.S. Congratulations to your exhibit!!!
> 
> 
> On Mar 24, 2004, at 8:39 PM, Connor Ferguson wrote:
> 
>> For list-related administrative tasks:
>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>> 
>> Hey everybody-
>> 
>> Thanks especially to Matthias and Bruce and mathematica for your help.
>> My
>> science project of the UFO game (from HTDP) has been chosen to compete
>> in
>> the Los Angeles County Science Fair on April 13.
>> 
>> While I¹m very happy about this, I am still having some problems.
>> Whenever I
>> successfully modify hit-shot? to register the UFO as hit when it passes
>> through, it also classifies as hit when the shot has already passed and
>> missed and the UFO moves back to the line that the shot traveled.
>> Below is
>> my function for hit-shot? If anyone could take a look at it and please
>> tell
>> me where I may be going wrong, that would be great.
>> 
>> ;; hit-shot? : shot/f ufo -> boolean
>> (define (hit-shot? shot/f ufo)
>> (cond
>> [ (boolean? shot/f) false]
>> [ else
>> (cond
>> [ (and (>= (+ (posn-x (ufo-nw ufo)) 22)
>> (posn-x (shot-posn shot/f)))
>> (<= (posn-x (ufo-nw ufo))
>> (+ (posn-x (shot-posn shot/f)) 2))
>> (>= (posn-y (ufo-nw ufo))
>> (posn-y (shot-posn shot/f)))
>> (>= (posn-y (ufo-nw ufo))
>> (+ (posn-y (shot-posn shot/f)) 5))) true]
>> [ else false])]))
>> 
>> Thanks again
>> -Connor
>> 
> 
> 



Posted on the users mailing list.