Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need Help with this JAVA MAZE RUNNER PROJECT.. Can you please help me with the c

ID: 3588973 • Letter: N

Question

Need Help with this JAVA MAZE RUNNER PROJECT.. Can you please help me with the code and also add comments so I understand the situation.. A sample output is also attached so that you can check your code.

You are working for a software company to develop a new game that involves characters exploring a world. The world is represented as a two dimensional array. In each cell of the array, a monster capable of a certain amount of damage (represented as an integer value) is present. A player starts out in some cell of the two-dimensional array and progresses to the next level by reaching any cell on the edge of the array. On each turn, a player can move north, south, east or west (but not diagonally).

Your task for this project is to write a basic AI character for this game, as follows:

Your program should begin by prompting for the number of rows and columns in the world, and the danger level of each cell in the world.

The program should then prompt for the starting x and y coordinate (i.e. row and column) of the AI character.

On each turn, your program should display the state of the world (i.e. the two dimensional array) with the AI character’s location marked with an *.

The AI should decide which way to move simply by looking at the cells to the north, south, east and west and moving towards the one with the smallest amount of danger.

The AI character should not return to a cell that it has already visited. Hint: This can be done using a String variable. Every time the character is in a new position, add this position to the string variable. That way, you can use the String contains method to check if a position has already been visited.

When the character reaches the edge of the world, the program should stop, and display the place the character exited the world and the total amount of danger the character faced on its way through the world. Don’t forget to include the danger faced in the character’s starting location.

Your project will be graded based on the above requirements (each requirement is worth one point).

Output- Sample (to check if the code is correct or not

How many rows are in the maze? 5
How many columns are in the maze? 7
Enter the danger in row 0, separated by spaces: 0 1 4 2 6 0 1

Enter the danger in row 1, separated by spaces: 1 7 4 2 2 6 0

Enter the danger in row 2, separated by spaces: 0 0 0 8 1 4 1

Enter the danger in row 3, separated by spaces: 1 1 2 7 3 4 2

Enter the danger in row 4, separated by spaces: 5 1 6 4 2 2 1

Enter the starting x coordinate: 2

Enter the starting y coordinate: 4

0142601
1742260

0008*41

1127342

5164221

Moving to 1,4 (danger level 2)

0142601

1742*60

0008141

1127342

5164221

Moving to 1,3 (danger level 2)

0142601

174*260

0008141

1127342

5164221

Moving to 0,3 (danger level 2)

014*601

1742260

0008141

1127342

5164221
Exited the world at 0,3 Total danger faced: 7

Explanation / Answer

package java_maze_runner;

import java.util.Scanner;

/**
*
* @author pc
*/
public class JAVA_MAZE_Runner {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//Taking Input........................
Scanner sc=new Scanner(System.in);
int danger[][];
System.out.println("How Many rows are in the Maze? :");
int row=sc.nextInt();
System.out.println("How Many columns are in the Maze? :");
int column=sc.nextInt();
danger=new int[row][column]; // Creating An Array Danger of size row*column..
//Take input for Danger Array..
for(int i=0;i<row;i++)
{
System.out.println("Enter the danger in row "+i+", separeted by spaces: ");
for(int j=0;j<column ;j++)
{
danger[i][j]=sc.nextInt();
}
}
  
//Starting X and Starting Y coordinate input..
System.out.println("Enter The Starting x coordinate ");
int x_now=sc.nextInt();
System.out.println("Enter The Starting y coordinate ");
int y_now=sc.nextInt();

//Processing Input........................
String st=new String("");//Creating string to store all location we visited so we dont visit it again..
int total_danger=danger[x_now][y_now]; //initally
st=x_now+""+y_now; // string is in the form (x1y1 x2y2 x3y3....) initially st=x_nowy_now..
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
if(x_now==i && y_now==j)
System.out.print("*");// we print asterisk at current position..
else
System.out.print(danger[i][j]); // at other places just print value of dander at that location..
}
System.out.println();
}
  
while(x_now!=0 || y_now!=0 || x_now!=row-1 || y_now!=column-1) //Iterate loop until it reaches edge of the world..
{
int arrayx[]=new int[4];//Creating two arrays to store x and y (unvisited) coordinate north east south and west ..
int arrayy[]=new int[4];
int index=-1;//manege index value according to no. of coordinates which are still unvisited..
if(!st.contains(x_now+""+(y_now-1)))
{
++index;
arrayx[index]=x_now;
arrayy[index]=y_now-1;
}
if(!st.contains(x_now+""+(y_now+1)))
{
++index;
arrayx[index]=x_now;
arrayy[index]=y_now+1;
}
if(!st.contains((x_now-1)+""+y_now))
{
++index;
arrayx[index]=x_now-1;
arrayy[index]=y_now;
}
if(!st.contains((x_now+1)+""+y_now))
{
++index;
arrayx[index]=x_now+1;
arrayy[index]=y_now;
}int min_danger=9999;
for(int i=0;i<=index;i++)// find minimum for each unvisited coordinate..
{
if(min_danger>danger[arrayx[i]][arrayy[i]])
{
min_danger=danger[arrayx[i]][arrayy[i]];
x_now=arrayx[i];// if it is minimum then update x_now and y_now
y_now=arrayy[i];
}
  
}
st=" "+x_now+""+y_now;// update visited coordinates inside string value
total_danger+=min_danger;// update total danger
//Output
System.out.println("Moving to "+x_now+","+y_now+"("+danger[x_now][y_now]+")");
for(int i=0;i<row;i++)
{
for(int j=0;j<column;j++)
{
if(x_now==i && y_now==j)
System.out.print("*");// we print asterisk at current position..
else
System.out.print(danger[i][j]); // at other places just print value of dander at that location..
}
System.out.println();
}
}
System.out.println("Exited the world at "+x_now+","+y_now+" Total Danger Faced :"+total_danger);
}
  
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote