Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment - Play a fun strategy game that only requires two players! In this game, we have an 8 x 8 board and a Knight

Assignment-Play a fun strategy game that only requires two players! In this game, we have an 8 x 8 board and a Knight chess piece that starts on the top left of the board. Each player gets to move the Knight piece one square over either down, diagonal
(bottom right direction), or to the right of its current position (a player cannot move the piece two or more squares). The Knight piece can keep moving until it reaches the bottom right corner of the board. The respective player that moves the Knight to the bottom right corner of the board wins the game! In this assignment you are going to implement the winning strategy for player 1 only.
For this assignment, you must follow these requirements.
1. You will create a public class called Game.
2. The Game Class will have the following attributes:
a.2D integer array that symbolizes the board to assist you with simulating the game.
b.1D primitive character array that stores the respective moves that will be used for
player 2. Please store them in order of how they are presented here.
i.d for downward diagonal right direction (index 0)
ii.r for horizontal right direction (index 1)
iii. b for vertical bottom direction (index 2)
c. A reference to a Random Class object. This will point to the object created by the driver and passed to the constructor. This should be used when selecting a random move for player 2 in the selectPlayerTwoMove method.
3. The Game Class has a constructor that takes one parameter.
a. A reference to a Random Class object that is instantiated in the driver class.
4. The Game class has a public non-static method called selectPlayerTwoMove. The method will select a random move from the 1D primitive character array attribute that stores the respective move (from 2b). This method is intended to select player 2s move only. This should not be used for player 1. The method should return a primitive
character.
5. The Game class has a public non-static method called play. play will simulate a round of the game where player 1 must win against player 2. The method has no parameters. The method should return a value 1 if the player 1 wins the game, if not return 2 or some other value.
6. You are allowed to create helper methods as long as they are not called directly from the driver file. The helper methods must be called from your solution file.
A driver file (GameDriver.java) has been provided for you to show you how the methods are called along with 10 test cases to see if you get the same scenario result.
The GameDriver Class will test your play method with 10 different test cases. The first part of the code will create 10 different random objects with unique (seeds). Each object will be associated with a test case. Please remember the professor will change a few test cases when
grading your code. After the random objects are instantiated, the Game class objects are instantiated with their respective random object reference. Last, all play methods with the respective game object is invoke and will determine if player 1 won.
//CLASS DRIVER
import java.util.Random;
public class GameDriver
{
public static void main(String [] args) throws Exception
{
//different seeds for each random object
Random rand1= new Random(1);
Random rand2= new Random(2);
Random rand3= new Random(3);
Random rand4= new Random(4);
Random rand5= new Random(5);
Random rand6= new Random(6);
Random rand7= new Random(7);
Random rand8= new Random(8);
Random rand9= new Random(9);
Random rand10= new Random(10);
System.out.println("Testing to See if Player 1 will always win with the
10 random seeds.");
Game g1= new Game(rand1);
Game g2= new Game(rand2);
Game g3= new Game(rand3);
Game g4= new Game(rand4);
Game g5= new Game(rand5)
Game g6= new Game(rand6);
Game g7= new Game(rand7);
Game g8= new Game(rand8);
Game g9= new Game(rand9);
Game g10= new Game(rand10);
if(g1.play()==1)
System.out.println("Game 1 Pass!");
else
System.out.println("Game 1 Fail!");
if(g2.play()==1)
System.out.println("Game 2 Pass!");
else
System.out.println("Game 2 Fail!");
if(g3.play()==1)
System.out.println("Game 3 Pass!");
else
System.out.println("Game 3 Fail!");
if(g4.play()==1)
System.out.println("Game 4 Pass!");
else
System.out.println("Game 4 Fail!");
if(g5.play()==1)
System.out.println("Game 5 Pass!");
else
System.out.println("Game 5 Fail!");
if(g6.play()==1)
System.out.println("Game 6 Pass!");
else
System.out.println("Game 6 Fail!");
if(g7.play()==1)
System.out.println("Game 7 Pass!");
else
System.out.println("Game 7 Fail!");
if(g8.play()==1)
System.out.println("Game 8 Pass!");
else
System.out.println("Game 8 Fail!");
if(g9.play()==1)
System.out.println("Game 9 Pass!");
else
System.out.println("Game 9 Fail!");
if(g10.play()==1)
System.out.println("Game 10 Pass!");
else
System.out.println("Game 10 Fail!");
}
}
image text in transcribed

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

Advances In Databases And Information Systems Uropean Conference Adbis 2020 Lyon France August 25 27 2020 Proceedings Lncs 12245

Authors: Jerome Darmont ,Boris Novikov ,Robert Wrembel

1st Edition

3030548317, 978-3030548315

More Books

Students also viewed these Databases questions