Last active
August 29, 2015 14:19
-
-
Save goloroden/3400e4fc7a21417f4276 to your computer and use it in GitHub Desktop.
Some card playing code…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defun rank (card) | |
(car card)) | |
(defun suit (card) | |
(cadr card)) | |
(setf my-hand '((3 hearts) | |
(5 clubs) | |
(2 diamonds) | |
(4 diamonds) | |
(ace spades))) | |
(defun count-suit (suit hand) | |
(length (remove-if-not #'(lambda (card) (equal suit (suit card))) hand))) | |
(setf colors '((clubs black) | |
(diamonds red) | |
(hearts red) | |
(spades black))) | |
(defun color-of (card) | |
(cadr (assoc (suit card) colors))) | |
(defun first-red (hand) | |
(find-if #'(lambda (card) (equal (color-of card) 'red)) hand)) | |
(defun black-cards (hand) | |
(remove-if-not #'(lambda (card) (equal (color-of card) 'black)) hand)) | |
(defun what-rank (suit hand) | |
(mapcar #'rank (remove-if-not #'(lambda (card) (equal (suit card) suit)) hand))) | |
(setf all-ranks '(2 3 4 5 6 7 8 9 10 jack queen king ace)) | |
(defun higher-rank-p (card-1 card-2) | |
(member (rank card-1) (member (rank card-2) all-ranks))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment