Project 1 - Tic-Tac-Toe (V2)
Project 1 - Tic-Tac-Toe (V2)
Instructions
1. Answer the below question in the boxes if needed.
2. Code on your computer and zip all your code before submission.
3. Please submit the assignment through TalentLabs Learning System.
Part 0 Setting up your development environment
Steps:
1. Go to the official website(https://code.visualstudio.com/) of Visual Studio
Code to download the latest version of Visual Studio Code installer.
Steps:
1. Open the “Extension” panel by clicking on the fifth icon on the left.
2. In the search bar, type “Python” and install the “Python Extension”.
5. In the terminal opened at the bottom of VSCode, type “python” and press
enter. If the setup is successful, then you should see something like the
following screenshot (Python 3.x.x).
6. If the above step is not successful, install python in the step 7
7. Download Python Windows installer here:
https://www.python.org/ftp/python/3.9.4/python-3.9.4-amd64.exe
8. In the installation step, click “Customized Installation”
9. Make sure you selected “Add Python to environment variables”
10. After the installation, restart the VSCode and try step 4 ~ 5 again, and you
should see this:
5. Give the new file name as “helloworld.py”. It should look like something like
the screenshot below.
6. In the helloworld.py file, type in the following code.
8. If it is successful, then you should see the output at the bottom of the window.
Part 1 Project Introduction
In this project, you are going to build a Tic-Tac-Toe game in the command
line interface. Two players, X and O are gonna take turns in picking their
next move by entering the numbers in the command line (See the
screenshot on the right hand side.)
To help you in building the project, we have break down the project into 2
parts:
● Part 1: To build all the utility functions for this game including:
○ markBoard
○ printBoard
○ validateMove
○ checkWin
○ checkFull, and
○ A constant variable storing all the winning combination
(winCombinations)
● Part 2: To complete the game play using the utility functions you
built in Part 1.
The name of the property represents the position of the box, while the value of the property
represents who put their mark in the box (either “X” or “O” or “ “).
2.2 Get familiar with the utility functions that you are going to build
This function should fill in the box picked with the mark X or O.
printBoard() Print out the game board in the format below. If a box is
unoccupied, then you should print the number of that box.
validateMove(position) This function takes in the position that the player picked as an
input, and validates for the following error. This function
should return true or false, with true denoting correct input.
checkWin Check if the input user is the winner by returning true or false.
True denotes the player wins.
checkFull Check if the game is in a tie situation, i.e. all boxes occupied
with no winner.
The test cases specifications start from line 62 of the tic-tac-toe_Part1.py file. We built the
automated tests using a Python Module named “unittest”. You don’t have to worry about the
setup of it, you only need to know how to read the test cases.
Steps:
1. Open the project1 file.
2. Start implementing the functions in tick-tac-toe_Part1.py following the sequence
below. After implementing each of the following, run the test to make sure all the test
cases of that function are passed. You can run the tests by running tic-tac-
toe_Part1.py in the command line.
○ validateMove
○ markBoard
○ winCombinations and checkWin
○ checkFull
○ printBoard (No automated test cases)
3. If you are seeing "All tests passed! Congratulations!" in the console output, then you
have successfully implemented all the functions. Congratulations!
3.1 Copy the utility functions you created to the project file
Steps:
1. Open the tic-tac-toe.py file in the project folder in VSCode.
2. Replace all the functions in this file with the functions you implemented in Part 1 (i.e.
remove line 1-63, and replace with the code from tic-tac-toe_Part1.py without test cases)
3.2 Implement the game play
Basically you will need to complete the game play implementation using the functions you
created in Part 1.
Try play around with the game after finishing the game to make sure it works for all cases
(wrong input, winning scenarios, and tie scenarios)
If you are not too sure about the logic, you can take a look in the flowchart below. The flow chart
described a recommended control flow of the game. We have already included some hints in
the while loop at line 82.