1 How to play
2 Customize the behavior of the robot
3 Default move-robot fuuction
Version: 5.0.2

DynaBlaster: Htdp version of Dynablaster game

1 How to play

To run the game, type

  (require (planet "dynablaster.rkt" ("jeeve" "dynablaster.plt" 1 8)))

Use left, right, up and down keys to move blue player in the scene.

Drop bombs with space key and attack the red player.

Good luck !

2 Customize the behavior of the robot

(run my-move-robot-function)

Before, define a basic custom move-robot function. For example :

  (define (my-move-robot-function r d)
    (if (empty? r)
        (if (empty? (sprite-left r (lambda (x) #t) d))
            (go-left r d)

Also, you can start the game in automatically mode, the blue player is controlled by a function like the robot. So you can easily compare the behavior of two algorithms.

(run my-move-robot-function my-move-player-function)

You can use these functions and predicates :

Do not hesitate to send me your move-robot functions (jeeve <jvjulien@free.fr>)

3 Default move-robot fuuction

For information, the default move-robot has only random and defensive behavior. The code corresponding is

  (define (move-robot-default r d)
    (let* ([x (random 100)]
           [danger? (lambda (x) (or (bomb? x) (fire? x)))]
           [something? (lambda (x) #t)]
           [escape (lambda (r d)
                     (cond [(not (empty? (sprite-left r danger? d))) (go-right r d)]
                           [(not (empty? (sprite-right r danger? d))) (go-left r d)]
                           [(not (empty? (sprite-up r danger? d))) (go-down r d)]
                           [(not (empty? (sprite-down r danger? d))) (go-up r d)]
                           [(not (empty? (search-sprite (sprite-x r) (sprite-y r) bomb? d)))
                            (cond  [(empty? (sprite-left r something? d)) (go-left r d)]
                                   [(empty? (sprite-right r something? d)) (go-right r d)]
                                   [(empty? (sprite-up r something? d)) (go-up r d)]
                                   [(empty? (sprite-down r something? d)) (go-down r d)]
                                   [else d])]))])
      (if (empty? r)
            [(or (not (empty? (sprite-left r danger? d)))
                 (not (empty? (sprite-right r danger? d)))
                 (not (empty? (search-sprite (sprite-x r) (sprite-y r) bomb? d))))
             (if (empty? (sprite-up r something? d))
                 (go-up r d)
                 (if (empty? (sprite-down r something? d))
                     (go-down r d)
                     (escape r d)))]
            [(or (not (empty? (sprite-up r danger? d)))
                 (not (empty? (sprite-down r danger? d)))
                 (not (empty? (search-sprite (sprite-x r) (sprite-y r) bomb? d))))
             (if (empty? (sprite-left r something? d))
                 (go-left r d)
                 (if (empty? (sprite-right r something? d))
                     (go-right r d)
                     (escape r d)))]
            [(and (> x 0) (<= x 10) (empty? (sprite-up r fire? d))) (go-up r d)]
            [(and (> x 10) (<= x 20) (empty? (sprite-down r fire? d))) (go-down r d)]
            [(and (> x 20) (<= x 30) (empty? (sprite-left r fire? d))) (go-left r d)]
            [(and (> x 30) (<= x 40) (empty? (sprite-right r fire? d))) (go-right r d)]
            [(and (> x 40) (<= x 42) (not (blocked? r d))) (drop-bomb r d)]
            [else d]))))