title: Java Maze shortest path 2d int array
body: <p>I am currently stuck on a project.
  My aim is to use Dijkstra's algorithm.</p>
  
  <p>I understand that I start at point (0,0) I look at the two nodes next to the start point and then I move to the smallest first and look at the surrounding nodes. My maze is random but to make it easy to start lets say the following is my maze.</p>
  
  <p>I will start at (0,0) and want to end at (9,9) the numbers are the DANGER level and we aim for the safest path not really the shortest.</p>
  
  <p>I need a push to understand how to set this up.
   I know I need a list or a path to keep where I am and where I want to look. but I don't know how to do that in java.</p>
  
  <pre><code>import java.awt.Point;
  import java.util.ArrayList;
  import java.util.LinkedList;
  import java.util.List;
  
  
  public class solver {
  
      /**
       * @param args
       */
      public static int[][]maze;
      public static int[][]openlist;
      public static int[][]closed;
      public static int[][]copy;
      public static int danger;
      public static int size=100;
      static int Max=9;
      static int Min=0;
      public static List path = new ArrayList();
      public static void main(String[] args) {
          // TODO Auto-generated method stub
          maze = new int[size][size];
          openlist = new int[size][size];
          closed = new int[size][size];
          copy = new int[size][size];
          filler(maze);
          copy=dijstkra();
          printer(maze);
          //printer(copy);
          EDSfAO(maze,0,0);
          printer(openlist);
          printer(copy);
      }
      private static Boolean notwall(int i, int j){
  
          if((i&gt;maze.length-1)||(j&gt;maze.length-1)||(i&lt;0)||(j&lt;0))
          {return false;}
  
          return true;}
      private static int[][] dijstkra(){
  
  
          for(int i=0;i&lt;maze.length;i++){
              for(int j=0;j&lt;maze.length;j++){
                  copy[i][j]=100000000;
              }}
          copy[0][0]=0;
          return copy;
          }
  
      private static void EDSfAO(int[][] maze,int i,int j){
          int min=100000000;
          int holdx = 0;  
          int holdy = 0;
          openlist[i][j]=1;
          danger=copy[i][j];
          if(i==maze.length-1&amp;&amp;j==maze.length-1){
  
              printer(copy);
              for(holdx=0;holdx&lt;path.size();holdx++){
  
                  System.out.print(path.get(holdx));
  
              }
  
  
          }
          else{
          if(notwall(i+1,j)&amp;&amp;openlist[i+1][j]!=1){
              copy[i+1][j]=danger+maze[i+1][j];
          } if(notwall(i,j+1)&amp;&amp;openlist[i][j+1]!=1){
              copy[i][j+1]=danger+maze[i][j+1];
          } if(notwall(i,j-1)&amp;&amp;openlist[i][j-1]!=1){
              copy[i][j-1]=danger+maze[i][j-1];
          } if(notwall(i-1,j)&amp;&amp;openlist[i-1][j]!=1){
              copy[i-1][j]=danger+maze[i-1][j];
          }
          for(int x=0;x&lt;maze.length;x++){
              for(int y=0;y&lt;maze.length;y++){
  
              if(openlist[x][y]!=1){
  
                  if(min&gt;copy[x][y]){
                  min=copy[x][y];
                  holdx=x;    
                  holdy=y;
                  }
  
              }
  
  
          }}
          moveToPosition(holdx,holdy);
          }
      }
  
  
      private static void moveToPosition(int x, int y) {
  
              openlist[x][y]=1;
              path.add("("+x+","+y+")");
              openlist[x][y]=1;
              EDSfAO(maze,x,y);
      }
  
  private static void printer(int[][] maze) {
          // TODO Auto-generated method stub
      for(int i=0;i&lt;maze.length;i++){
          for(int j=0;j&lt;maze.length;j++){
          System.out.print("["+maze[i][j]+"]");                       
          }
          System.out.println();
          }
  
      }
  
  public static void filler(int[][] maze){
  
          for(int i=0;i&lt;maze.length;i++){
  
              for(int j=0;j&lt;maze.length;j++){
              //If i=0 AND j=0 then maze[0][0]= 0(start) OR i= maze.length-1 AND j= maze.length-1 then maze[maze.length][maze.length]=0
              if((i==0 &amp;&amp; j==0) || (i==maze.length-1 &amp;&amp; j==maze.length-1)){
  
                  maze[i][j]=0;   
  
              }else{
                  maze[i][j]=Min + (int)(Math.random() * ((Max - Min) + 1));
              }
              }
              }
      }
  }
  </code></pre>
  
  <p>The maze is connected with no walls all the boxes are rooms.
   I have been trying to work on this for time and I could really use a push.
  I have watched a lot of videos about dijstkra's algorithm I am just currently really lost.</p>
  
  <p>I added a array that i keep the danger in it starts by making ever node 100000000 but the starting node (0,0) is 0. </p>
  
  <p>CAN someone help me with the next steps I understand it's homework but I am running out of time and really need some pointers.</p>
  
  <p>UPDATE:</p>
  
  <p>OK so I have it workingish. It prints the path it takes but if it finds a better path it prints both can someone help me fix this.</p>
  
  <p>Also it breaks if i do 100X100 element can someone tell me why?
  This is the last of the real "programming assignments". As you may expect, this will involve graphs (with a twist); but of course, there will be some problem solving involved as well.
  Instruction</p>
  
  <hr>
  
  <p>Imagine a “dungeon game” where all the rooms are laid out in a perfect grid with in a square environment. Each room has a creature posing some degree of danger ranging from 0 (harmless) to 9 (avoidance would be prudent). The object is to find a path through the dungeon from start to end which minimizes the overall amount of danger.</p>
  
  <p>Each room, unless at boundary, only has exists in the up, down, left, right directions (no diagonals). The entrance is at the upper-left (0,0) and the exit is at the lower right (n-1, n-1).</p>
  
  <p>List all of the “rooms” which must be traversed, in the form of a path of room coordinates, from the start to finish.</p>
  
  <p>For example:</p>
  
  <p>(0,0)
  (1,0)
  (2,0)
  (2,1)
  (2,2)
  (2,3)
  (3,3)
  (4,3)
  (4,4)</p>
  
  <p>Total danger = 11
  Input</p>
  
  <p>The input file will consist of 100 rows of 100 digits, 0-9.  (Yes, 10,000 is be a lot of rooms, but luckily, our intrepid traveler never leaves home without a portable computer and a collection of Electronic Data-Sets for All Occasions received in last year's holiday gift exchange; it was probably re-gifted.)*</p>
  
  <p>*For this assignment, you'll have to generate your own test data. This is why I don't go to these kinds of parties...
  Output</p>
  
  <p>The program should write the output to a file (in the format illustrated above, including the "total danger" output).
  Thanks.</p>
  
  <p>UPDATE2: i found an error in my coding I have </p>
  
  <pre><code>if(min&gt;copy[x][y]){
                  min=copy[x][y];
                  holdx=x;    
                  holdy=y;
                  }
  </code></pre>
  
  <p>This will make it test every path that is there at a given point my shortest path is bigger then the other path how do I fix this?</p>
  
  <p>What I am I missing?
  UPDATE I finished this thanks for the VERY LITTLE help.</p>