Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Racket 0.93 KB | None | 0 0
  1. (: enemy-adj-pawns : Board Player Loc -> (Listof Loc))
  2. (define (enemy-adj-pawns b p l)
  3.   (local
  4.     {(define opp-player (switch-player p))
  5.      (: with-bounds :  (Listof Integer) -> (Listof Loc))
  6.      (define (with-bounds c-dirs)
  7.        (match* (c-dirs l p)
  8.          [('() _ _) '()]
  9.          [((cons hd tl) (Loc row col) 'Black)
  10.           (match (board-ref b (Loc row (+ col hd)))
  11.             [(Some (Piece 'Pawn 'White))
  12.              (cons (Loc row (+ col hd)) (with-bounds tl))]
  13.             [_ (with-bounds tl)])]
  14.          [((cons hd tl) (Loc row col) 'White)
  15.           (match (board-ref b (Loc row (+ col hd)))
  16.             [(Some (Piece 'Pawn 'Black))
  17.              (cons (Loc row (+ col hd)) (with-bounds tl))]
  18.             [_ (with-bounds tl)])]))}
  19.     (cond
  20.       [(zero? (Loc-col l)) (with-bounds (list 1))]
  21.       [(= (sub1 (length (list-ref b 0))) (Loc-col l)) (with-bounds (list -1))]
  22.       [else (with-bounds (list -1 1))])))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement