- There are 2 steps to solve this one.SolutionStep 1View the full answer
Algorithm:
Initialize class
TicTacToe
:Initialize an empty
board
as a 2D list to represent the TicTacT...
Step 2UnlockAnswerUnlock
Transcribed image text:
Tic-Tac-Toe For this question, you will be implementing a simple Tic-Tac-Toe game without the graphics. Here is how it works: • First, it is randomly determined if the user starts the game or the computer and this information is shown to the user. The player who starts always starts as "X". • The players (computer and the user) will then take turns in playing. The computer will choose a random empty spot on its turn. The user enters its choice in the console. • Each of the empty spots have a corresponding number that the players choose on their turn. If the user enters anything other than the number of an empty spot (not yet filled with "X" or "O"), it will not be accepted, and they will be prompted to enter a correct number. 3 4 5 7 8 6 After each turn, two things need to be done: 1) displaying the updated board 2) checking if anyone has won (it should be printed who has won - the user or the computer). • The game goes on until someone wins or until all the 9 empty spots are filled and no one has won. When the game ends, the user should see the message saying who has won (even if no one) Implementation details You should implement at least the two following functions. The printings, messages, and shape of the board should match the gameplay example. display Board(board) Parameter board is a dictionary containing the non-empty spots of the board. This function does not return anything. It will just print the content of the board as depicted in Gameplay example. haswon(board) Parameter board is a dictionary containing the non-empty spots of the board. This function determines if anyone has won and returns a suitable value (up to you how you want to handle the returned value). Creating other functions can be helpful (such as checking if the user input is valid, the general gameplay, etc.). The design and implementation of other functions is up to you.
Gameplay example Game is starting You will start the game. Please enter your choice: Updated board: LXI. 4 == Computer is playing Updated board: _|_0_ _!_X_! 2 Your turn. Please enter your choice: Invalid choice, please enter again: Updated board: _X_l_l_o_ -IXI Computer is playing... Updated board: _X_!_!__ _i_X_l_o_ Your turn. Please enter your choice: 8 Updated board: _X_!_!_0 _I_X_l_o_ 1 x You won! Congratulations!
Assignment 3 In this assignment, there are a total of two questions: Morse Code and Tic-Tac-Toe. Similar to the midterm the code for answering both questions should be in a single Python file and the user should be able to select Morse code or the Tic-Tac-Toe to be run. The weight for this assignment is 9%. Morse Code Morse code maps each letter of the alphabet to a series of dashes and dots (a =. The list of the Morse code for all English letters (from a to z) is provided below: Your goal here is to implement a function that takes a list of strings as its only parameter (called "words"). Each of the words can be transformed to Morse code by concatenation of a number of the above strings (without spaces). For example, the transformation of "ab" will be ".--... (".-" + "-..."). The word "ems" will also have the same transformation".-- + " In this function, the goal is to return the number of the unique transformations in words list. Here is an example (none of this is needed to be printed, the function will only return one integer): Words - ("ab", "a", "ems") Returned value: 2 Explanation: the transformation of each word is: "ab" - "a" - "ems There are a total of 2 unique transformations: ".--..." and You should be using dictionaries for this question. You can call this function with the above words example, while grading, we will change the function parameter and call the function with different word lists.