WJ
unread,May 19, 2012, 9:23:44 AM5/19/12You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to
Why this is marked as abuse? It has been marked as abuse.
Kenny Tilton wrote:
> Steven Bee wrote:
> > Okay, I am relatively new at Lisp, but have been catching on fairly
> > quickly. I have designed a simple little game of Go Fish (in
> > pseudocode). As I started writing it I realized that there HAS to be
> > code available that already does things like shuffling cards,
> > organizing a deck, dealing the cards into hands, etc.
>
> > Does anybody no where I can get these functions? Any card game will
> > work since I will adapt it to my design, but I'd even be interested if
> > there is already a Go Fish that would handle card manipulations so
> > that I can concentrate on the heuristic of the computer player.
>
> > Any help would be GREATLY appreciated.
>
> I'll give you some help. Write it yourself. :)
>
> The hidden tip being "Lisp makes this easy" and in fact fun, so I did it
> (largely untested):
>
> (let (deck shuffled (hand-count 4))
> (loop for suit in '(spades hearts diamonds clubs)
> do (loop for value in '(2 3 4 5 6 7 8 9 10 jack queen king ace)
> do (push (cons suit value) deck)))
> (loop while deck
> for next-card = (elt deck (random (length deck)))
> do
> (push next-card shuffled)
> (setf deck (delete next-card deck)))
> (loop with hands = (make-list hand-count :initial-element nil)
> for dealt in shuffled
> for n upto (length shuffled)
> do (push dealt (nth (mod n hand-count) hands))
> finally (return hands)))
Kenny did it in COBOL (CL) instead of in Lisp.
Racket:
(define (create-hands)
(define deck
(append-map
(lambda (suit) (map (curry cons suit)
'(2 3 4 5 6 7 8 9 10 jack queen king ace)))
'(spades hearts diamonds clubs)))
(define shuffled (shuffle deck))
(map (lambda (n) (take (drop shuffled (* n 13)) 13))
'(0 1 2 3)))