So I am working on this 8 puzzle game and I need to set an initial state. So lets say I am given the input "1b2 345 678" and I want to do various search methods and move pieces around (in particular the b (blank) piece). So I want to represent that given input in a matrix like: 1 b 2 3 4 5 6 7 8
So I wrote the following code:
public class EightPuzzle {
String[][] gameBoard = new String[3][3];
String bLocation;
String board;
/*public void ReadFromTxt(String file) throws FileNotFoundException, IOException {
String read;
FileReader f = new FileReader(file);
int i = 0;
int j;
BufferedReader b = new BufferedReader(f);
System.out.println("Loading puzzle from file...");
while((read = b.readLine())!=null){
if(read.length()==3){
for(j=0;j<3;j++){
board[i][j] = (int)(read.charAt(j)-48);
}
}
i++;
}
b.close();
System.out.println("Puzzle loaded!");
}*/
public String[][] setState(String board){
gameBoard[0][0] = board.substring(0,1);
gameBoard[0][1] = board.substring(1,2);
gameBoard[0][2] = board.substring(2,3);
gameBoard[1][0] = board.substring(4,5);
gameBoard[1][1] = board.substring(5,6);
gameBoard[1][2] = board.substring(6,7);
gameBoard[2][0] = board.substring(8,9);
gameBoard[2][1] = board.substring(9,10);
gameBoard[2][2] = board.substring(10,11);
System.out.println(gameBoard);
return gameBoard;
}
public static void main (String[]args){
EightPuzzle b1=new EightPuzzle();
b1.setState("b12 345 678");
}
}
But when I run it, it just displays that my gameBoard is stored as: [[Ljava.lang.String;@15db9742 What am I doing wrong?