while(!paths.isEmpty()){
BoggleSearchState2 path = paths.pop();
if(dictionary.contains(path.getWord()) && !foundWords.contains(path.getWord())){
foundWords.add(path.getWord());
}
int[][] grid = path.getGrid();
int row = path.getRow();
int column = path.getColumn();
Letter[][] game = path.getGame();
if(row < (grid.length-1) && grid[row+1][column] == 0) {
paths.push(new BoggleSearchState2(path.getWordWord(), game[(row+1)][column], game));
}
}
我的BoggleSearchState2构造函数重载如下:
public BoggleSearchState2(Letter l, Letter[][] gameIn) {
game = gameIn;
word = new Word(l);
grid = initialGrid(l);
row = l.getPoint().y;
column = l.getPoint().x;
stringWord = wordToString(word);
}
public BoggleSearchState2(Word wordIn, Letter l, Letter[][] gameIn){
game = gameIn;
word = new Word(wordIn.getLetters());
word.addLetter(l);
grid = genGrid(word, game);
row = l.getPoint().y;
column = l.getPoint().x;
stringWord = wordToString(word);
}
使用我的类变量:
public class BoggleSearchState2 {
private Word word;
private Letter[][] game;
private int[][] grid;
private String stringWord;
private int row, column;
我遇到的问题是,在推动新的BoggleSS2后,我的path.word会更改并添加另一个字母对象。我不知道这是怎么回事。谁能告诉我为什么?
public class Word {
private ArrayList<Letter> word;
public Word(Letter l) {
word = new ArrayList<Letter>();
word.add(l);
}
public Word(ArrayList<Letter> listLetters, Letter l){
word = listLetters;
word.add(l);
}
public Word(ArrayList<Letter> letters) {
word = letters;
}