about summary refs log tree commit diff stats
path: root/README
diff options
context:
space:
mode:
authorAnselm R Garbe <garbeam@gmail.com>2008-06-01 17:41:15 +0100
committerAnselm R Garbe <garbeam@gmail.com>2008-06-01 17:41:15 +0100
commitc8eaab21b697247e2bc07ce9b8c7dfdd94e87af9 (patch)
treeb4eee7437c77d0c0fda63ac56740d68e4cf1d41c /README
parentc26e22cceeee5fdd40e6bd6e019729ed316e2e01 (diff)
downloaddwm-c8eaab21b697247e2bc07ce9b8c7dfdd94e87af9.tar.gz
using anydot's memcpy-approach in drawtext, however it still looks awkward to me
Diffstat (limited to 'README')
0 files changed, 0 insertions, 0 deletions
='#n95'>95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
<P>

<P><HTML>
<HEAD>
<TITLE>Simply Scheme:Project: Scoring Poker Hands</TITLE>
</HEAD>
<BODY>
<CITE>Simply Scheme</CITE>:
<CITE>Introducing Computer Science</CITE> 2/e Copyright (C) 1999 MIT
<H1>Project: Scoring Poker Hands</H1>

<TABLE width="100%"><TR><TD>
<IMG SRC="../simply.jpg" ALT="cover photo">
<TD><TABLE>
<TR><TD align="right"><CITE><A HREF="http://www.cs.berkeley.edu/~bh/">Brian
Harvey</A><BR>University of California, Berkeley</CITE>
<TR><TD align="right"><CITE><A HREF="http://ccrma.stanford.edu/~matt">Matthew
Wright</A><BR>University of California, Santa Barbara</CITE>
<TR><TD align="right"><BR>
<TR><TD align="right"><A HREF="../pdf/ssch15.pdf">Download PDF version</A>
<TR><TD align="right"><A HREF="../ss-toc2.html">Back to Table of Contents</A>
<TR><TD align="right"><A HREF="adv-recur.html"><STRONG>BACK</STRONG></A>
chapter thread <A HREF="../ssch16/match.html"><STRONG>NEXT</STRONG></A>
<TR><TD align="right"><A HREF="http://mitpress.mit.edu/0262082810">MIT
Press web page for <CITE>Simply Scheme</CITE></A>
</TABLE></TABLE>

<HR>

<P>The idea of this project is to invent a procedure <CODE>poker-value</CODE>
that works like this:

<P><PRE>&gt; (<A NAME="g19"></A>poker-value '(h4 s4 c6 s6 c4))
(FULL HOUSE - FOURS OVER SIXES)

&gt; (poker-value '(h7 s3 c5 c4 d6))
(SEVEN-HIGH STRAIGHT)

&gt; (poker-value '(dq d10 dj da dk))
(ROYAL FLUSH - DIAMONDS)

&gt; (poker-value '(da d6 d3 c9 h6))
(PAIR OF SIXES)
</PRE>

<P>As you can see, we are representing cards and hands just as in the
Bridge project, except that poker hands have only five
cards.<A NAME="text1" HREF="poker.html#ft1">[1]</A>

<P>Here are the various kinds of poker hands, in decreasing order of value:

<P><P><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Royal flush: ten, jack, queen, king, and ace, all of the same suit
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Straight flush: five cards of sequential rank, all of the same suit
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Four of a kind: four cards of the same rank
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Full house: three cards of the same rank, and two of a second rank
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Flush: five cards of the same suit, not sequential rank
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Straight: five cards of sequential rank, not all of the same suit
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Three of a kind: three cards of the same rank, no other matches
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Two pair: two pairs of cards, of two different ranks
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Pair: two cards of the same rank, no other matches
</TABLE><TABLE><TR><TH align="right" valign="top">&bull;<TD>&nbsp;&nbsp;&nbsp;&nbsp;<TD valign="top">Nothing: none of the above

</TABLE>
<P>
An ace can be the lowest card of a straight (ace, 2, 3, 4, 5) or
the highest card of a straight (ten, jack, queen, king, ace), but a straight
can't &quot;wrap around&quot;; a hand with queen, king, ace, 2, 3 would be worthless
(unless it's a flush).

<P>Notice that most of the hand categories are either entirely about the ranks
of the cards (pairs, straight, full house, etc.) or entirely about the
suits (flush).  It's a good idea to begin your program by separating the
rank information and the suit information.  To check for a straight flush or
royal flush, you'll have to consider both kinds of information.

<P>In what form do you want the suit information?  Really, all you need is a
true or false value indicating whether or not the hand is a flush, because
there aren't any poker categories like &quot;three of one suit and two of
another.&quot;

<P>What about ranks?  There are two kinds of hand categories involving ranks: 
the ones about equal ranks (pairs, full house) and the ones about sequential
ranks (straight).  You might therefore want the rank information in two
forms.  A sentence containing all of the ranks in the hand, in sorted order,
will make it easier to find a straight.  (You still have to be careful about
aces.)

<P>For the equal-rank categories, what you want is some data structure that
will let you ask questions like &quot;are there three cards of the same rank
in this hand?&quot;  We ended up using a representation like this:

<P><PRE>&gt; (compute-ranks '(q 3 4 3 4))
(ONE Q TWO 3 TWO 4)
</PRE>

<P>One slightly tricky aspect of this solution is that we spelled
out the numbers of cards, <CODE>one</CODE> to <CODE>four</CODE>, instead of using the more
obvious <CODE>(1 Q 2 3 2 4)</CODE>.  The reason, as you can probably tell just by
looking at the latter version, is that it would lead to confusion between
the names of the ranks, most of which are digits, and the numbers of
occurrences, which are also digits.  More specifically, by spelling out the
numbers of occurrences, we can use <CODE>member?</CODE> to ask easily if there is
a three-of-a-kind rank in the hand.

<P>You may find it easier to begin by writing a version that returns only the
name of a category, such as <CODE>three of a kind</CODE>, and only after you get
that to work, revise it to give more specific results such as <CODE>three
sixes</CODE>.

<P><H2>Extra Work for Hotshots</H2>

<P>In some versions of poker, each player gets seven cards and can choose any
five of the seven to make a hand.  How would it change your program if the
argument were a sentence of seven cards?  (For example, in five-card poker
there is only one possible category for a hand, but in seven-card you have
to pick the best category that can be made from your cards.)  Fix your
program so that it works for both five-card and seven-card hands.

<P>Another possible modification to the program is to allow for playing with
&quot;wild&quot; cards.  If you play with &quot;threes wild,&quot; it means that if there is
a three in your hand you're allowed to pretend it's whatever card you like.
For this modification, your program will require a second argument indicating
which cards are wild.  (When you play with wild cards, there's the
possibility of having five of a kind.  This beats a straight flush.)

<P>



<HR>
<A NAME="ft1" HREF="poker.html#text1">[1]</A> Later on we'll think about seven-card variants of poker.<P>
<P><A HREF="../ss-toc2.html">(back to Table of Contents)</A><P>
<A HREF="adv-recur.html"><STRONG>BACK</STRONG></A>
chapter thread <A HREF="../ssch16/match.html"><STRONG>NEXT</STRONG></A>

<P>
<ADDRESS>
<A HREF="../index.html">Brian Harvey</A>, 
<CODE>bh@cs.berkeley.edu</CODE>
</ADDRESS>
</BODY>
</HTML>