Guest User

Untitled

a guest
May 20th, 2018
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scheme 1.42 KB | None | 0 0
  1. (define runaway-strategy
  2.   (lambda (gh g)
  3.     (letrec ((p (game-pacman g))
  4.              (c (ghost-col gh))
  5.              (r (ghost-row gh))
  6.              (dir (ghost-dir gh))
  7.              (d-up (distance p c (- r 1)))
  8.              (d-down (distance p c (+ r 1)))
  9.              (d-left (distance p r (- c 1)))
  10.              (d-right (distance p r (+ c 1)))
  11.              (crossing-code (direction-map/coordinate
  12.                               (maze-direction-map
  13.                                (field-maze
  14.                                 (game-field g)))
  15.                               c r))
  16.              (poss-dirs (code->direction crossing-code))
  17.              (distances (map (lambda (x)
  18.                                (cond ((string=? "up" x) d-up)
  19.                                      ((string=? "down" x) d-down)
  20.                                      ((string=? "left" x) d-left)
  21.                                      ((string=? "right" x) d-right))) poss-dirs))
  22.              (maxdist (fold 0 max distances)))
  23.       (cond
  24.         ((= maxdist 0) dir)
  25.         ((and (any? (lambda (x) (direction=? "down" x)) poss-dirs) (= d-down maxdist))  "down")
  26.         ((and (any? (lambda (x) (direction=? "up" x)) poss-dirs) (= d-up maxdist)) "up")
  27.         ((and (any? (lambda (x) (direction=? "left" x)) poss-dirs) (= d-left maxdist)) "left")
  28.         ((and (any? (lambda (x) (direction=? "right" x)) poss-dirs) (= d-right maxdist)) "right")))))
Add Comment
Please, Sign In to add comment