java - Navigating a .txt file with a two dimensional array -


for assignment read .txt file , recursively navigate maze produces(i'll provide example below) navigate , print it. have navigation down , partner making print method. however, having problems determining start position of maze. in maze start signified s. it's easier explain picture i'll provide now

5     ##### #s.## ##..# ###.# #g..# 

the number @ top determines size of array(we have make them square). '#' wall, '.' available path, , 'g' goal. right problem is, finding coordinate of s know start maze at. below file chooser class(where problem is) , class navigate maze(it works thought i'd include in case curious

public static void main(string[] args)     throws filenotfoundexception, ioexception     {         filereader myreader;         jfilechooser chooser = new jfilechooser();         if(chooser.showopendialog(null) == jfilechooser.approve_option)         {             file myfile = chooser.getselectedfile();             myreader = new filereader(myfile);                scanner myscanner = new scanner(myreader);             string placeholder = myscanner.nextline();             int arraythings = integer.parseint(placeholder);             char[][] maze = new char[arraythings][arraythings];             int rows = 0;             int collumns = 0;             for(int = 0; < maze.length(); i++)             {                 if (maze[rows][collumns] == 's' || maze[rows][collumns] =='s')                 {                     findpath(maze[arraythings][arraythings],rows,collumns);                 }                                 }                            myreader.close();         }                } 

i'm not entirely sure how navigate maze find 's'. , here findpath method

public static boolean findpath(char[][] maze,int x,int y)     {         try         {             if (maze[x][y] == 'g' || maze[x][y] =='g')             {                 system.out.println("the maze printed");  //replace print method                 return true;             }             else if (maze[x][y] == '#' || maze[x][y] == '?' || maze[x][y] == 'p')                 return false;             else              {                 maze[x][y] = 'p';                 system.out.println("the maze printed"); //replace print method                 if(mazesolver.findpath(maze,x,y-1)== true)                     return true;                 else if(mazesolver.findpath(maze,x+1,y)== true)                     return true;                 else if(mazesolver.findpath(maze,x,y+1)== true)                     return true;                 else if(mazesolver.findpath(maze,x-1,y)== true)                     return true;                 maze[x][y] = '?';                 return false;             }         }          catch (arrayindexoutofboundsexception myex)         {             return false;         }             } 

you need initialize maze before :

for(int row = 0; row < maze.length; row++)      {          for(int col = 0; col < maze[0].length;col++){              if(maze[row][col] == 's'){                  system.out.println("x :" + row + " y : " + col);              }          }      }    

it's not looking for?


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -