Advertisement
Guest User

Untitled

a guest
Jan 7th, 2013
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lisp 1.63 KB | None | 0 0
  1. (defun white-pawn-move (file rank)       
  2.   (let ((movelist '()))
  3.     (if (and (within-boardp file (+ rank 1))
  4.          (eql #\s (aref *board* (+ rank 1) file)))
  5.     (push (cons file (+ rank 1)) movelist))
  6.     (if (= rank 1)
  7.     (push (cons file (+ rank 2)) movelist))
  8.     (if (and (within-boardp (- file 1) (+ rank 1))
  9.          (belongs-to-opponent (aref *board*  (+ rank 1) (- file 1))))
  10.     (push (cons (- file 1) (+ rank 1)) movelist))
  11.     (if (and (within-boardp (+ file 1) (+ rank 1))
  12.          (belongs-to-opponent (aref *board* (+ rank 1) (+ file 1))))
  13.     (push (cons (+ file 1) (+ rank 1)) movelist))
  14.     movelist))     
  15.  
  16. ;refactor:
  17. ;file / rank numeric      
  18. (defun pawn-move (direction)
  19.   (let ((startrank (if (eql direction #'+)
  20.                1
  21.                6)))
  22.     (lambda (file rank)
  23.       (let ((movelist '()))
  24.       (if (and (within-boardp file (funcall direction rank 1))
  25.            (eql #\s (aref *board* (funcall direction rank 1) file)))
  26.           (push (cons file (funcall direction rank 1)) movelist))
  27.       (if (= rank startrank)
  28.           (push (cons file (funcall direction rank 2)) movelist))
  29.       (if (and (within-boardp (- file 1) (funcall direction rank 1))
  30.            (belongs-to-opponent (aref *board*  (funcall direction rank 1) (- file 1))))
  31.           (push (cons (- file 1) (funcall direction rank 1)) movelist))
  32.       (if (and (within-boardp (+ file 1) (funcall direction rank 1))
  33.            (belongs-to-opponent (aref *board* (funcall direction rank 1) (+ file 1))))
  34.           (push (cons (+ file 1) (funcall direction rank 1)) movelist))
  35.     movelist))))
  36. ;desired usage
  37. (setf (gethash #\P *move-table*) (pawn-move #'+))    
  38. (setf (gethash #\p *move-table*) (pawn-move #'-))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement