Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
  • module Player1 (player1.py)
    1. Player 1 will ask the user for the host information of player 2:
      1. Prompt the user for the host name/IP address of player 2 they want to play with
      2. Prompt the user for the port to use in order to play with player 2
    2. Using that information they will attempt to connect to player 2
      1. Upon successful connection they will send player 2 the their user name (over the socket, just alphanumeric user name with no special characters)
      2. If the connection cannot be made then the user will be asked if they want to try again:
        1. If the user enters 'y' then you will request the host information from the user again
        2. If the user enters 'n' then you will end the program
    3. Once player 1 receives player 2's username or if the users decides to play again (see step 4.2 below)
      1. Player 1 will ask the user for their move using the built-in input() function
      2. and send it to player 2.
        1. Player 1 will always be x/X
        2. Player 1 will always send the first move to player 2
          1. Each move will correspond to the input given using the keyboard.
        3. Once player 1 sends their move they will wait for player 2's move.
        4. 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)
    4. Once a game as finished (win or tie) the user will indicate if they want to play again using the command line.
      1. If the user enters 'y' or 'Y' then player 1 will send "Play Again" to player 2
      2. If the user enters 'n' or 'N' then player 1 will send "Fun Times" to player 2 and end the program
        1. Once the user is done player they will print all the statistics.
  • module Player2 (player2.py)
    1. The user will be asked to provide the host information so that it can establish a socket connection.
    2. Player 2 will accept incoming requests to start  a new game
    3. When a connection request is received and accepted, player 2 will wait for player 1 to send their user name
    4. 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.
      1. 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.
        1. Each move will correspond to the input given using the keyboard.
      2. Once player 2 sends their move they will wait for player 1's move.
      3. 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)
    5. 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.
      1. If player 1 wants to play again then player 2 will wait for player 1's first move.
      2. 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

RubricPts

updateGamesPlayed() (1 pts)
resetGameBoard() (1 pts)
updateGameBoard() (1 pt)
isWinner() (1 pt)
boardIsFull() (0.5 pts)
printStats() (correctly computed info - 1 pts total)

 

5.5 pts
 

The current board state is shown to both players after each player makes a move. (1 pt)
Both programs end when the player 1 no longer wants to play (1 pt)
Continuing to play once a game is done properly starts a new game, clearing both boards (1 pt)
Game statistics are printed on both terminals when player 1 chooses to quit playing - each player will see their own statistics(1 pt)
Players cannot make moves out of turn, or invalid moves (1 pt)

 

4.5 pts
 

The program requests the host info on both player modules (1 pts)
The modules establish a connection (1 pt)
The players exchange their username (1 pt)
Both players send their moves to each other via sockets (1 pt)
Both players receive each other's moves via sockets (1 pt)

 

5 pts
 

Classes are used appropriately (1pt)

Functions are small and cohesive (2 pts)
Variable names are meaningful and self-identifying (0.25 pts)
Docstrings follow the Google Style Guide (0.5 pt)
Input and return types are documented properly in the function declaration (0.25 pts)
There is no executing code outside of any function or indentation block (0.5 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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Operating System questions

Question

Find the inverse, if it exists, for the matrix. -1

Answered: 1 week ago