Skip to the content of the web site.

Project M.1: Tic-tac-toe

Write a program play tic-tac-toe against the user. First, query who should go first:

Do you want to go first (y/n)?

Give each box a coordinate, e.g., A3 or C1:

   1   2   3
     |   |
A    |   |
  ---+---+---
B    |   |
  ---+---+---
C    |   |
     |   |

Now, place either an X or an O as appropriate. If someone wins, indicate so; otherwise indicate a draw:

   1   2   3
     |   |
A  X | O | X
  ---+---+---
B  O | O | X
  ---+---+---
C  X | X | O
     |   |

DRAW!

Do you want to play again (y/n)?

You, as the programmer of the computer, should never lose against the human player.