#include
#include
#include
#define ROW 3
#define COLUMN 3
#define DICTIONARYSIZE 2
struct BOGGLE{
char *dictionary[DICTIONARYSIZE];
char boggle[3][3];
};
struct BOGGLE boggle2 = {
.dictionary = {"GEEKS", "FOR", "QUIZ", "GO"},
.boggle = { {'G', 'I', 'Z'},
{'U', 'E', 'K'},
{'Q', 'S', 'E'}}
};
struct BOGGLE boggle1 = {
.dictionary = {"GEEKS", "ABCFIHGDE"},
.boggle = { {'A', 'B', 'C'},
{'D', 'E', 'F'},
{'G', 'H', 'I'}}
};
bool findWay(char *input, int row ,int col){
char c = *(++input);
if(c == '\0')
return true;
if(col < 2 && c == boggle1.boggle[row][col + 1])
if(findWay(input , row, col + 1))
return true;
if(col > 0 && c == boggle1.boggle[row][col - 1])
if(findWay(input , row, col - 1))
return true;
if(row < 2 && c == boggle1.boggle[row + 1][col])
if(findWay(input , row + 1, col))
return true;
if(row > 0 && c == boggle1.boggle[row - 1][col])
if(findWay(input , row - 1, col))
return true;
if(row < 2 && col < 2){
if(boggle1.boggle[row + 1][col + 1] == c)
if(findWay(input , row + 1, col + 1))
return true;
}
if(row > 0 && col > 0){
if(boggle1.boggle[row - 1][col - 1] == c)
if(findWay(input , row - 1, col - 1))
return true;
}
if(row > 0 && col < 2){
if(boggle1.boggle[row - 1][col + 1] == c)
if(findWay(input , row - 1, col + 1))
return true;
}
if(col > 0 && row < 2){
if(boggle1.boggle[row + 1][col - 1] == c)
if(findWay(input , row + 1, col - 1))
return true;
}
return false;
};
bool findStart(char *input, int *row, int *col){
for(*row = 0; *row < ROW; (*row)++){
for(*col = 0; *col < COLUMN; (*col)++)
if(boggle1.boggle[*row][*col] == *input)
return false;
}
return true;
}
void solveBoggle(){
for(int i = 0; i < DICTIONARYSIZE; i++){
char *input = boggle1.dictionary[i];
char *input_ = boggle1.dictionary[i];
int row_, col_, *row, *col;
row_ = col_ = 0;
row = &row_;
col = &col_;
if(findStart(input, row, col))
continue ;
row_ = *row;
col_ = *col;
if(findWay(input, row_, col_))
printf("%s\n", boggle1.dictionary[i]);
}
}
int main(){
solveBoggle();
return 0;
}