这是 Boggle Board 的 C 作业。
任务是在一个 4x4 的字符板上搜索字典中的单词,方法是从一个图块开始并在任意点向上、向下、向左、向右或对角移动。我的程序从一个点“跳”到另一个点,从不相邻的字母拼写单词,并多次添加单词。
void goToNextLetter(struct trie* dictionary, char boggleBoard[SIDELENGTH][SIDELENGTH], int usedLetters[SIDELENGTH][SIDELENGTH], char word[MAX], int row, int column){
int i, rowTemp, colTemp;
if (isPrefix(dictionary, word, 0)){
if (isInDictionary(dictionary, word, 0)){
printf("%s\n", word);
}
word[strlen(word)]=boggleBoard[row][column];
usedLetters[row][column]=1;
//printf("%d\t%d\t%s\n", row, column, word);
for (i=0; i<D_SIZE; i++){
rowTemp=row+DY[i];
colTemp=column+DX[i];
if ((rowTemp<SIDELENGTH) && (rowTemp>=0) && (colTemp>=0) && (colTemp<SIDELENGTH) && (usedLetters[rowTemp][colTemp]==0)){
goToNextLetter(dictionary, boggleBoard, usedLetters, word, rowTemp, colTemp);
}
}
//remove the last letter of word
word[strlen(word)-1] = 0;
usedLetters[row][column]=0;
}
}