Final: Tic Tac Toe

Reminder: In tic-tac-toe, player X and O take turns marking one square in a 3X3 board with their mark (X or O). A player wins if they get three of their marks in a row horizontally, vertically, or diagonally. If neither player has three in a row when the board is full, the game is a tie.

Your final project is to implement a web-based version of tic-tac-toe where the user plays against the computer. A user will pick moves on the page, and you will make the computer's move using the method described below.

There are lots of tic-tac-toe programs on the web. You may not use any other code either as the basis for your code , to help with parts of your code, nor may you take segments of it to use as your own (other than code you or I have written in class). Do not consult other programs, in Javascript or in any other language. You may not use them for logic or for syntax. You must solve this problem entirely on your own and writing code entirely on your own. You may not work with other students, on the code or on the logic. This entire program from ideas to implementation in Javascript must be written by you working alone with no collaboration. Basically, this is a test of your problem solving abilities.

Let the user make the first move. After they do, display an updated board with the computer's move and theirs shown. Repeat until the end of the game. If the game ends, either because you win or there is a tie, print out a message that says the result and do not allow the user to make another move.

You will be graded on your implementation of the algorithm, and the effectiveness of game play (i.e. does it work like it should).

The Interface

You can make the interface look any way you like. It could build on the forms I gave you in earlier assignments or you can create something new. Whatever you do, there should be an easy way for a player to see the board and pick a space.

I'd suggest having the person somehow indicate their move and then click a button which will prompt you to compute the computer's move, which you then enter into the board.

The Algorithm

Do this in three parts:
  1. After the user makes a move, check if they won. If they did, announce it.
  2. If not, the computer will check to see what move it should make. First, just get the computer to move anywhere. Then the user should be able to move again.
  3. Once that's working, the computer should be smart about making a move:
    1. Can it win by making a move? If so, make that move.
    2. If it can't win, can it block the human from winning on their next move (essentially, are there two Xes in a row)? If so, block them.
    3. If neither of the above are true, the computer should make a move. It can move anywhere.
    After the computer moves, check to see if it won. If so, announce that! If not, the user moves again.
  4. If you get all that working and want a challenge, email me!

Grading

The final is worth 10 points. Here's how many total points you will earn under certain circumstances:
  • 7 points if the computer isn't playing effectively but the human can play both players and you can detect a win from X
  • 8 points if there is working game play (the human can move and there's a computer move)
  • 9 points if the computer will block X from winning
  • 10 points if the computer can block X and make a winning move if one exists
  • <7 points with some partial credit if you don't get computer play or a win check.