Next / Previous / Contents

3. A family of simple rummy games

To illustrate the facilities defined above, we show how they might be used to generate cards for a simple game; or, rather, for a family of related games with similar rules. The simplest of these games might be suitable for young children, but the more complicated variations should be challenging enough for adults.

Each card will have three properties printed on it; these will be a person, something for the person to do, and a place to do it. Parents might use our program to generate a customized deck of cards, featuring their children and their friends, their favorite activities, and places they go or have visited.

The games will be played much like gin rummy. Each player is dealt a certain number of cards, and a card is turned up on the table to start a discard pile. As each turn, a player draws either a card from the unused part of the deck, or the card on the top of the discard pile. The player may be able to combine all of the cards in his or her hand, to win the game; otherwise, the player discards a card and puts it on the discard pile, and he turn passes to the next player.

Cards are combined by making groups of three (or more) of a kind: these are cards with matching values for any one of the three properties. Different games can be defined by varying the number of cards dealt to each hand and the rules for combining. Some possibilities are:

3.1. Design of the cards

Here we define the design of the cards for this game. The design is simple: the three properties and words to connect them to make a sentence. Examples might be "John goes bird watching in Florida" and "Lynda goes swimming in New Mexico". The elements of the sentence are on separate lines. Positions, fonts and sizes are chosen rather arbitrarily, for appearance.

The code in this section and the next is specific to this game, so it is marked with the role attribute "rummy". This is so it can be extracted separately from the code that pertains to all games. We assume that the latter code, when extracted, will be placed in a module named cards.

rummy
def makeCard(person, activity, place):
  Card.start()
  Card.put(person, 16, 0.0, 0.6)
  Card.putCentered("goes", 12, 1.1, font="Helvetica-Oblique")
  Card.putCentered(activity, 16, 1.6)
  Card.putCentered("in", 12, 2.1, font="Helvetica-Oblique")
  Card.putCentered(place, 16, 2.6)
  Card.finish()

Here is a sample of such a card, as printed on business-card stock with the long dimension vertical.