Tic-Tac-Toe with a Computer Player

Note that this is lab is a continuation of Unit 3 Lab 3: Tic-Tac-Toe

Pacing

The X lab pages could be split across X–X days (X–X minutes). Expected times to complete follow:
Expected times to complete the optional projects follow, but these times will vary significantly depending on your students:

Prepare

Lab Pages

  1. If students have been told that a computer program is "a sequence of steps," it may take some intellectual effort to learn to think instead of a program as built out of functions. But the effort pays off in vastly reducing the work of writing the actual code. For example, students are asked to write winning square for, a function whose input is "X" or "O" and whose return value is a number from 1 to 9, or 0 if there is no winning square on this move. Some students will want to jump right into coding, and will have an impossibly long sequence of if board=(some list) report (some number). (There are 39=19,683 possible board configurations, so it would be a very long procedure if they try to cover every one.) But finding a winning triple is just find first from the list of winning triples, where the predicate function is, e.g., "this triple has two O squares and no X squares." And then the actual winning square is find first looking for a number in the winning triple. The resulting program isn't quite a one-liner because it has to check for the case in which there is no winning triple, but it's hardly any code compared to the sequence of if statements.