Your task is to develop a Tic-Tac-Toe (also called as “Noughts and Crosses”) game in Java using Swing. In this assignment, you are asked to implement a single-player version of the Tic-Tac-Toe game with easy-to-use graphical user interface (GUI). One player will be the user and the second player will be artificial intelligence (AI), namely, the computer. The entire procedure of the implementation has been split into three tasks with detailed description and explanation provided. By completing the three tasks, you will develop your own Tic-Tac-Toe game. Task 1: GUI Implementation Please implement a GUI satisfying the following requirements. • A menu bar with two buttons “Reset” and “Quit”. User can click the “Reset” button to restore the software to the initial status. User can software the game by clicking the “Quit” button; • The top pane is an information board to display username and present some basic guidance to the user about this game. The information board will also print out the winner (user or AI) at the end of the current game session; • The bottom pane is a text box, where user is required to enter a username before starting the first game session. Once the username has been given, it cannot be changed anymore unless the entire game software is reset by clicking the “Reset” button from the menu; • The right pane has two buttons “Start” and “Re-play”. User can click the “Start” button to start the game session if a valid username is given. During the middle of a game session, or the current game session is finished, user can click “Re-play” to start a new game session (without changing username). Note that the “Start” button will be deactivated after the game starts, and the “Re-play” button will be activated only after the first nought has been placed by user; • The central area is a three-by-three square grid with a total of nine buttons. During a game session, user can click one of the buttons to place a nought, namely, mark “O”, to the selected cell within the grid. After this, AI will place randomly a cross, namely, mark “X”, at any cell within the grid if it is not occupied. Then, user can place the next nought at an unoccupied cell by clicking the corresponding button, and the cycle continues until all nine cells have been occupied by noughts and crosses. However, once a particular cell has been occupied by either a nought or a cross, user and AI cannot overwrite that mark. In other words, if user has already clicked the button to place a nought or AI has placed a cross on the cell, clicking the same button will do nothing, and AI cannot change the mark on it as well. Note that you could change the layout of your GUI as you prefer. However, the GUI should contain all the elements as described above and the functionalities should be kept the same. Importantly, the GUI must be easy-to-use. Tips: (a) JMenu - menu; (b) JLabel - information board; (c) JTextField - text box; (d) JButton - buttons. Task 2: Adding Some Intelligence to AI In the GUI you have implemented in Task 1, AI will place a cross at an unoccupied cell within the grid in a purely random manner. In Task 2, you are asked to implement a basic algorithm to let AI to act in a more clever (semi-random) manner such that AI will prefer the empty cell that is surrounded by the most cells with noughts. In other words, the empty cell with the most noughts nearby will be more likely to be chosen by AI for placing a cross. Task 3: Finding the Winner Once the AI has been improved in Task 2, you will realise that the GUI will continue the current game session until all the nine cells within the three-by-three grid have been filled. However, the problem is that the current game session may already finish before that, i.e., when user has placed three noughts or AI has placed three crosses in a row. Therefore, in Task 3, you are asked to implement an algorithm such that the software will check whether one of the two players has actually won the game after the fifth mark has been placed onto the grid. Once the algorithm identifies the winner, the current game session finishes, and user and AI will not be able to put any marks further. The information board will print out who is the winner. After that, user can either click “Re-play” button to restart the game session or use “Re-set” option on the menu to initialise the software. Note that in some cases, there will be no winner even after all nine cells have been occupied. The algorithm needs to identify such cases and the information board needs to display the message accordingly.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Your task is to develop a Tic-Tac-Toe (also called as “Noughts and Crosses”) game in Java using Swing.

In this assignment, you are asked to implement a single-player version of the Tic-Tac-Toe game with easy-to-use graphical user interface (GUI). One player will be the user and the second player will be artificial intelligence (AI), namely, the computer. The entire procedure of the implementation has been split into three tasks with detailed description and explanation provided. By completing the three tasks, you will develop your own Tic-Tac-Toe game.

Task 1: GUI Implementation
Please implement a GUI satisfying the following requirements.
• A menu bar with two buttons “Reset” and “Quit”. User can click the “Reset” button to restore the software to the initial status. User can software the game by clicking the “Quit” button;
• The top pane is an information board to display username and present some basic guidance to the user about this game. The information board will also print out the winner (user or AI) at the end of the current game session;
• The bottom pane is a text box, where user is required to enter a username before starting the first game session. Once the username has been given, it cannot be changed anymore unless the entire game software is reset by clicking the “Reset” button from the menu;
• The right pane has two buttons “Start” and “Re-play”. User can click the “Start” button to start the game session if a valid username is given. During the middle of a game session, or the current game session is finished, user can click “Re-play” to start a new game session (without changing username). Note that the “Start” button will be deactivated after the game starts, and the “Re-play” button will be activated only after the first nought has been placed by user;
• The central area is a three-by-three square grid with a total of nine buttons. During a game session, user can click one of the buttons to place a nought, namely, mark “O”, to the selected cell within the grid. After this, AI will place randomly a cross, namely, mark “X”, at any cell within the grid if it is not occupied. Then, user can place the next nought at an unoccupied cell by clicking the corresponding button, and the cycle continues until all nine cells have been occupied by noughts and crosses. However, once a particular cell has been occupied by either a nought or a cross, user and AI cannot overwrite that mark. In other words, if user has already clicked the button to place a nought or AI has placed a cross on the cell, clicking the same button will do nothing, and AI cannot change the mark on it as well.
Note that you could change the layout of your GUI as you prefer. However, the GUI should contain all the elements as described above and the functionalities should be kept the same. Importantly, the GUI must be easy-to-use.
Tips: (a) JMenu - menu; (b) JLabel - information board; (c) JTextField - text box; (d) JButton - buttons.
Task 2: Adding Some Intelligence to AI
In the GUI you have implemented in Task 1, AI will place a cross at an unoccupied cell within the grid in a purely random manner. In Task 2, you are asked to implement a basic algorithm to let AI to act in a more clever (semi-random) manner such that AI will prefer the empty cell that is surrounded by the most cells with noughts. In other words, the empty cell with the most noughts nearby will be more likely to be chosen by AI for placing a cross.
Task 3: Finding the Winner
Once the AI has been improved in Task 2, you will realise that the GUI will continue the current game session until all the nine cells within the three-by-three grid have been filled. However, the problem is that the current game session may already finish before that, i.e., when user has placed three noughts or AI has placed three crosses in a row. Therefore, in Task 3, you are asked to implement an algorithm such that the software will check whether one of the two players has actually won the game after the fifth mark has been placed onto the grid. Once the algorithm identifies the winner, the current game session finishes, and user and AI will not be able to put any marks further. The information board will print out who is the winner. After that, user can either click “Re-play” button to restart the game session or use “Re-set” option on the menu to initialise the software. Note that in some cases, there will be no winner even after all nine cells have been occupied. The algorithm needs to identify such cases and the information board needs to display the message accordingly.

The right pane has two buttons "Start" and "Re-play". User can click the "Start" button to start
the game session if a valid username is given. During the middle of a game session, or the
current game session is finished, user can click "Re-play" to start a new game session (without
changing username). Note that the "Start" button will be deactivated after the game starts,
and the "Re-play" button will be activated only after the first nought has been placed by user;
The central area is a three-by-three square grid with a total of nine buttons. During a game
session, user can click one of the buttons to place a nought, namely, mark "O", to the selected
cell within the grid. After this, Al will place randomly a cross, namely, mark "X", at any cell
within the grid if it is not occupied. Then, user can place the next nought at an unoccupied cell
by clicking the corresponding button, and the cycle continues until all nine cells have been
occupied by noughts and crosses. However, once a particular cell has been occupied by either
a nought or a cross, user and Al cannot overwrite that mark. In other words, if user has already
clicked the button to place a nought or Al has placed a cross on the cell, dicking the same
button will do nothing, and Al cannot change the mark on it as well.
Note that you could change the layout of your GUI as you prefer. However, the GUI should contain all
the elements as described above and the functionalities should be kept the same. Importantly, the
GUI must be easy-to-use.
Tips: (a) JMenu - menu; (b) JLabel - information board; (c) JTextField - text box; (d) JButton - buttons.
Task 2: Adding Some Intelligence to AI
In the GUI you have implemented in Task 1, Al will place a cross at an unoccupied cell within the grid
in a purely random manner. In Task 2, you are asked to implement a basic algorithm to let Al to act in
a more clever (semi-random) manner such that Al will prefer the empty cell that is surrounded by the
most cells with noughts. In other words, the empty cell with the most noughts nearby will be more
likely to be chosen by Al for placing a cross.
Task 3: Finding the Winner
Once the Al has been improved in Task 2, you will realise that the GUI will continue the current game
session until all the nine cells within the three-by-three grid have been filled. However, the problem
is that the current game session may already finish before that, i.e., when user has placed three
noughts or Al has placed three crosses in a row. Therefore, in Task 3, you are asked to implement an
algorithm such that the software will check whether one of the two players has actually won the game
after the fifth mark has been placed onto the grid. Once the algorithm identifies the winner, the
current game session finishes, and user and Al will not be able to put any marks further. The
information board will print out who is the winner. After that, user can either dick "Re-play" button
to restart the game session or use "Re-set" option on the menu to initialise the software. Note that in
some cases, there will be no winner even after all nine cells have been occupied. The algorithm needs
to identify such cases and the information board needs to display the message accordingly.
Transcribed Image Text:The right pane has two buttons "Start" and "Re-play". User can click the "Start" button to start the game session if a valid username is given. During the middle of a game session, or the current game session is finished, user can click "Re-play" to start a new game session (without changing username). Note that the "Start" button will be deactivated after the game starts, and the "Re-play" button will be activated only after the first nought has been placed by user; The central area is a three-by-three square grid with a total of nine buttons. During a game session, user can click one of the buttons to place a nought, namely, mark "O", to the selected cell within the grid. After this, Al will place randomly a cross, namely, mark "X", at any cell within the grid if it is not occupied. Then, user can place the next nought at an unoccupied cell by clicking the corresponding button, and the cycle continues until all nine cells have been occupied by noughts and crosses. However, once a particular cell has been occupied by either a nought or a cross, user and Al cannot overwrite that mark. In other words, if user has already clicked the button to place a nought or Al has placed a cross on the cell, dicking the same button will do nothing, and Al cannot change the mark on it as well. Note that you could change the layout of your GUI as you prefer. However, the GUI should contain all the elements as described above and the functionalities should be kept the same. Importantly, the GUI must be easy-to-use. Tips: (a) JMenu - menu; (b) JLabel - information board; (c) JTextField - text box; (d) JButton - buttons. Task 2: Adding Some Intelligence to AI In the GUI you have implemented in Task 1, Al will place a cross at an unoccupied cell within the grid in a purely random manner. In Task 2, you are asked to implement a basic algorithm to let Al to act in a more clever (semi-random) manner such that Al will prefer the empty cell that is surrounded by the most cells with noughts. In other words, the empty cell with the most noughts nearby will be more likely to be chosen by Al for placing a cross. Task 3: Finding the Winner Once the Al has been improved in Task 2, you will realise that the GUI will continue the current game session until all the nine cells within the three-by-three grid have been filled. However, the problem is that the current game session may already finish before that, i.e., when user has placed three noughts or Al has placed three crosses in a row. Therefore, in Task 3, you are asked to implement an algorithm such that the software will check whether one of the two players has actually won the game after the fifth mark has been placed onto the grid. Once the algorithm identifies the winner, the current game session finishes, and user and Al will not be able to put any marks further. The information board will print out who is the winner. After that, user can either dick "Re-play" button to restart the game session or use "Re-set" option on the menu to initialise the software. Note that in some cases, there will be no winner even after all nine cells have been occupied. The algorithm needs to identify such cases and the information board needs to display the message accordingly.
COMP5200: Tic-Tac-Toe
Assignment Overview
Your task is to develop a Tic-Tac-Toe (also called as "Noughts and Crosses") game in Java using Swing.
Tic-Tac-Toe is played on a three-by-three grid by two players, who alternately place the marks "O" and
"X" in one of the nine spaces in the grid. The player who succeeds in placing three of their marks in a
horizontal, vertical, or diagonal row is the winner. An example of Tic-Tac-Toe game is given by Fig. 1,
where the player with mark "O" is the winner. If you are not familiar with this game, please read more
from the Wikipedia webpage: https://en.wikipedia.org/wiki/Tic-tac-toe.
Fig. 1. Example of Tic-Tac-Toe game
In this assignment, you are asked to implement a single-player version of the Tic-Tac-Toe game with
easy-to-use graphical user interface (GUI). One player will be the user and the second player will be
artificial intelligence (AI), namely, the computer. The entire procedure of the implementation has been
split into three tasks with detailed description and explanation provided. By completing the three
tasks, you will develop your own Tic-Tac-Toe game.
Please implement the entire game within a single dass, and submit the project folder with all the
contents as a single zip file to the submission area on Moodle before the deadline. Any work submitted
after the deadline will receive zero mark unless an extension has been agreed before submission.
Deadline: Friday, 8 April 2022, 11:55 pm
Description
Details of the software are as follows.
Task 1: GUI Implementation
Please implement a GUI satisfying the following requirements.
• A menu bar with two buttons "Reset" and "Quit". User can click the "Reset" button to restore
the software to the initial status. User can software the game by dicking the "Quit" button;
• The top pane is an information board to display username and present some basic guidance
to the user about this game. The information board will also print out the winner (user or Al)
at the end of the current game session;
• The bottom pane is a text box, where user is required to enter a username before starting the
first game session. Once the username has been given, it cannot be changed anymore unless
the entire game software is reset by clicking the "Reset" button from the menu;
Transcribed Image Text:COMP5200: Tic-Tac-Toe Assignment Overview Your task is to develop a Tic-Tac-Toe (also called as "Noughts and Crosses") game in Java using Swing. Tic-Tac-Toe is played on a three-by-three grid by two players, who alternately place the marks "O" and "X" in one of the nine spaces in the grid. The player who succeeds in placing three of their marks in a horizontal, vertical, or diagonal row is the winner. An example of Tic-Tac-Toe game is given by Fig. 1, where the player with mark "O" is the winner. If you are not familiar with this game, please read more from the Wikipedia webpage: https://en.wikipedia.org/wiki/Tic-tac-toe. Fig. 1. Example of Tic-Tac-Toe game In this assignment, you are asked to implement a single-player version of the Tic-Tac-Toe game with easy-to-use graphical user interface (GUI). One player will be the user and the second player will be artificial intelligence (AI), namely, the computer. The entire procedure of the implementation has been split into three tasks with detailed description and explanation provided. By completing the three tasks, you will develop your own Tic-Tac-Toe game. Please implement the entire game within a single dass, and submit the project folder with all the contents as a single zip file to the submission area on Moodle before the deadline. Any work submitted after the deadline will receive zero mark unless an extension has been agreed before submission. Deadline: Friday, 8 April 2022, 11:55 pm Description Details of the software are as follows. Task 1: GUI Implementation Please implement a GUI satisfying the following requirements. • A menu bar with two buttons "Reset" and "Quit". User can click the "Reset" button to restore the software to the initial status. User can software the game by dicking the "Quit" button; • The top pane is an information board to display username and present some basic guidance to the user about this game. The information board will also print out the winner (user or Al) at the end of the current game session; • The bottom pane is a text box, where user is required to enter a username before starting the first game session. Once the username has been given, it cannot be changed anymore unless the entire game software is reset by clicking the "Reset" button from the menu;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY