Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (defun directionp (thing)
- (member thing *all-dirs*))
- (defun piece-function (x y)
- #'(lambda (&rest dirs-and-signatures)
- (make-piece x y
- (remove-if-not #'directionp dirs-and-signatures)
- (remove-if #'directionp dirs-and-signatures))))
- (defparameter *atoms*
- '((:wazir 1 0)
- (:ferz 1 1)
- (:dabbabah 2 0)
- (:knight 2 1)
- (:alfil 2 2)
- (:threeleaper 3 0)
- (:camel 3 1)
- (:zebra 3 2)
- (:tripper 3 3)
- (:fourleaper 4 0)
- (:giraffe 4 1)
- (:doubleknight 4 2)
- (:antelope 4 3))
- "List that holds definitions for all chess pieces.")
- (defparameter *piece-functions*
- (let ((hash-table (make-hash-table)))
- (dolist (piece *atoms* hash-table)
- (destructuring-bind (piece-name x y) piece
- (setf (gethash piece-name hash-table) (piece-function x y))))
- hash-table)
- "Hash table that holds lambdas for all chess pieces.")
- (defun piece (name &rest dirs-and-signatures)
- "Creates a simple chess piece based on its name argument.
- The names of the basic items or a two-number list is accepted.
- Additionally, a single number n is interpreted as the combination of '(n n) and '(n 0)."
- (cond ((member name *atoms* :key #'first)
- (apply (gethash name *piece-functions*) dirs-and-signatures))
- ((numberp name)
- (append (apply (piece-function name 0) dirs-and-signatures)
- (apply (piece-function name name) dirs-and-signatures)))
- (t (piece-function (first name) (second name)))))
Advertisement
Add Comment
Please, Sign In to add comment