about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorvamsee <vamsee.somasi@gmail.com>2021-11-19 17:00:39 +0530
committervamsee <vamsee.somasi@gmail.com>2021-11-19 17:00:39 +0530
commitae3b3ca0ca9fd3b8ec0aa5da84dc2276b398bbfd (patch)
tree24d79fae9dedcd9076800406328958ff8d5e8c16
parent80c7c780cd74504673a131220c5ab312c806498b (diff)
downloadfornax-ae3b3ca0ca9fd3b8ec0aa5da84dc2276b398bbfd.tar.gz
java/BFS: Print according to fornax format
-rw-r--r--algorithms/java/BFS.java31
1 files changed, 20 insertions, 11 deletions
diff --git a/algorithms/java/BFS.java b/algorithms/java/BFS.java
index a6f368a..d31d941 100644
--- a/algorithms/java/BFS.java
+++ b/algorithms/java/BFS.java
@@ -62,9 +62,6 @@ class BFS {
             System.out.println();
             if (maze[curx][cury] == '$') {
                 path[curx][cury]=new Coordinates(start.x,start.y);
-
-                System.out.println("Path found");
-                
                 boolean[][] printpath=new boolean[maze.length][maze.length];
                 for (int q = 0; q < maze.length; q++) {
                     for (int j = 0; j < maze.length; j++) {
@@ -80,16 +77,28 @@ class BFS {
 
                                    //path stores parent of current coordinate
                 }  
-                for(int d=0;d<maze.length;d++){
-                    for(int e=0;e<maze.length;e++){
-                        System.out.print(printpath[d][e]);                  //print path
+                for(int j = 0; j < maze.length; j++)
+                for(int k = 0; k < maze[j].length; k++) {
+                    if (maze[j][k] == '^' || maze[j][k] == '$')
+                        System.out.print(maze[j][k]);
+                    else {
+                        if (j == curx && k == cury)
+                            System.out.print("@");
+                        else {
+                            if(printpath[j][k])
+                            System.out.print("~");
+                        else if (visited[j][k])
+                                System.out.print("-");
+                            else
+                                System.out.print(maze[j][k]);
+                        }
                     }
-                    System.out.println();
                 }
+            System.out.println();
                 System.exit(0);
             } else if (visited[curx][cury] || maze[curx][cury] == '#') {
                 continue;
-            } else if(maze[curx][cury]=='_') {
+            } else if(maze[curx][cury]=='.') {
                 enqueue(new Coordinates(curx, cury));
                 visited[curx][cury] = true;
                 path[curx][cury]=new Coordinates(start.x,start.y);
@@ -108,9 +117,9 @@ class BFS {
 
     public static void main(String[] args) {
         char[][] maze = {
-            {'*', '#', '_'},
-            {'_', '_', '#'},
-            {'_', '_', '$'},
+            {'^', '#', '.'},
+            {'.', '.', '#'},
+            {'.', '.', '$'},
         };
 
         Coordinates start = new Coordinates(0,0);