Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please use Python In this assignment we will be implementing a 3D version of Tic-Tac-Toe game. It has 1 board of 5x5 cells. To win,

Please use Python image text in transcribed

In this assignment we will be implementing a 3D version of Tic-Tac-Toe game. It has 1 board of 5x5 cells. To win, a player must have a series of 5 consecutive cells marked with the same symbol. For example, a player will win if he/she manages to get 4 Xs on one line in the same table (any table): X X X X Or vertically: X X X X 2 Or diagonally: X X And so on... When we run the program we will get the following message: Hello and welcome to the Tic-Tac-Toe Comp 208 challenge: Player against Computer. The board is numbered from 1 to 64 as per the following: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 Player starts first. Simply input the number of the cell you want to occupy. Player's move is marked with X. Computer's move is marked with o. Start? (y): 3 If you press "n" for no, the program exits. If you press "y" for yes, the game starts and will ask the player to choose a cell: Which cell would you like to occupy: 23 Assuming the player enters 23, to occupy cell number 23, which is located in the second row, third column of the second table. Now, the program should choose a cell for the computer's move, assuming that your code selected the cell number 8, the board will be displayed as follow to reflect both the player's move and the computer's: 1 2 3 4 5 6 7 0 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 Directly after that the program should ask the user to input the number of cell for his/her next move: Which cell would you like to occupy: This should go on until the end of the game meaning that until either the player or the computer wins the game, or also until all the cells are occupied and a tie situation is occurring meaning that no one won the game. A message should be displayed to announce the winner or to announce a tie situation: Congratulations. Player wins. 4 Please note the following about the implementation of this assignment: 1. You are not allowed to use advanced Python techniques that were not covered in this class. 2. You are not allowed to use Python libraries that were not covered yet in this class. 3. Efficiency of your code will be graded, meaning that your implementation should be the most efficient possible. You need to make sure that you are not making unnecessary checking or unnecessary looping. 4. You shall not hardcode all the winning cases. The algorithm must be able to find the winner without hardcoding. Let's build the game step by step. Step 1 (10 pts): Let's write the main game loop. Write a function called main() that contains an infinite loop. The loop will keep on displaying the last up to date state of the board (by calling the function described in step 2) then asks the user to input a cell number as per the previous description. The loop will exit when the game is over because someone wins or because we got a tie. Note that the main function will be calling all the other functions described below. Your main Python script will only call the main function. Step 2 (15 pts): Write a function called displayBoard(board) that prints out to the screen the tic-tac-toe board reflecting the current status of the game. For a new game, the board will be empty except for the cell numbers. After each move the displayBoard function should reflect the new status by correctly displaying Xs and Os where appropriate. 5 Feel free to use one data structure or many data structures to implement the board. Adapt the code accordingly. Step 3 (15 pts): After every move we need to check if the move is legal. Write the function checklfLegal(number, board) which will return True if the move is legal, False otherwise. The function takes the cell number as argument. If the user inputs an illegal cell number for the move (illegal because it is out of range or because it is the number of an already occupied cell) the checkiflegal function should warn the user about the move and the program should ask the user to input a different cell number. Step 4 (20 pts) After every move and after verifying that the move is legal, we need to check whether we have a winner. Write the function checkWinner(board) that will return True if the game is over, False otherwise. If the checkWinner function finds a winner, a message should be displayed to the screen identifying who won the game and the program should exit. Remember that sometimes the board is full and no winner, this is called a tie, in this case the game is over, the program should announce a tie then exits. Step 5 (5 pts): Write the function that decides the move for the computer computerMove(board). For simplicity, the program will choose a random number that is legal, meaning that the number is within the acceptable range and that the cell is not occupied so far. 6 Step 6 (20 pts): Let's make the computer smarter by trying to guess a move that would block the user from winning. The function smartComputer Move(board) will replace the previous function and will decide the move for the computer. The move should not be random, you need to check whether there is a move that would make the player a winner, if so you need to block this cell in order to block the opponent from winning. If there is not a move that would make the player a winner, check whether there is a move that would make the computer a winner. If such a move exists, you need to make it. Don't use any artificial intelligence algorithm. Please come up with your own method to achieve this goal. Feel free to come up with out of the box solutions. Ingenuity has no limits. Step 7 (15 pts): Rewrite the whole game to make it possible for the user to choose the dimension of the board. When the game starts, it will first ask the user to input the dimensions of the board. The minimum accepted number is 3. If for example the user inputs 7, a board of 7 by 7 will be created. The game will be following exactly the same rules as before. For this question, submit a separate file called assignment3_enhanced.py

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions