Question
Assuming our tic tac toe game uses a 3 x 3 board, we will use x/X and o/O for the values that we will be
Assuming our tic tac toe game uses a 3 x 3 board, we will use x/X and o/O for the values that we will be passing back and forth. For those not familiar with Tic Tac Toe, it is a 2 player game where one player's game piece is X and the second player's game piece is O (letter). Each player takes a turn putting their game piece in one of the empty slots in the 3 by 3 board. First place to get 3 of their game pieces that align wins. If the board has no empty slots and nobody wins then the game ends in a tie.
Please read the program details and important details below.
Program Details:
You will create 3 new modules with the following details:
- class BoardClass (gameboard.py)
- The board game will consist of the following public interface. (Note this module can be imported and used by both player1 and player2 modules
- The class should have a minimum of the following (you can add more if you need to):
- Attributes:
- Players user name
- User name of the last player to have a turn
- Number of wins
- Number of ties
- Number of losses
- Functions:
- updateGamesPlayed()
- Keeps track how many games have started
- resetGameBoard()
- Clear all the moves from game board
- updateGameBoard()
- Updates the game board with the player's move
- isWinner()
- Checks if the latest move resulted in a win
- Updates the wins and losses count
- boardIsFull()
- Checks if the board is full (I.e. no more moves to make - tie)
- Updates the ties count
- printStats()
- Prints the following each on a new line:
- Prints the players user name
- Prints the user name of the last person to make a move
- prints the number of games
- Prints the number of wins
- Prints the number of losses
- Prints the number of ties
- Prints the following each on a new line:
- updateGamesPlayed()
- Attributes:
- module Player1 (player1.py)
- Player 1 will ask the user for the host information of player 2:
- Prompt the user for the host name/IP address of player 2 they want to play with
- Prompt the user for the port to use in order to play with player 2
- Using that information they will attempt to connect to player 2
- Upon successful connection they will send player 2 the their user name (over the socket, just alphanumeric user name with no special characters)
- If the connection cannot be made then the user will be asked if they want to try again:
- If the user enters 'y' then you will request the host information from the user again
- If the user enters 'n' then you will end the program
- Once player 1 receives player 2's username or if the users decides to play again (see step 4.2 below)
- Player 1 will ask the user for their move using the built-in input() function
- and send it to player 2.
- Player 1 will always be x/X
- Player 1 will always send the first move to player 2
- Each move will correspond to the input given using the keyboard.
- Once player 1 sends their move they will wait for player 2's move.
- Repeat steps 3.1.2 - 3.1.4 until the game is over (A game is over when a winner is found or the board is full)
- Once a game as finished (win or tie) the user will indicate if they want to play again using the command line.
- If the user enters 'y' or 'Y' then player 1 will send "Play Again" to player 2
- If the user enters 'n' or 'N' then player 1 will send "Fun Times" to player 2 and end the program
- Once the user is done player they will print all the statistics.
- Player 1 will ask the user for the host information of player 2:
- module Player2 (player2.py)
- The user will be asked to provide the host information so that it can establish a socket connection.
- Player 2 will accept incoming requests to start a new game
- When a connection request is received and accepted, player 2 will wait for player 1 to send their user name
- Once player 2 receives player 1's user name, then player 2 will send "player2" as their user name to player 1 (over the socket) and wait for player 1 to send their move.
- Once player 2 receives player 1's move they will ask the user for their move and send it to player 1 using the built-in input() function.
- Each move will correspond to the input given using the keyboard.
- Once player 2 sends their move they will wait for player 1's move.
- Repeat steps 3.1 - 3.2 until the game is over (A game is over when a winner is found or the board is full)
- Once player 2 receives player 1's move they will ask the user for their move and send it to player 1 using the built-in input() function.
- Once a game as finished (win or tie) player 2 will wait for player 1 to indicate if they want to play again using the command line.
- If player 1 wants to play again then player 2 will wait for player 1's first move.
- If player 1 does not wants to play again then player 2 will print the statistics
Important Details:
-
- The User Interface is simple the shell console, you will not give a Graphical User Interface for this lab.
- All user inputs are case insensitive.
- Hint: Maintain the current state of the board on both client and server side to determine if someone won, lost or the board is full.
- Do not use global variables or write everything in 1 giant code block. Organize your code to use functions with inputs and outputs instead.
- You must use docstrings, specify input and return types, and follow general good practices for the code that you write. This is similar to how you saw Lab 2's starter code was written. See the documentation below for more information:
- https://google.github.io/styleguide/pyguide.html#38-comments-and-docstringsLinks to an external site.
- https://google.github.io/styleguide/pyguide.html#316-namingLinks to an external site.
- https://google.github.io/styleguide/pyguide.html#317-mainLinks to an external site.
- https://google.github.io/styleguide/pyguide.html#318-function-lengthLinks to an external site.
- https://google.github.io/styleguide/pyguide.html#319-type-annotationsLinks to an external site.
- Useful Links:
- https://steelkiwi.com/blog/working-tcp-sockets/Links to an external site. (Note this link has an example code for Python 2. In Python 3, when you send a message you must add .encode() after a string, and when you want to receive a message you must add .decode() after the string)
Lab 3: Tic Tac Toe with Command Line
Rubric | Pts |
---|---|
updateGamesPlayed() (1 pts)
| 5.5 pts |
The current board state is shown to both players after each player makes a move. (1 pt)
| 4.5 pts |
The program requests the host info on both player modules (1 pts)
| 5 pts |
Classes are used appropriately (1pt) Functions are small and cohesive (2 pts)
| 5 pts |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
QUESTION Assuming our tic tac toe game uses a 3 x 3 board we will use xX and oO for the values that we will be passing back and forth For those not familiar with Tic Tac Toe it is a 2 player game wher...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started