Tie-Tac-Toe Problem Description: Tic Tac Toe game is traditionally played on a 3x3 board bewoen two players x and o. A player can mark a single cell by placing a symbol in it (either an x'or an w character). A player who manages to mark a row, column, or a diagonal completely with his symbol fiest wins the game. The game ends in a tie if no player manages to win after all the cells have boen marked. You will design a textal version of this game, in which a human player gets to play against a computer opponent. Program Specification: In this project, you will implement a complete Tio-Tac-Toe game in a Java program. Your implementation should follow this specification. You may use one or two dimensional amay as data structure for the game bourd. Your program should include the following list of methods: 1. initloard ()- update this method This function initializes the game board. There are 9 cells represenied by 1 oc 2 dimensional amay. 2. gameloard ()- update this method This method prints the game boand. 3. checkWinner ()- update this method This method examines the array to see if either player has won. A player has won if he has marked a row, oolumn or diagonal with his symbol. The fimnction retums different values based on results of winner, loser and no winner. 4. void yourTum() This method handles moves made by the wuser. It displays the game board and asks the user to eater a move. If the move is invalid, in peompts user to eater a valid move again. A valid move sefers to one of the empty cells in the board. 5. void machine lum ) This method handles moves by the oompuler. You can implement a simple logic where you just search for an empty position in the array and mark it for computer player. You can get really creative and design the method so that it makes a well thought out move. The logic is entirely up to you. Finally, you should display the ocomputer's move. 6 main ) The main method controls the game. You will declare an amay for the game and make e of the methods that you have writen to produce behavior of the Tie-Tae-Toe game. The human player always makes the finst move in the game. You should alternate hetwoen the human player and the computer. After each move you should check for a wimer using the checkWinner method. While there is no winner, you should display the penchoard, ak the ser for nest valid mowe, update computer move until one of player wim or the gme is tie. Easy vernsion: human vs. human (machineTum method will he skipped) Challenging version: human vs. smant computer (ie. computer can't he heaten) Sample Output: ter dinate le tahi

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 2GZ
icon
Related questions
Question
Tic-Tac-Toe
Problem Description:
Tic Tac Toe game is traditionally played on a 3x3 board berween two players x and o. A
player can mark a single cell by placing a symbol in it (either an 'x'or an 'o' character). A
player who manages to mark a row, column, or a diagonal completely with his symbol
first wins the game. The game ends in a tie if no player manages to win after all the cells
have been marked. You will design a textual version of this game, in which a human
player gets to play against a computer opponent.
Program Specification:
In this project, you will implement a complete Tie-Tac-Toe game in a Java program.
Your implementation should follow this specification. You may use one or two
dimensional amay as data structure for the game board. Your program should include
the following list ef methods:
1. initBoard ()- update this method
This function initializes the game board. There are 9 cells represented by I or 2
dimensional armay.
2. gameBoard ()- upcdate this method
This method prints the game board.
3. checkWinner () - update this method
This method examines the array to see if either player has won. A player has won if he
has marked a row, oolumn or diagonal with his symbol. The function returns different
values based on results of winner, loser and no winner.
4. void yourTum ()
This method handles moves made by the user. It displays the game board and asks the
user to eater a move. If the move is invalid, in prompts user to enter a valid move again.
A valid move refers to one of the empty cells in the board.
5. void machineTum ()
This method handles moves by the computer. You can implement a simple logic where
you just search for an empty position in the array and mark it for computer player. You
can get really creative and design the method so that it makes a well thought out move.
The logic is entirely up to you. Finally, you should display the computer's move.
6. main )
The main method controls the game. You will declare an array for the game and make
use of the methods that you have written to produce behavior of the Tic-Tac-Toe game.
The human player always makes the first move in the game. You should altermate
betwoen the human player and the computer. After each move you should check for a
winner using the checkWinner method. While there is no winner, you should display the
pumehoard, ask the user for next valid move, update computer move until one of player
wins or the game is tie.
Easy version: human vs. human (machineTum method will be skipped)
Challenging version: human vs. smart computer (i.e. computer can't be beaten)
Sample Output:
a enter ceardinate of your lacation Co
ter eeandinate ef r leeat
key ta contie
Transcribed Image Text:Tic-Tac-Toe Problem Description: Tic Tac Toe game is traditionally played on a 3x3 board berween two players x and o. A player can mark a single cell by placing a symbol in it (either an 'x'or an 'o' character). A player who manages to mark a row, column, or a diagonal completely with his symbol first wins the game. The game ends in a tie if no player manages to win after all the cells have been marked. You will design a textual version of this game, in which a human player gets to play against a computer opponent. Program Specification: In this project, you will implement a complete Tie-Tac-Toe game in a Java program. Your implementation should follow this specification. You may use one or two dimensional amay as data structure for the game board. Your program should include the following list ef methods: 1. initBoard ()- update this method This function initializes the game board. There are 9 cells represented by I or 2 dimensional armay. 2. gameBoard ()- upcdate this method This method prints the game board. 3. checkWinner () - update this method This method examines the array to see if either player has won. A player has won if he has marked a row, oolumn or diagonal with his symbol. The function returns different values based on results of winner, loser and no winner. 4. void yourTum () This method handles moves made by the user. It displays the game board and asks the user to eater a move. If the move is invalid, in prompts user to enter a valid move again. A valid move refers to one of the empty cells in the board. 5. void machineTum () This method handles moves by the computer. You can implement a simple logic where you just search for an empty position in the array and mark it for computer player. You can get really creative and design the method so that it makes a well thought out move. The logic is entirely up to you. Finally, you should display the computer's move. 6. main ) The main method controls the game. You will declare an array for the game and make use of the methods that you have written to produce behavior of the Tic-Tac-Toe game. The human player always makes the first move in the game. You should altermate betwoen the human player and the computer. After each move you should check for a winner using the checkWinner method. While there is no winner, you should display the pumehoard, ask the user for next valid move, update computer move until one of player wins or the game is tie. Easy version: human vs. human (machineTum method will be skipped) Challenging version: human vs. smart computer (i.e. computer can't be beaten) Sample Output: a enter ceardinate of your lacation Co ter eeandinate ef r leeat key ta contie
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

Hi I like this code but is it possible to incorportate the 3 methods, because i dont see it in the current code - 

void yourTurn ( ) - This method handles moves made by the user. It displays the game board and asks the user to enter a move.  If the move is invalid, it prompts user to enter a valid move again. A valid move refers to one of the empty cells in the board.

void machineTurn ( ) - This method handles moves by the computer.  One possibility is to search for an empty position in the array and mark it for the computer player

main ( ) - The main method controls the game. You will declare an array for the game and make use of the methods that you have written to produce behavior of the Tic-Tac-Toe game. The human player always makes the first move in the game.  You should alternate between the human player and the computer. After each move you should check for a winner using the checkWinner method. While there is no winner, you should display the gameboard, ask the user for next valid move, update computer move until one of player wins or the game is tie.

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Problems on Dynamic Programming
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT