Dealing with the fear of being a boring teacher.


Tic-Tac-Toe Artificial Intelligences & Student Responsibility

Note: I think the last bit of this post will be interesting to most of you in a general sense, even if you don’t teach computer science.

I wanted my kids to do something more interactive with each other in programming. Up until now the kids have basically just been working on projects that I’ve come up with. They’ve added their own little variations, but in general I’ve orchestrated the whole thing (chagrin). My goal with the course has been to introduce genuinely interesting projects that have way more than one functioning solution. I really impress on my kids that this course is not about making the code “work,” it is about planning and thinking of an elegant solution to a problem that could be solved any number of inelegant ways.

For instance, I have them program a battleship clone. This turns out to be heavy on arrays. I know it may sound simple to those of you who are well versed — and are probably way more experienced CS teachers than myself — but my kids have a great and difficult time trying to organize and shuffle all of the information necessary to run this simple game.

Next, I wanted something where the kids could play each other. Battleship was nominally two player. By that I mean two kids could sit down and take turns clicking at the same machine. I wanted to foster the idea of communication via the Internet between programs so I came up with this idea: Battling Tic-Tac-Toe Artificial Intelligences. The kids would write a program that could assess the state of a game and then make a good next move. This information would then need to be stored on a server for their opponent’s AI to go and get in order to make a move. The kids loved it. We ended up making a big deal out of it. We had a bracket system, there were prizes, the whole school filled out brackets online. This was probably borderline ethically (gambling), but hey, I’m generally toeing the line with instructional activities as it is (my room has been on fire more than once).

My style in programming is to present the idea of the end product with a few concrete demands. Everything else is up to the kid. My demands were:

  1. The AI must always make a legal move.
  2. The AI must store the game state in a standard format in a file available to the other AI.
  3. The AI must function autonomously from the programmer.

So, my first question for all of you is: Is this good pedagogy? I’m admittedly green in the CS department. How are projects presented? Is this project-based model out of date? I’d love to hear how assignments and the like are handled in others’ programming courses.

The kids used about 5 days in class to program their AI’s. This was exciting. Many kids were quite secretive about how their program would select the best move. Many kids had crushing realizations that their program had to be smart enough to play both X’s and O’s. Which required a whole lot more programming for offense vs. defense.

The day of the tournament came and the kids chose sweet names for their AI’s (i.e.: Super Purple Pony Squadron, Var_Dump). Things went alright. Some kids obviously didn’t finish and had to forfeit. Some of the kids that were picked to win the whole tournament were knocked out in the first round via some fatal error in their programming logic. There was moderate buzz around the building, which means that programming itself was getting some much need PR. It was great to see how different approaches fared in the tournament. The basic approaches were:

  1. Play purely defense: always look for a block
  2. Play purely randomly. (this was pretty much punting on 4th and 20 for the kids who couldn’t finish on time)
  3. Use logic to play offense and defense, just like a human.
  4. Play sequentially: place left-right, top-bottom

An AI of type 3 won the tournament, but an AI of type 4 got all the way to the finals. There was pizza, revelry, and smack talk. My kind of classroom. At one point there was a wave and some chanting. Here’s a screen shot of the Tic-Tac-Toctagon:


Here’s what I liked about the lesson/project:

  1. The end result was social
  2. There was no road map to the end result (not that road maps are common for me.)
  3. The project involved the whole school

Teaching Responsibility (!= Grading It)

I was presented with one challenge: the students who didn’t meet the deadline of tournament day. How was I going to deal with their embarrassment at forfeiting? How should I grade them? How is my Standards-Based system going to incorporate participating in the tournament?

I thought to myself, “What standards are wrapped up in this project?” Arrays, Looping, Logic, and File System Mechanics. These are what I want this project to assess, the tournament is sort of just a carrot out in front. Do I really want their grade to be altered by their performance in something that’s supposed to be fun and silly? No. I decided that tournament participation would have to have nothing to do with their grade. I graded the unfinished projects against my standards just like the finished projects.

On the day of the tournament I decided that having to admit that they had to forfeit was a necessary evil. I don’t really love putting high schoolers in embarrassing situations, but I think that being eliminated from something fun is a great way to teach the great (unstated) responsibility lesson. It’s not going to ruin your grade, but it’s still going to suck that you decided not to put the work in to get this thing done. So, some kids had to forfeit, and they didn’t like it. Some kids who thought they had the best programs had to forfeit due to overlooking some small avenues. This was a great lesson. However, I refuse, I mean I absolutely refuse to let something as arbitrary as this lower a kid’s grade. Many of them have a deep understanding of programming, but messed up one little if/else statement on game day. Should there really be “points” for participation? No. In the end, I feel forfeiting taught responsibility in a way grades could never even hope to approximate.

Each pile of source code came in, flooding my inbox. I graded each one for elegance, use of arrays, use of logic and flow control, etc. All my standards. What the students get is feedback about what they have done, instead of just negative points about not being able to compete. The students also see concrete — yet dynamic — grades for the central themes in programming, instead of “TicTacToe AI: 40/60.” Honestly, what would that even mean? Did they compete poorly? Did their AI not work? Did it work, but cheat? I can’t even imagine regressing back to the summative-obsessed model. Have I ever mentioned that I love Standards-Based Grading?

Shawn Cornally • April 29, 2010

Previous Post

Next Post


  1. Andrew May 4, 2010 - 3:59 pm

    @Chris: That’s cute! It gets the nice balance between elegant and “understandable to 5th graders.”

    I did my first round of this with students today (right before I went home with a wicked fever, so I was not on the top of my game). In 20 minutes I had 4 groups do explicit non-reactive move sequences, which was enough to get the smack talk flowing. We’ll see how it loks next week I bring in a mildly adaptive player.

  2. Chris May 4, 2010 - 5:33 am

    Andrew: There’s a cute trick you could use that might make win checking easier. If you label the cells with the numbers 1-9 in the pattern of a magic square, then a player wins when they own three squares that sum to 15.

    • Shawn May 4, 2010 - 6:53 am

      @Chris: Oh! That’s great! I never thought of that. Totally going to use that next year. Thanks!

      Thanks for the great conversation, all. I really appreciate the ideas here!


  3. Andrew May 3, 2010 - 10:22 pm

    Maria- I whipped up a little demo in a free period this afternoon, and will try to introduce it to my 5th graders tomorrow. Send me an email to andrew carle (oneword) AT gmail if you’d like to see my kludge.

    Your place pictures via stamps was a good one. Much cleaner than I had feared. Win checking on a 9 element list is still huge and messy, alas.

  4. Maria Droujkova May 3, 2010 - 7:29 am

    Andrew – clever! You could probably implement this easier with some less “coordinate-oriented” games. Still, with just 9 cells, you can tell the cat (or some other character) to go stamp them by coordinates to change the state.

    I think I may try to have a demo for the May 22nd international Scratch Day we are celebrating :-)

  5. Andrew May 3, 2010 - 6:14 am

    @Maria – If you wanted to run “competitive”projects like this in Scratch, you’d forget the web-comunication and go wist a bunch of scripted Sprites that you can load up on one machine.

    Make a “board” sprite for use by the class. Define a 9 element list that records the board state. Assuming you don’t want to gin-up 255,168 different costumes for the board-sprite, you’d need to be a bit clever with how you read the list and placed the X’s & O’s. But once that’s done, you’ve got a really standard interface for kids to work with.

    Now every kid sprite doesn’t need to do anything but read the board_state list (be sure to make it available to every sprite!), and then modify it. Load two competing sprites, set the Board Sprite to broadcast alternating turn signals to them, and then let it go.

    If you wanted to do rule checking (like making sure there were no overwrite rules), then that should be done at the Board level as well. But I think that a room full of MS students are quite effective at detecting erroneous TicTacToe moves. :)

    Hmm. Maybe I can set this up this week for my 5th graders…

  6. Chris April 29, 2010 - 7:55 pm

    Sometimes for beginning students I use a game similar to the lightcycles from Tron. Each turn you decide whether to turn left, turn right, or go straight, but you can analyze the board as much as you want before deciding.

    For more experienced students, I use a simulation of two ant colonies that are battling for limited resources (food). This one is nominally an exercise in object-oriented programming, but really its an excuse to get them excited about programming.

  7. Chris April 29, 2010 - 4:15 pm

    I run similar events every year, although for more complicated games and more experienced students.

    I distribute several opponents ahead of time, in a range of difficulties from easy to moderate (not hard). They can experiment and try different strategies against those opponents from day one. The assessment is then (partially) based on how well they do against those opponents.

    The tournament is just for fun, but students and other observers get really fired up about it. Lots of hootin’ and hollerin’!

    I structure the tournament as a round-robin where everybody plays everybody else, and students who don’t finish simply are omitted from the schedule, rather than forfeiting. Although, honestly, I think the good-natured ribbing students get when their agent does something visibly stupid is probably more embarassing than a forfeit would be.

    One of the things I really love about these tournaments is that the winner is almost never the top students in the class, but rather somebody in the middle of the class who could use the ego-boost and positive reinforcement far more than the top students.

    • Shawn April 29, 2010 - 6:21 pm

      @Chris: I love the idea of distributing opponent AI’s. What games do you play? Thanks for the comment!

      @Maria: Thanks for commenting; I’m going to spend a bunch of time this summer playing with Scratch, please let me know what you come up with!


  8. Maria Droujkova April 29, 2010 - 3:57 pm

    Neat idea! Thank you for the detailed description. Now to figure out how to do something like this in Scratch and GeoGebra…

Comments are closed.