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);
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306