Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

CSCI 2251 - Programming Assignment TicTacToe - Part 2 This assignment is based on the textbook exercise 8.18 (page 325). INSTRUCTIONS For part 2 you

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

CSCI 2251 - Programming Assignment TicTacToe - Part 2 This assignment is based on the textbook exercise 8.18 (page 325). INSTRUCTIONS For part 2 you need to write three methods for the TicTacToe class and add code to Main to call one of the methods. You will also create and use a new enum named Gamestate in TicTacToe.java. First, write a method named validmove in TicTacToe. This method may or may not take two integer inputs representing a row and a column (It depends on whether you choose to make these local or instance variables). The method will return a boolean value (true or false). True should be returned if the row and column values are "in-bounds" and index an empty location on the board. Otherwise return False. I request that you let the user use 1, 2,3 as valid row and column inputs and then subtract 1 from these values before your code performs the actual indexing. (Note that the board does not need passed into the method because it is an instance variable belonging to the TicTacToe object.) Second, write a method named gamestatus in TicTacToe. This method will take no input and will return a value of type GameState. GameState is a new enum that you should implement. GameState should have three values: WIN, DRAW, CONTINUE. The gameStatus method should check the board to see if either player X or player O has won (three in a row), or if the game should continue (if there are empty spaces remaining on the board), or the game is a draw (the entire board is filled up but no one has won). You are encouraged to create private helper methods to organize gameStatus. For example, you might write a method that only checks for a win and takes as input a CellState.X or CellState.O to check for a win for one player or the other. Lastly, you must write a runTests method in TicTacToe and call this method from Main.java. Write custom code in runTests to test, and print the results of, all of the following conditions in order to make sure your latest code is written correctly: - validMove returns false when one of its inputs is less than zero - validMove returns false when one of its inputs is greater than two - validMove returns false when its inputs index a cell in the board that is not empty - validMove returns true when its inputs are in bounds and refer to an empty board cell - gameStatus returns WIN when a player has three in a row - gameStatus returns DRAW when the board is full and there are no three-in-a-rows - gameStatus returns CONTINUE when at least one cell is empty and there are no three-in-arows There begin to be more options for how each person's UML looks. Maybe you will also detect who the winner is in the gameStatus method and save that information in an instance variable named winner. Maybe you will use instance variables row_choice and col_choice to save the chosen moves. It's up to you. There are other ways to organize your TicTacToe game and some of them are probably better (in terms of writing readable, efficient, minimalist code). Compilation and Execution I will test your program as follows (assume both TicTacToe.java and Main.java are in the default folder) javac * java java Main Final Output After completing the next part of this assignment, interaction with the program will look like the following: Player x "s turn. Player X : Enter row (,1 or 2): Player X : Enter column (,1 or 2):1 Player 0s turn. Player 0: Enter row (,1 or 2): Player 0 : Enter column (,1 or 2):2 Player x s turn. Player X : Enter row (,1 or 2): Player X : Enter column (,1 or 2): 2 Invalid move to row , colum 2 Player X : Enter row (,1 or 2) : 2 Player X : Enter column (,1 or 2):3 Invalid move to row 2 , colum 3 Player X : Enter row (,1 or 2): Player X : Enter column (,1 or 2):1 C:IWindows \ System32\cmd.exe Player U's turn. Player 0: Enter row (,1 or 2): 2 Player 0: Enter column (,1 or 2):2 Player X 's turn. Player X : Enter row (,1 or 2) : 1 Player X: Enter column (0,1 or 2):2 Player 0 s turn. Player 0: Enter row(,1 or 2): 2 Player 0: Enter column (0,1 or 2):0 C:WWindows System 32/cmd.exe Player X 's turn. Player X : Enter row(,1 or 2) : 1 Player X: Enter column (,1 or 2)

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What does Processing of an OLAP Cube accomplish?

Answered: 1 week ago