diff options
author | rsiddharth <s@ricketyspace.net> | 2018-05-30 04:56:02 +0000 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2018-05-30 04:56:02 +0000 |
commit | 747ea39e398aedd53e4299e06e6593614088f059 (patch) | |
tree | c63dc121787fba6317add00b25cf9f9ac81b5585 | |
parent | 4bacc7c7fc9ea4435aeebf317f1ccd9470547b31 (diff) |
net: Update snake.rkt
* net/ricketyspace/ror/six/snake.rkt (eat, renew): Update functions.
(fresh-goos): New function.
-rw-r--r-- | net/ricketyspace/ror/six/snake.rkt | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/net/ricketyspace/ror/six/snake.rkt b/net/ricketyspace/ror/six/snake.rkt index 17555c0..30c4c24 100644 --- a/net/ricketyspace/ror/six/snake.rkt +++ b/net/ricketyspace/ror/six/snake.rkt @@ -83,7 +83,7 @@ (can-eat snake (rest goos)))])) (define (eat goos goo-to-eat) - (cons (fresh-goo) (remove goo-to-eat goos))) + (append (list (fresh-goo)) (remove goo-to-eat goos))) (define (close? s g) (posn=? s (goo-loc g))) @@ -118,9 +118,9 @@ (define (renew goos) (cond [(empty? goos) empty] [(rotten? (first goos)) - (cons (fresh-goo) (renew (rest goos)))] + (append (fresh-goos) (renew (rest goos)))] [else - (cons (first goos) (renew (rest goos)))])) + (append (list (first goos)) (renew (rest goos)))])) (define (rot goos) (cond [(empty? goos) empty] @@ -137,6 +137,12 @@ (add1 (random (sub1 SIZE)))) EXPIRATION-TIME)) +(define (fresh-goos) + (define (gen-goos n) + (cond [(= n 0) empty] + [else (cons (fresh-goo) (gen-goos (- n 1)))])) + (let ((n (random 4))) + (gen-goos n))) ;; keys (define (dir? x) |