Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Description: We have an 8 x 8 board and a Knight chess piece that starts on the top left of the board. Each player

Assignment Description: 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, 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 both players.

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.

b. 1D primitive char array (not a String object) that will store computerize moves. There is no need to use the Random Class. Hint: This should be used in one of the hypothetical strategies for one of the players to always win.

3. The Game Class has a constructor that takes two parameters

a. A primitive integer that represents the size of board (assume the board is always a square)

b. A String object reference that contains the name of a file that keeps the moves the player 2 will use in the game.

4. The Game Class has a public non static method called readMoves. readMoves will scan the respective text files of moves and store them in the character array attribute. The characters r, b, and d represent the moves.

a. r means move to the right one square

b. b means move down one square

c. d means move diagonal one square The method has one String reference parameter that represents the name of the text file. This method should be invoked when the object of the class is instantiated.

5. The Game class has a public non static method called play. play will simulate a round of the game. The method has one parameter that represents the player you want to win the game. If a one is passed, then player 1 must win. If a two is passed, then player 2 must win. The method returns an integer type value that represents the winner of the game (1 being player 1 and 2 being player 2). You can assume that player 1 will always go first in the game, however based on the value past, you need to determine the appropriate strategy for always winning the game for the appropriate player. This also includes what the other player must do in their respective move. That means for this scenario there is something that needs to always happen for player 2 to win!!!

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.

DRIVER FILE

public class GameDriver { public static void main(String [] args) throws Exception { System.out.println("Testing to See if Player 1 will always win..."); System.out.println("********************"); Game g1 = new Game(8, "moves1.txt"); Game g2 = new Game(8, "moves2.txt"); Game g3 = new Game(8, "moves3.txt"); Game g4 = new Game(8, "moves4.txt"); Game g5 = new Game(8, "moves5.txt"); if(g1.play(1) == 1) System.out.println("Player 1 Game 1 Pass!"); else System.out.println("Player 1 Game 1 Fail!"); if(g2.play(1) == 1) System.out.println("Player 1 Game 2 Pass!"); else System.out.println("Player 1 Game 2 Fail!"); if(g3.play(1) == 1) System.out.println("Player 1 Game 3 Pass!"); else System.out.println("Player 1 Game 3 Fail!"); if(g4.play(1) == 1) System.out.println("Player 1 Game 4 Pass!"); else System.out.println("Player 1 Game 4 Fail!"); if(g5.play(1) == 1) System.out.println("Player 1 Game 5 Pass!"); else System.out.println("Player 1 Game 5 Fail!");

System.out.println("Testing to See if Player 2 will always win..."); System.out.println("********************"); if(g1.play(2) == 2) System.out.println("Player 2 Game 1 Pass!"); else System.out.println("Player 2 Game 1 Fail!"); if(g2.play(2) == 2) System.out.println("Player 2 Game 2 Pass!"); else System.out.println("Player 2 Game 2 Fail!"); if(g3.play(2) == 2) System.out.println("Player 2 Game 3 Pass!"); else System.out.println("Player 2 Game 3 Fail!"); if(g4.play(2) == 2) System.out.println("Player 2 Game 4 Pass!"); else System.out.println("Player 2 Game 4 Fail!"); if(g5.play(2) == 2) System.out.println("Player 2 Game 5 Pass!"); else System.out.println("Player 2 Game 5 Fail!"); } }

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_2

Step: 3

blur-text-image_3

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

The Power Of Numbers In Health Care A Students Journey In Data Analysis

Authors: Kaiden

1st Edition

8119747887, 978-8119747887

Students also viewed these Databases questions

Question

5. Convert the hexadecimal number (AC12), to binary

Answered: 1 week ago

Question

What are the basic financial decisions ?

Answered: 1 week ago

Question

What is meant by 'Wealth Maximization ' ?

Answered: 1 week ago

Question

3. Identify the methods used within each of the three approaches.

Answered: 1 week ago