Course Level
CS1
Knowledge Unit
Fundamental Data Structures
Collection Item Type
Assignment
Synopsis

This is a programming assignment given in the middle of an introductory class aimed at non-CS majors. The assignment is to simulate repeated rounds of the Prisoner's Dilemma where there are many prisoners situated in cells on a grid, and neighboring prisoners interact with each other. Since the location of prisoners matters, these are called "spatial games". Each student works alone to write a program to do this simulation and produce an image of the final configuration of strategies. The CS goals of this assignment are to introduce reading files (since the initial configuration of the prisoners is supplied in a file), to practice working with 2-dimensional arrays and structs, and to gain additional practice with control structures (loops, if). Since we provide a template, an additional goal is to understand a partially written program by reading it.

Engagement Highlights

The assignment connects programming with ideas in game theory and evolutionary biology. We motivate the assignment by talking about how groups of individuals may evolve to adopt various strategies to gain fitness. We also talk about how complex behavior and patterns can emerge from simple rules. The connection to evolutionary dynamics typically interests biologists, physicists, and other students. Further, since the outcome is an image file showing the evolved pattern of strategies, the students are excited that they can produce something they can see. Finally, the students realize that this is the general type of simulation program that they might write to investigate behavior in other systems, and this motivates the importance of programming in science. We also provide an extra credit challenge and links to the primary research literature on spatial games, which lets more advanced students challenge themselves.

Materials and Links

Materials

Computer Science Details

Programming Language
Other Programming Language

Material Format and Licensing Information

Creative Commons License
CC BY-NC-SA