SlideShare a Scribd company logo
In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with
their respective tokens (either X or O). When one player has placed three tokens in a horizontal,
vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate
occurs when all the cells on the grid have been filled with tokens and neither player has achieved
a win. Write a program that emulates a Tic Tac Toe game. When you are done, a typical session
will look like this: Welcome to tic-tac-toe. Enter coordinates for your move following the X and
O prompts. 1 2 3 A | | ----- B | | ----- C | | X:A2 1 2 3 A |X| ----- B | | ----- C | | O:B3 1 2 3 A |X| ---
-- B | |O ----- C | | And so on. Illegal moves will prompt the user again for a new move. A win or
a stalemate will be announced, mentioning the winning side if any. The program will terminate
whenever a single game is complete. For this lab, you will be provided with a base file to work
with. The base file can be downloaded from: https://github.com/victoryu/CIS35A-LabsLinks to
an external site. You will add and/or modify the code, as instructed below. Do not change the
overall structure of the program. Just fill in with your code at TODO and Step #. This file has the
general framework of the TicTacToe class. An object of this class will represent a tic-tac-toe
"board". The board will be represented internally by a two dimensional array of characters (3 x
3), and by a character indicating who's turn it is ('X' or 'O'). These are stored in the class instance
variables as follows. private char[][] board; private char player; // 'X' or 'O' You will need to
define the following methods: 1. A constructor: public TicTacToe() to create an empty board,
with initial value of a space (' ') 2. play method public boolean play(String position) if position
represents a valid move (e.g., A1, B3), add the current player's symbol to the board and return
true. Otherwise, return false. 3. switchTurn method public void switchTurn() switches the current
player from X to O, or vice versa. 4. won method public boolean won() Returns true if the
current player has filled three in a row, column or either diagonal. Otherwise, return false. 5.
stalemate method public boolean stalemate() Returns true if there are no places left to move; 6.
printBoard method public void print() prints the current board 7. Use the following test code in
your main method to create a TicTacToe object and print it using the printBoard method given,
so as to test your code. Your printBoard method should produce the first board in the example
above. public static void main(String[] args) { Scanner in = new Scanner(System.in); TicTacToe
game = new TicTacToe(); System.out.println("Welcome to Tic-tac-toe");
System.out.println("Enter coordinates for your move following the X and O prompts");
while(!game.stalemate()) { game.print(); System.out.print(game.getPlayer() + ":"); //Loop while
the method play does not return true when given their move. //Body of loop should ask for a
different move while(!game.play(in.next())) { System.out.println("Illegal move. Enter your
move."); System.out.print(game.getPlayer() + ":"); } //If the game is won, call break;
if(game.won()) break; //Switch the turn game.switchTurn(); } game.print(); if(game.won()) {
System.out.println("Player "+game.getPlayer()+" Wins!!!!"); } else {
System.out.println("Stalemate"); } } Test the following cases: 1. A player makes a legal
movement; 2. A player makes an illegal movement; 3. Player X wins 4. Player X loses 5.
Stalemate (neither player wins)
In a game of Tic Tac Toe- two players take turns making an available c.docx

More Related Content

Similar to In a game of Tic Tac Toe- two players take turns making an available c.docx

Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
Sunjid Hasan
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
shakilaghani
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
FashionColZone
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
Utkarsh Aggarwal
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
fms12345
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
udit652068
 
python.pptx
python.pptxpython.pptx
python.pptx
sreeshanthSingarapu
 
Shoot-for-A-Star
Shoot-for-A-StarShoot-for-A-Star
Shoot-for-A-Star
Dmitry Kazakov
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
noorcon
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docx
abhi353063
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88
Mahmoud Samir Fayed
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
amit657720
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
info382133
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
info430661
 

Similar to In a game of Tic Tac Toe- two players take turns making an available c.docx (14)

Artificial intelligence - python
Artificial intelligence - pythonArtificial intelligence - python
Artificial intelligence - python
 
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdfConnect4.c2. Include the string.h header file3. Declare the foll.pdf
Connect4.c2. Include the string.h header file3. Declare the foll.pdf
 
You will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdfYou will write a multi-interface version of the well-known concentra.pdf
You will write a multi-interface version of the well-known concentra.pdf
 
Tic tac toe on c++ project
Tic tac toe on c++ projectTic tac toe on c++ project
Tic tac toe on c++ project
 
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdfExercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
Exercise 1 (10 Points) Define a FixdLenStringList class that encaps.pdf
 
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdfWorking with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
Working with Layout Managers. Notes 1. In part 2, note that the Gam.pdf
 
python.pptx
python.pptxpython.pptx
python.pptx
 
Shoot-for-A-Star
Shoot-for-A-StarShoot-for-A-Star
Shoot-for-A-Star
 
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
Introduction to Game Programming: Using C# and Unity 3D - Chapter 6 (Preview)
 
This is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docxThis is an individual project, to be completed on your own. It i.docx
This is an individual project, to be completed on your own. It i.docx
 
The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88The Ring programming language version 1.3 book - Part 38 of 88
The Ring programming language version 1.3 book - Part 38 of 88
 
Objectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docxObjectives Create a Java program using programming fundamentals (fi.docx
Objectives Create a Java program using programming fundamentals (fi.docx
 
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdfPlease follow the data 1) For Line 23 In the IF - Condition yo.pdf
Please follow the data 1) For Line 23 In the IF - Condition yo.pdf
 
package com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdfpackage com.tictactoe; public class Main {public void play() {.pdf
package com.tictactoe; public class Main {public void play() {.pdf
 

More from MichaelQEBMartinc

int FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docx
int FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docxint FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docx
int FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docx
MichaelQEBMartinc
 
Instructions- Indicate whether each of the following statements is tru (1).docx
Instructions- Indicate whether each of the following statements is tru (1).docxInstructions- Indicate whether each of the following statements is tru (1).docx
Instructions- Indicate whether each of the following statements is tru (1).docx
MichaelQEBMartinc
 
Instructions- Please answer all questions in FULL sentences- Use APA.docx
Instructions-  Please answer all questions in FULL sentences-  Use APA.docxInstructions-  Please answer all questions in FULL sentences-  Use APA.docx
Instructions- Please answer all questions in FULL sentences- Use APA.docx
MichaelQEBMartinc
 
Instructions Part 1- Compare and contrast the similarities and differe.docx
Instructions Part 1- Compare and contrast the similarities and differe.docxInstructions Part 1- Compare and contrast the similarities and differe.docx
Instructions Part 1- Compare and contrast the similarities and differe.docx
MichaelQEBMartinc
 
Instructions Assign ICD-10-CM codes after interpreting coding conventi.docx
Instructions Assign ICD-10-CM codes after interpreting coding conventi.docxInstructions Assign ICD-10-CM codes after interpreting coding conventi.docx
Instructions Assign ICD-10-CM codes after interpreting coding conventi.docx
MichaelQEBMartinc
 
Instructions Amount Hershey needs- $1 billion to build four new manufa.docx
Instructions Amount Hershey needs- $1 billion to build four new manufa.docxInstructions Amount Hershey needs- $1 billion to build four new manufa.docx
Instructions Amount Hershey needs- $1 billion to build four new manufa.docx
MichaelQEBMartinc
 
Insertion Sort- 7- Copy paste the card images to the empty cells below.docx
Insertion Sort- 7- Copy paste the card images to the empty cells below.docxInsertion Sort- 7- Copy paste the card images to the empty cells below.docx
Insertion Sort- 7- Copy paste the card images to the empty cells below.docx
MichaelQEBMartinc
 
Input of preparatory reaction (1-2) Output of preparatory reaction (2-.docx
Input of preparatory reaction (1-2) Output of preparatory reaction (2-.docxInput of preparatory reaction (1-2) Output of preparatory reaction (2-.docx
Input of preparatory reaction (1-2) Output of preparatory reaction (2-.docx
MichaelQEBMartinc
 
Innovative Consulting Co- has the foliowhg accounts in its jodper Cash.docx
Innovative Consulting Co- has the foliowhg accounts in its jodper Cash.docxInnovative Consulting Co- has the foliowhg accounts in its jodper Cash.docx
Innovative Consulting Co- has the foliowhg accounts in its jodper Cash.docx
MichaelQEBMartinc
 
Information Technology Project Management Which of these types of p.docx
Information Technology Project Management    Which of these types of p.docxInformation Technology Project Management    Which of these types of p.docx
Information Technology Project Management Which of these types of p.docx
MichaelQEBMartinc
 
Indicate whether the following items can be classified on a statement.docx
Indicate whether the following items can be classified on a statement.docxIndicate whether the following items can be classified on a statement.docx
Indicate whether the following items can be classified on a statement.docx
MichaelQEBMartinc
 
Indigo Inc- uses a calendar year for financial reporting- The company (1).docx
Indigo Inc- uses a calendar year for financial reporting- The company (1).docxIndigo Inc- uses a calendar year for financial reporting- The company (1).docx
Indigo Inc- uses a calendar year for financial reporting- The company (1).docx
MichaelQEBMartinc
 
Income statement information for Martincz Tire Repair Corporation for.docx
Income statement information for Martincz Tire Repair Corporation for.docxIncome statement information for Martincz Tire Repair Corporation for.docx
Income statement information for Martincz Tire Repair Corporation for.docx
MichaelQEBMartinc
 
In your initial post- present an area or a country that currently has.docx
In your initial post- present an area or a country that currently has.docxIn your initial post- present an area or a country that currently has.docx
In your initial post- present an area or a country that currently has.docx
MichaelQEBMartinc
 
include calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docx
include calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docxinclude calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docx
include calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docx
MichaelQEBMartinc
 
In what areas will oxygen move into the blood- In the lungs None of th.docx
In what areas will oxygen move into the blood- In the lungs None of th.docxIn what areas will oxygen move into the blood- In the lungs None of th.docx
In what areas will oxygen move into the blood- In the lungs None of th.docx
MichaelQEBMartinc
 
In the Stevens Case- the Supreme Court determined that the defendant-.docx
In the Stevens Case- the Supreme Court determined that the defendant-.docxIn the Stevens Case- the Supreme Court determined that the defendant-.docx
In the Stevens Case- the Supreme Court determined that the defendant-.docx
MichaelQEBMartinc
 
In the last few years- many healthcare organizations have had challeng.docx
In the last few years- many healthcare organizations have had challeng.docxIn the last few years- many healthcare organizations have had challeng.docx
In the last few years- many healthcare organizations have had challeng.docx
MichaelQEBMartinc
 
In the plot below- the y-axis represented fractional saturation (Y) an.docx
In the plot below- the y-axis represented fractional saturation (Y) an.docxIn the plot below- the y-axis represented fractional saturation (Y) an.docx
In the plot below- the y-axis represented fractional saturation (Y) an.docx
MichaelQEBMartinc
 
In the histology image shown below- letter A represents the - Select-.docx
In the histology image shown below- letter A represents the - Select-.docxIn the histology image shown below- letter A represents the - Select-.docx
In the histology image shown below- letter A represents the - Select-.docx
MichaelQEBMartinc
 

More from MichaelQEBMartinc (20)

int FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docx
int FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docxint FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docx
int FUNCTION(unsigned int process_id) -{ task_t processes-MAX_PROCESSE.docx
 
Instructions- Indicate whether each of the following statements is tru (1).docx
Instructions- Indicate whether each of the following statements is tru (1).docxInstructions- Indicate whether each of the following statements is tru (1).docx
Instructions- Indicate whether each of the following statements is tru (1).docx
 
Instructions- Please answer all questions in FULL sentences- Use APA.docx
Instructions-  Please answer all questions in FULL sentences-  Use APA.docxInstructions-  Please answer all questions in FULL sentences-  Use APA.docx
Instructions- Please answer all questions in FULL sentences- Use APA.docx
 
Instructions Part 1- Compare and contrast the similarities and differe.docx
Instructions Part 1- Compare and contrast the similarities and differe.docxInstructions Part 1- Compare and contrast the similarities and differe.docx
Instructions Part 1- Compare and contrast the similarities and differe.docx
 
Instructions Assign ICD-10-CM codes after interpreting coding conventi.docx
Instructions Assign ICD-10-CM codes after interpreting coding conventi.docxInstructions Assign ICD-10-CM codes after interpreting coding conventi.docx
Instructions Assign ICD-10-CM codes after interpreting coding conventi.docx
 
Instructions Amount Hershey needs- $1 billion to build four new manufa.docx
Instructions Amount Hershey needs- $1 billion to build four new manufa.docxInstructions Amount Hershey needs- $1 billion to build four new manufa.docx
Instructions Amount Hershey needs- $1 billion to build four new manufa.docx
 
Insertion Sort- 7- Copy paste the card images to the empty cells below.docx
Insertion Sort- 7- Copy paste the card images to the empty cells below.docxInsertion Sort- 7- Copy paste the card images to the empty cells below.docx
Insertion Sort- 7- Copy paste the card images to the empty cells below.docx
 
Input of preparatory reaction (1-2) Output of preparatory reaction (2-.docx
Input of preparatory reaction (1-2) Output of preparatory reaction (2-.docxInput of preparatory reaction (1-2) Output of preparatory reaction (2-.docx
Input of preparatory reaction (1-2) Output of preparatory reaction (2-.docx
 
Innovative Consulting Co- has the foliowhg accounts in its jodper Cash.docx
Innovative Consulting Co- has the foliowhg accounts in its jodper Cash.docxInnovative Consulting Co- has the foliowhg accounts in its jodper Cash.docx
Innovative Consulting Co- has the foliowhg accounts in its jodper Cash.docx
 
Information Technology Project Management Which of these types of p.docx
Information Technology Project Management    Which of these types of p.docxInformation Technology Project Management    Which of these types of p.docx
Information Technology Project Management Which of these types of p.docx
 
Indicate whether the following items can be classified on a statement.docx
Indicate whether the following items can be classified on a statement.docxIndicate whether the following items can be classified on a statement.docx
Indicate whether the following items can be classified on a statement.docx
 
Indigo Inc- uses a calendar year for financial reporting- The company (1).docx
Indigo Inc- uses a calendar year for financial reporting- The company (1).docxIndigo Inc- uses a calendar year for financial reporting- The company (1).docx
Indigo Inc- uses a calendar year for financial reporting- The company (1).docx
 
Income statement information for Martincz Tire Repair Corporation for.docx
Income statement information for Martincz Tire Repair Corporation for.docxIncome statement information for Martincz Tire Repair Corporation for.docx
Income statement information for Martincz Tire Repair Corporation for.docx
 
In your initial post- present an area or a country that currently has.docx
In your initial post- present an area or a country that currently has.docxIn your initial post- present an area or a country that currently has.docx
In your initial post- present an area or a country that currently has.docx
 
include calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docx
include calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docxinclude calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docx
include calculations Problem 4- Consider the system x1-x13x2x2-x1x2 Is.docx
 
In what areas will oxygen move into the blood- In the lungs None of th.docx
In what areas will oxygen move into the blood- In the lungs None of th.docxIn what areas will oxygen move into the blood- In the lungs None of th.docx
In what areas will oxygen move into the blood- In the lungs None of th.docx
 
In the Stevens Case- the Supreme Court determined that the defendant-.docx
In the Stevens Case- the Supreme Court determined that the defendant-.docxIn the Stevens Case- the Supreme Court determined that the defendant-.docx
In the Stevens Case- the Supreme Court determined that the defendant-.docx
 
In the last few years- many healthcare organizations have had challeng.docx
In the last few years- many healthcare organizations have had challeng.docxIn the last few years- many healthcare organizations have had challeng.docx
In the last few years- many healthcare organizations have had challeng.docx
 
In the plot below- the y-axis represented fractional saturation (Y) an.docx
In the plot below- the y-axis represented fractional saturation (Y) an.docxIn the plot below- the y-axis represented fractional saturation (Y) an.docx
In the plot below- the y-axis represented fractional saturation (Y) an.docx
 
In the histology image shown below- letter A represents the - Select-.docx
In the histology image shown below- letter A represents the - Select-.docxIn the histology image shown below- letter A represents the - Select-.docx
In the histology image shown below- letter A represents the - Select-.docx
 

Recently uploaded

Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Henry Hollis
 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
blueshagoo1
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
deepaannamalai16
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
Kalna College
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
TechSoup
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
andagarcia212
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Celine George
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapitolTechU
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
zuzanka
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
EduSkills OECD
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
سمير بسيوني
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
Mohammad Al-Dhahabi
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
sanamushtaq922
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
Kalna College
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
Steve Thomason
 
Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”
Taste
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
nitinpv4ai
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
Celine George
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
OH TEIK BIN
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
indexPub
 

Recently uploaded (20)

Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.pptLevel 3 NCEA - NZ: A  Nation In the Making 1872 - 1900 SML.ppt
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.ppt
 
CIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdfCIS 4200-02 Group 1 Final Project Report (1).pdf
CIS 4200-02 Group 1 Final Project Report (1).pdf
 
Standardized tool for Intelligence test.
Standardized tool for Intelligence test.Standardized tool for Intelligence test.
Standardized tool for Intelligence test.
 
220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology220711130097 Tulip Samanta Concept of Information and Communication Technology
220711130097 Tulip Samanta Concept of Information and Communication Technology
 
Accounting for Restricted Grants When and How To Record Properly
Accounting for Restricted Grants  When and How To Record ProperlyAccounting for Restricted Grants  When and How To Record Properly
Accounting for Restricted Grants When and How To Record Properly
 
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
欧洲杯下注-欧洲杯下注押注官网-欧洲杯下注押注网站|【​网址​🎉ac44.net🎉​】
 
Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17Creation or Update of a Mandatory Field is Not Set in Odoo 17
Creation or Update of a Mandatory Field is Not Set in Odoo 17
 
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptxCapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
CapTechTalks Webinar Slides June 2024 Donovan Wright.pptx
 
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptxRESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
RESULTS OF THE EVALUATION QUESTIONNAIRE.pptx
 
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
Andreas Schleicher presents PISA 2022 Volume III - Creative Thinking - 18 Jun...
 
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdfمصحف القراءات العشر   أعد أحرف الخلاف سمير بسيوني.pdf
مصحف القراءات العشر أعد أحرف الخلاف سمير بسيوني.pdf
 
skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)skeleton System.pdf (skeleton system wow)
skeleton System.pdf (skeleton system wow)
 
Observational Learning
Observational Learning Observational Learning
Observational Learning
 
220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx220711130088 Sumi Basak Virtual University EPC 3.pptx
220711130088 Sumi Basak Virtual University EPC 3.pptx
 
A Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two HeartsA Visual Guide to 1 Samuel | A Tale of Two Hearts
A Visual Guide to 1 Samuel | A Tale of Two Hearts
 
Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”Creative Restart 2024: Mike Martin - Finding a way around “no”
Creative Restart 2024: Mike Martin - Finding a way around “no”
 
Bonku-Babus-Friend by Sathyajith Ray (9)
Bonku-Babus-Friend by Sathyajith Ray  (9)Bonku-Babus-Friend by Sathyajith Ray  (9)
Bonku-Babus-Friend by Sathyajith Ray (9)
 
How to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in useHow to Fix [Errno 98] address already in use
How to Fix [Errno 98] address already in use
 
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptxA Free 200-Page eBook ~ Brain and Mind Exercise.pptx
A Free 200-Page eBook ~ Brain and Mind Exercise.pptx
 
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
THE SACRIFICE HOW PRO-PALESTINE PROTESTS STUDENTS ARE SACRIFICING TO CHANGE T...
 

In a game of Tic Tac Toe- two players take turns making an available c.docx

  • 1. In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program that emulates a Tic Tac Toe game. When you are done, a typical session will look like this: Welcome to tic-tac-toe. Enter coordinates for your move following the X and O prompts. 1 2 3 A | | ----- B | | ----- C | | X:A2 1 2 3 A |X| ----- B | | ----- C | | O:B3 1 2 3 A |X| --- -- B | |O ----- C | | And so on. Illegal moves will prompt the user again for a new move. A win or a stalemate will be announced, mentioning the winning side if any. The program will terminate whenever a single game is complete. For this lab, you will be provided with a base file to work with. The base file can be downloaded from: https://github.com/victoryu/CIS35A-LabsLinks to an external site. You will add and/or modify the code, as instructed below. Do not change the overall structure of the program. Just fill in with your code at TODO and Step #. This file has the general framework of the TicTacToe class. An object of this class will represent a tic-tac-toe "board". The board will be represented internally by a two dimensional array of characters (3 x 3), and by a character indicating who's turn it is ('X' or 'O'). These are stored in the class instance variables as follows. private char[][] board; private char player; // 'X' or 'O' You will need to define the following methods: 1. A constructor: public TicTacToe() to create an empty board, with initial value of a space (' ') 2. play method public boolean play(String position) if position represents a valid move (e.g., A1, B3), add the current player's symbol to the board and return true. Otherwise, return false. 3. switchTurn method public void switchTurn() switches the current player from X to O, or vice versa. 4. won method public boolean won() Returns true if the current player has filled three in a row, column or either diagonal. Otherwise, return false. 5. stalemate method public boolean stalemate() Returns true if there are no places left to move; 6. printBoard method public void print() prints the current board 7. Use the following test code in your main method to create a TicTacToe object and print it using the printBoard method given, so as to test your code. Your printBoard method should produce the first board in the example above. public static void main(String[] args) { Scanner in = new Scanner(System.in); TicTacToe game = new TicTacToe(); System.out.println("Welcome to Tic-tac-toe"); System.out.println("Enter coordinates for your move following the X and O prompts"); while(!game.stalemate()) { game.print(); System.out.print(game.getPlayer() + ":"); //Loop while the method play does not return true when given their move. //Body of loop should ask for a different move while(!game.play(in.next())) { System.out.println("Illegal move. Enter your move."); System.out.print(game.getPlayer() + ":"); } //If the game is won, call break; if(game.won()) break; //Switch the turn game.switchTurn(); } game.print(); if(game.won()) { System.out.println("Player "+game.getPlayer()+" Wins!!!!"); } else { System.out.println("Stalemate"); } } Test the following cases: 1. A player makes a legal movement; 2. A player makes an illegal movement; 3. Player X wins 4. Player X loses 5. Stalemate (neither player wins)