A.I practice

Run Settings
LanguageJava
Language Version
Run Command
import java.util.*; import java.io.*; class Main { public static void main(String[] args) { // 2D array for the world //temporary 2D array to store the movements //buildWorld(); printWorld(); } public static String[][] buildWorld(){ String [][] world = new String[8][10]; //store row/column values in the world[][] array try{ File f = new File("robotdata.txt"); Scanner s = new Scanner(f); for(int row=0; row<world.length; row++){ for(int col=0; col<world[0].length; col++){ world[row][col]=s.next(); } } } catch(FileNotFoundException f){ System.out.println("No Files Exist!"); }catch(NoSuchElementException e){ System.out.println("No Elements Exist!"); } return world; } public static void printWorld(){ String[][] World = buildWorld(); String[][] robotPos = new String [World.length][World[0].length]; int x =0; int y =0; int c =0; System.out.println("==========PRINTING WORLD=========="); try{ for(int row=0; row<World.length; row++){ for(int col=0; col<World[0].length; col++){ if(World[row][col].equals("A") || World[row][col].equals("B")){ System.out.print("[" + World[row][col]+"]");//highlight robot pos robotPos[row][col] = World[row][col]; x =row+1; y =col+1; System.out.print(" Robot position is: Row "+ (x)+" Column "+(y)); }else if(World[row][col].equals("X")){ c++; if(World[row][col-1].equals("X")){ System.out.print(" X "); }else if(World[row][col+1].equals("X")){ System.out.print(" X "); }else{ System.out.print(" X "); } }else{ System.out.print(" "); } } System.out.println(); } System.out.println("Moves: "+c); } catch(ArrayIndexOutOfBoundsException a){ System.out.println("\ncomplete."); } } }
O O O O O O O A O O O O O O O O X X O O O O O O O O X O O O O O O X X X X O O O O O O X O O O O O O O O O X X X X O O O O O O O O O X X X O O O O O O O O B O O
Editor Settings
Theme
Key bindings
Full width
Lines