Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Make a TicTacToe game, you want it to be able to compete against the computer as well as you. Hence, your game is going to

Make a TicTacToe game, you want it to be able to compete against the computer as well as you. Hence, your game is going to have two modes: (i) single player mode (against the computer) and (ii) two player mode. In two player mode, your program should first ask the players their names and toss a coin to decide who goes first. Then the program should ask the users to take turns playing the game. Ensure that each move is legitimate, and print the game result when someone wins or when the game ends in a draw. In one player mode, your program should first ask for the difficulty as well as the player's name. There can be 3 modes: easy, medium, or hard. Then it should toss a coin to decide who gets to go first. In easy mode, the computer just randomly decides a row and column (really dumb) and keeps doing that until a valid move is found. In hard mode, your program should be good enough so that the human never wins; instead, the game should end in a "draw" or "the computer wins." Here is the algorithm you should implement for the hard AI: 1. Check if there is a winning move available, and if yes, make that move and win. 2. If not, check if there is a winning move available for the opponent, and if yes, take that spot on the board. 3. If not, then check to see if the center spot is empty. If yes, take that spot on the board. 4. If not, then see if there are any open corners on the board. If yes, take the first open corner found on the board. 5. If not, then find any remaining empty spot on the board and take that spot.

Medium should be in between these two. It should not be dumb but not as good as the hard level. It's up to you how you want to implement the AI for this difficulty as long as you follow this guideline. There should be a main menu option to display the last match. As you'll see in the starter code, this can be achieved by storing each turn of the game in an ArrayList. Player one and player two refer to the order in which the players enter their names. Player one gets the 'X' character while player two gets the 'O' character. Player one does NOT refer to the player who takes the first turn, since it's based on a coin-flip. When playing one-player mode, the AI will always be player two. Lastly, the menu should repeat unless the user selects the quit option

Struggling to make the methods and code I need some help

Sample code for single player:

One player, playing a game in each mode and watching some replays 1. Single player 2. Two player

D. Display last match Q. Quit What do you want to do: s 's' is not a valid option

Sample code for 2 players:

Two players, game ends in tie with replay display 1. Single player 2. Two player D. Display last match Q. Quit What do you want to do: 2 Enter player 1 name: Nazim Enter player 2 name: Obed Tossing a coin to decide who goes first!!! Obed gets to go first. | | ----------- | | ----------- | | Obed's turn: Obed enter row: 1 Obed enter col: 1 | | ----------- | O | ----------- | |

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

Statistics For Business & Economics

Authors: David R. Anderson, Dennis J. Sweeney, Thomas A. Williams, Jeffrey D. Camm, James J. Cochran

13th Edition

1305585313, 978-1305585317

More Books

Students also viewed these Programming questions