This exercise is Part 4 of 4 of the Tic Tac Toe exercise series. The other exercises are: Part 1, Part 2, and Part 3.
In 3 previous exercises, we built up a few components needed to build a Tic Tac Toe game in Python:
- Draw the Tic Tac Toe game board
- Checking whether a game board has a winner
- Handle a player move from user input
The next step is to put all these three components together to make a two-player Tic Tac Toe game! Your challenge in this exercise is to use the functions from those previous exercises all together in the same program to make a two-player game that you can play with a friend. There are a lot of choices you will have to make when completing this exercise, so you can go as far or as little as you want with it.
Here are a few things to keep in mind:
- You should keep track of who won - if there is a winner, show a congratulatory message on the screen.
- If there are no more moves left, don’t ask for the next player’s move! As a bonus, you can ask the players if they want to play again and keep a running tally of who won more - Player 1 or Player 2.
Starting this exercise from scratch will take you longer than 30 minutes. The best way to save time is to reuse work that has already been done!
A large part of programming is reusing code written by someone else to accomplish a task. Sometimes it is fun to write a solution yourself, but other times you want to build on top of something else. This exercise gives you an opportunity to practice one of the arts of programming - starting from code someone else wrote and creating something on top of it.
To effectively complete this exercise, you will need to make extensive use of functions to accomplish small, modular, tasks within your larger program. Here are some resources about functions in case you get stuck:
- The PracticePython take on functions
- Learn Python the Hard Way, exercise 19 and exercise 21
- Execute some basic code on learnpython.org If you are new to Python, this might be one of the longest programs you have written so far, so have fun!