Lec 9
Lec 9
The faces
• 2
• 3
• ...
• 10
• Jack
• Queen
• King
• Ace
https://commons.wikimedia.org/wiki/File:English_pattern_playing_cards_deck.svg
• If card is a card, then card[0] is the face, card[1] is the suit, and
card[2] is the value.
• Blackjack rules
• The player receives 2 cards and decides to get one more card or not.
• The player wins, if the sum of the values of his/her cards is closer to 21
than the dealer.
• The player loses, if the sum is larger than 21.
Hand of a Score of a
player player
Hand of a Score of a
dealer dealer
Let us define a new object type with attributes for face, suit, and value:
class Card(object):
"""A Blackjack card."""
pass
The hen and the chicks are exactly the same. The hen is larger and white.
The simplest method to make similar objects is to write the code once, and
copy & paste it (with the necessary modifications).
Disadvantage: When you find a bug, you have to debug all copies of the code.
It is not easy to change the appearance of all the chickens at once.
Our chicken will have attributes layer, body, wing, eye, and beak.
ch = Chicken()
ch.layer = layer
ch.body = body
ch.wing = wing
ch.eye = eye
hen = make_chicken(True)
chick1 = make_chicken()
chick1.layer.move(120, 0)
herd = Layer()
herd.add(hen.layer)
herd.add(chick1.layer)
herd.move(600, 200)
chick2 = make_chicken()
chick2.layer.move(800, 200)