0
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;
}
4

0 回答 0