Tic-tac-toe (American English), noughts and crosses (Commonwealth English), or Xs and Os (Irish English) is a paper-and-pencil game for two players who take turns marking the spaces in a three-by-three grid with X or O. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. It is a solved game, with a forced draw assuming best play from both players. Live Website Here.
Tic-tac-toe is played on a three-by-three grid by two players, who alternately place the marks X and O in one of the nine spaces in the grid.
There is no universally-agreed rule as to who plays first.
The Aim of the game is the get three of your marks in a horizontal, vertical, or diagonal row.
Players soon discover that the best play from both parties leads to a draw. Hence, tic-tac-toe is often played by young children who may not have discovered the optimal strategy.
- Was this achieved?
Yes
- How was this achieved?
This was achieved by taking a very simple apporach to the classic Tic Tac Toe.
The game will run in a smooth loop to allow the user to keep playing as many times as they want to or can end the game.
- Was this achieved?
Yes
- How was this achieved?
This was achieved by creating a computer choice function which randomly generates a choice on the board for the computer.
- Was this achieved?
Yes
- How was this achieved?
This was achieved by adding color to the various outcomes of the game.
-
Winner Message, Green ("\033[1;34m").\
-
Lose Message, Red ("\033[1;31;31m").\
-
Draw Message, White ("\033[1;37;40m").\
-
Main Game Color,Pink ("\033[1;35;35m").\
-
Reference Board color, Blue ("\033[1;34;34m").
- This is the first page you see when the app loads. On this page there is a Tic Tac Toe image located at the top of the screen, a welcoem message and a question to the user. The question asks the user "Please Enter Your Name: ".
- The player is welcomed by name and asked to choose a marker to play with. "X" or "O".
- After the user chooses a marker , either the user of computer will play first. The user is asked one more time if they are ready to play?
- The user is presented with the main game screen. A reference board in blue and a game board in pink.
- The user is asked to pick a position to drop their marker.
- If the computer was chose to go first , it's move will already be on the board.
- In the event of the user winning, the user is presented with a winner message in green , and asked if they want to play again
- In the event of the computer winning, the user is presented with a loosing message in red , and asked if they want to play again
- In the event of a draw, the user is presented with a draw message in white , and asked if they want to play again
- The user has selectted that they do not want to play again and is displayed the message below.
- In the future i woudl like to implennt the Minimax algorithm for the computer choice. This would add a much higher level of difficulty to the game. Currently it is only a randomly generated computer choice.
-
Python was tested using PEP8 validator
-
The Python results came back with the following:
Resolved by reduceing line length
Resolved by aligning code up correctly that goes across 2 lines
Resolved by removing blank lines
Resolved by removing additional white space
Resolved by removing trailing whitespace
Resolved by indeningt lines to the opening parentheses
Resolved me removing additonal line and the end of the file.
- When the game is first run , the user can enter in any name , which may include letters , numbers and special characters. This was tested and works as expected. (The Letter F was tested as a name)
- The user is then asked if you want to choose "X" or "O".
- If neither "X" or "O" is entered , the program will keep asking the name quesitons until a valid input is recieved.
- A random decision is then made if the user or computer goes first.
- This was tested by running the program multiple times to see both decisions.
-
The user is then asked if they are ready to play (Yes or No).\
-
A bug was found here when the user enters no.\
-
This was resolved by amending the play_game variable code.
-
This is the error that was recieved
play_game = input('Are you ready to play? Enter Yes or No. ')
if play_game.lower()[0] == 'y':
game_on = True
else:
game_on = False
After this amendment , the code worked as expected.
- Once the user selects "No" , They are then asked if they wish to "play again".\
- If not , the user is displayed a thank you message , and instrucitons how to paly again.
- When the user selection "Yes" that they are ready to play the game, the reference board is displayed and the game board.
- A number from 1-9 must be entered in by the user.
- Any other entry will result in the user being asked again for a selection.
- Even a empty space will ask the user for antoher choice
- When the User Wins the game , a user win message is displayed
- When the User loses the game , a computer win message is displayed
- When the User Draws the game , a Draw message is displayed
- Do you want to play again screen
- If "Yes", the game restarts to the welcome screen
- If anyhing else other than "Y" or "Ye" or "Yes" is entered , the game ends with the ending message and intructions how to play again
- Went to Heroku dashboard and clicked on 'create a new app'.
- Selected a name for my app; every app must have a unique name so I couldn't call it TicTacToe as this was already taken so I went for tictactoe2022.
- Selected my region (Ireland) and clicked create app.
- I then went to the tab at the top of the page and clicked on settings.
- As Instruced on the Codeinstitute tutorial i added a Key: PORT and Value: 8000
- I added the buildpacks needed by clicking on the buildpack button.
- Here I selected python and pressed save changes.
- Then repeated the same process but selected nodejs this time, making sure it was done in that order with python at the top and nodejs under.
- I went back up to the tab at the top and clicked deploy.
- I selected github as the deployment method and clicked connect to github.
- I then searched for my github repository name, and connected to the correct repository.
- Then I scrolled down, here there were two options.
- The first option being to enable automatic deployment, which means that Heroku will rebuild the app every time I pushed a change to github. This is the on i selected.
- The other option being to manually deploy.
- When all the code is received from github there is a view button that it a link to the running app, I clicked this to make sure everything was running as expected.
- Luci Chart was used for the Flow Chart.
- Am I Responsive was used to test the responsiveness of the site
- Github was used as the repository hosting service
- Gitpod was used as the Code Editor for the site
- Heroku was used to deploy the site
- PEP8 was used to test the python code.
- Youtube was used to watch tutorials on how to make tic-tac-toe using python.
The Code used in this website was written by the developer. The Code institute , YouTube and W3 Schools were used a guides.