My Girl Scouts Are Better Than Your Girl Scouts
Some of the best programming students I've taught have been 15 and 16 year old Girl Scouts. At this age they are old enough to deal with intellectual issues, but still young enough to have wonder. This is the general age of my daughter Emily's troop. When the troop leader (who also happens to be my wife, Alice) asked me to help them get their computer badge, I was delighted.
I had two meetings. The first was easy. We spent an hour on the Web learning to do searches and discussing censorship and an hour at our local computer store learning to configure systems. But this still left me a second meeting to fill.
I decided that I would use that meeting to teach them C++ and how to work with object frameworks. Now I know most adults spend years learning these topics, but I figured these girls had three advantages. First, they liked computers. Second, they had nothing to unlearn. Third, nobody had ever told them these topics were hard.
I set up a simple game framework. The Girl Scouts then split into teams and programmed game players. The players then plugged into the game framework and played against each other.
The game was very successful. The girls developed some fascinating strategies, learned (with the help of some knowledgeable C++ programmers) to turn these strategies into algorithms, and then to turn those algorithms into working C++ objects. They also learned what it means to work within an object framework.
It occurred to me that this project would be even more interesting if opened up to a larger audience. So that is what I'm doing in this article. I invite all of my readers to program players for this framework, and we will have a large playoff.
I especially urge readers who are working with youth groups, such as Girl-Scouts and Boy Scouts, to involve their youth and help them to design strategies and submit players. Many of these groups offer computer badges, for which this project will probably make them eligible. To sweeten the pot, I am offering a first prize ($100), second prize ($50), and third prize ($25) to the best submissions from youth groups. These prizes have been donated by Object Watch Inc.
Here is the basic game setup. The name of the game is "Dog Meets Dog." The goal is to program various types of dogs. The framework will create one instance each of the various dog types, and then set up a series of rounds. In each round, two dogs will be chosen to play against each other. Each dog is told which dog it is playing against in that round. The dog then has to decide whether it will share or steal from the other dog. Both dogs make the decision. Both dogs are then informed of what the other dog decided.
In each round, the framework assigns payoffs to each dog. The unit of payoffs is dog biscuits. If both dogs deCide to steal, each dog is awarded one dog biscuit. If both dogs decide to share, each dog is awarded three dog biscuits. If one dog steals and the other shares, the stealer gets five dog biscuits and the sharer none.
A full game consists of many rounds, many more rounds than there are dog objects. In the course of a game, each dog will meet each other dog many times.
I did not originate the idea for this game. I first ran into it in a book that was published several years ago, and one I consider highly influential in shaping my own philosophy. I am not going to give the reference now, because I want to encourage readers to develop their own game strategies rather than turn this into a research project. I will give the reference in a later article when I discuss the results of this contest.
Although I did not originate this basic game, I have added several features I believe to be novel. First, I have turned this into an object-oriented framework. Second, I have set up the players as instances of C++ classes and have programmed both the overall framework and the dog players in VisualAge C++ running on OS/2. Third, I have made the players dogs, which for some reason has never before been done.
The game framework is typical of many frameworks: it defines and implements an architectural frame work in which objects operate and interact. The framework itself is a program. It instantiates specialized objects and coordinates their inter actions. The pseudo-code for the game framework program is shown in Listing 1.
Two related interactions occur in each round of the game. In the. beginning of the round, the dogs are asked what they want to do with their opponents. At the end of the round, the dogs are informed of what their opponents decided to do with them.
Each dog is assigned a unique, stable ID, which is a long integer. This ID is assigned by the frame work at the time the dog is instantiated, and it never changes. The dogs are identified to each other by this ID. So when a dog is asked how it
wants to interact with dog 14, it can base its decision on its history of previous interactions with dog 14. When the dog is told what dog 14 decided to do, it can make a note of that information to be used in future interactions when it meets dog 14 again.
The dogs are not told about inter actions in which they did not participate; for example, dog 11 is not told of the outcome between dog 12 and dog 3.
In an object-oriented framework, base classes are typically provided. These base classes contain both con 1: create methods (ones that have been fully implemented) and abstract methods (ones that have been defined but not implemented). The abstract methods are the hooks by which programmers provide specialized objects.
As an example, let's look at the C++ definition of dog, shown in Listing 2. I have simplified the definition by showing only protected and public areas.