Nov 6
next term
How many of you are interested in the Algorithms course next semester?
Choice of algorithms textbook for next term?
homework
Yes, doing all of this one was a lot of work.
Sounds like there's plenty to talk about here:
- What the heck does Jim mean by "skeleton"?
- And how the heck are these Card, Hand, PokerHand, and Deck classes supposed to fit together?
Things to think about:
- What data do we need for each class? How and where do we store that?
- What things would we like to do to each of these. These "verbs" should be methods.
- Do some of these classes inherit from others? Are built with other classes as interior parts?
Here's one take on
# -- Card --
card = Card(rank, suit) # rank=1..13, suit='c', 'd', 's', or 'h'
= Card() # or this way for a random card
print card.getRank() # returns 2 (duece) ... 14 (ace); or card.rank
print card.getSuit() # returns 'c', 'd', 'h', or 's'; or card.suit
print card # e.g. 'Three of Clubs'
card1 < card2 # ordering by (i) rank, (ii) suit
sort(cards) # sort a list of cards, low to high, in place
# -- Deck --
deck = Deck() # a 52-card deck
print len(deck) # number of cards left in the deck
card = deck.deal_a_card() # return and remove a random card from deck
list = deck.get_n_cards(n) # ditto for a list of cards
# -- PokerHand --
hand = PokerHand(string) # make hand from e.g. '1 s, 2 h, 3 d, 4 c, 5 s'
= PokerHand(cards=list) # ... from a list of PokerCard's
= PokerHand(deck=d) # ... from given deck (and remove 'em from deck)
hand = PokerHand() # ... from a new deck
hand1 < hand2 # True if hand1 loses to hand2
sort(hands) # sort a list of hands, low to high, in place
print hand # e.g. 'Straight Flush :
Queen of Hearts, Jack of Hearts, ...'
print hand.category # e.g. 'Two Pair'
print hand.description # e.g. 'Sixes over Fours'
Let's work on this together in class and see how far we get,
as a way to explore both the "object" concept, and
to talk about how to think through problems.
We worked on writing something along
the lines of the poker hand assignment;
I've attached it in its unfinished state.
looking ahead
The end of the term is going to come up quickly.
Here's the schedule :
- final proposal next week, Nov 13
- project progress report Nov 20 (Thanksgiving week)
- rough draft due Nov 27 ; I will give feedback
- class presentation Dec 4 (last class)
- final version due by Fri Dec 7
Meanwhile, we will discuss a few other topics (recursion,