Ok so im going to show you all of my code... embarrassing as it may be. I know its not written very well, but im a novice so i guess whatever.
import java.io.*;
import java.util.*;
public class Boggle {
public static void main(String[] args){
new Boggle();
}
public Boggle(){
ArrayList<ArrayList<Character>> dice = new ArrayList<ArrayList<Character>>();
// import the cubes
importCubes(dice);
/* THIS CHECKS IF EVERYTHING IS IMPORTED CORRECTLY
for(int d = 0; d<dice.size(); d++){
for(int l = 0; l<dice.get(d).size(); l++){
System.out.print(dice.get(d).get(l) + "\t");
}
System.out.println();
}
*/
// import dictionary
// roll the dice
Character[][] letterBoard = roll(dice);
for(int d = 0; d<letterBoard.length; d++){
for(int l = 0; l<letterBoard[d].length; l++){
System.out.print(letterBoard[d][l] + "\t");
}
System.out.println();
}
// find all the possible words
// cross check against dictionary
}
public void importCubes(ArrayList x){
Scanner in = null;
try {
in = new Scanner(new File("Dice.txt"));
}
catch (IOException i)
{
System.out.println("Error: " + i.getMessage());
}
for(int i = 0; i<16; i++){
ArrayList<Character> die = new ArrayList<Character>();
for (int j = 0; j < 6; j++){
die.add(in.next());
}
x.add(die);
}
}
// So the method roll with go through all the 16 spots on the 4x4 grid and pick a random
// 6 sided dice and put it in that spot, then "roll" it by picking at random one of it's sides and
// putting that into Character[][] board.
public Character[][] roll(ArrayList x){
Random rand = new Random();
int[] availability = {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1};
Character[][] board = null;
for(int r = 0;r<4;r++){
for(int c = 0;c<4;c++){
for(int tries=0;tries<10000;tries++){
int d = rand.nextInt(16);
if(availability[d]!=0){
int l = rand.nextInt(6);
board[r][c] = x.get(d).get(l); // At this line, it underlined the second "get" in
availability[d] = 0; // red and it suggests to add cast to 'x.get(d)'
break;
}
}
}
}
return board;
}
}
I am trying to make a Boggle simulator that will be able to randomize(shake) the letters on the 4x4 grid and then find all the words that can be made. I am sure there are MANY things you could fix in this code to be more optimized, but i would like to figure it mostly for myself. Could you please help figure out what is broken?