CS-211 Fall 2015 Lab 11 Tic-Tac-Toe


Today, the goal is to get some experience with refining requirements, as well as designing and implementing solutions. Since designing and implementing a full program can be quite time-consuming, we are going to be revising and improving an existing implementation.

Specifically, we are going to work on the ancient game of tic-tac-toe (or Noughts and Crosses if you have an English background.) Why tic-tac-toe? Well here's a quote from the Wikipedia article on Tic-Tac-Toe... "Because of the simplicity of Tic-tac-toe, it is often used as a pedagogical tool for teaching the concepts of good sportsmanship and the branch of artificial intelligence that deals with the searching of game trees."

Getting Started

After you have logged on to one of the Linux Lab machines, open a terminal window, download lab11.tar.gz and move it into you home directory. Use the command tar -xvzf lab11.tar.gz. This will unpack the tar file and make a new lab11 subdirectory. Make the lab11 directory your current directory. There should be 2 files... a Makefile, and a program files called ttt.c.

The Makefile contains just one target... ttt. If you make ttt it will comple ttt.c and create a ttt command.

Start off by building the ttt command and running the command (no parameters are required.) Just type ./ttt to run. Once you have played a couple of games of tic-tac-toe, you may start to realize that your opponent (the ttt program in this case) is not very smart, and often loses the game. However, the nature of the tic-tac-toe game is that a competant player will never lose! If two competant players play against each other, the result will always be a draw.

Making he Computer Smarter

The real work in this lab involves improving how well the computer plays tic-tac-toe. You may not have enough time to implement a strategy that never loses tic-tac-toe, but you can certainly improve on the existing strategy. Read through the code in ttt.c to understand how the game infrastructure works, and to see if there are any functions that might be useful to improve your strategy. You may want to do some researh on the game to see if there are any good strategies that are relatively easy to implement.

When you have some ideas on how to improve your code, modify the getComputerMove function to implement your strategy. Try it out.

Before the end of the lab, when you have implemented an improved strategy, ask the lab instructor (professor or CA, depending on what section you are in) to try playing against your updated code.

Lab Report

Download and edit the following file: lab11_report.txt. Then submit your editted file on Blackboard in the Lab_11 report area.