I have to create a maze in which a robot has to follow the set of directions given and I'm so stuck on how to make the robot go through the maze. I have most all of it done but I'm still getting errors. The maze includes 1.safe place 2.chasm 3.trap 4. destination. The robot can 1. move forward once 2. jump 3. Turn left 4. Turn right
Here's what I have so far.Please help!
import java.util.Scanner;
public class GameMachine
{
public static void main (String args [])
{
int robot_x = 0;
int robot_y = 0;
int robot_m_x = 0;
int robot_m_y = 0;
int[] robot_instructions = new int[64];
int i = 0;
int robot_state = 0;
int[][] maze = new int[8][8];
robot_instructions[0] = 1;
maze[4][5] = 2;
maze[6][7] = 3;
maze[1][1] = 1;
maze[8][8] = 4;
maze[3][2] = 3;
maze[4][1] = 2;
robot_x = 1;
robot_y = 1;
for(i = 0; i < 64; i++)
{
robot_state = 1;
switch(robot_instructions[i])
{
case 1:robot_x = robot_m_x;
robot_y = robot_m_y + 1;
break;
case 2:robot_x = robot_m_x;
robot_y = robot_m_y + 2 ;
break;
case 3:
robot_x = robot_m_x - 1;
break;
case 4:
robot_x = robot_m_x + 1;
break;
}
System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
System.out.println ("Robot State: ");
switch( maze[(robot_y*10) + robot_x])
{
case 1:robot_state = 1;
System.out.println ( "Robot is at a safe place");
break;
case 2:robot_state = 2;
System.out.println ("Robot falls into Chasm");
break;
case 3:robot_state = 3;
System.out.println("Robot falls into the trap");
break;
case 4:robot_state = 4;
System.out.println( "Robot reaches Destination");
break;
case 5:robot_state = 5;
System.out.println ( "Robot fails to reach Destination");
break;
}
}
}