Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using Pythong to make a Tic-tac-toe game in a 2D list where EMPTY = 0 X = 1 O = 2. I'm currently struggling with

Using Pythong to make a Tic-tac-toe game in a 2D list where

EMPTY = 0 X = 1 O = 2.

I'm currently struggling with Part 7.

Part 7: Giving the player an easy hint You should now be able to play the game successfully. You will notice that there is a hint option before each time you get to play on the board. This hint function has not yet been implemented. (If you are playing on a 3 by 3 board there is a hidden hint. You can enter a when prompted for a hint for an AI suggestion of a place to play.) We will implement a simple hint option that will be used by the game code to give the user a location to play to either win on their next play, or stop the opponent from winning. Edit the existing function named hint (notice the use of a lowercase h). The function will take 2 parameters: 1. a two-dimensional list that holds a representation of the board game-state 2. the piece type of one of the players The function returns a row and a column. Currently this is a default value of -1,-1 which indicates there is no hint. We will add code before this default value that will attempt to find a hint of a spot that wins the game for the indicated player. The following pseudo-code is an algorithm which gives such a hint. It relies on the concept of checking every location in the board. The algorithm attempts to temporarily play the players piece type. Then it checks if the player has won. If the player has won, then the algorithm reverts the board back to what it was and returns the location. If the player has not won, then the algorithm reverts the board back to what is it was and moves on to the next location.

For every row board For every column in the board If we can play at this row and column Play the players piece If the player has won the game Remove the players piece from the last played location Return the row and column Otherwise, Remove the players piece from the last player location Return -1 ,- 1Once this function is implemented you can enter h when prompted. If there is an immediate play that wins the board or blocks the computer, then that location will be highlighted on the board and the row and column reported in as output. My implementation of hint is around 10-12 lines of code.

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 Systems Introduction To Databases And Data Warehouses

Authors: Nenad Jukic, Susan Vrbsky, Svetlozar Nestorov

1st Edition

1943153191, 978-1943153190

More Books

Students also viewed these Databases questions

Question

4. Give partial credit for partially correct answers.

Answered: 1 week ago

Question

Explain how the appraisal interview should be conducted.

Answered: 1 week ago

Question

Summarize training and development implementation issues.

Answered: 1 week ago

Question

Describe management development.

Answered: 1 week ago