void SearchAll(string &word, string &occupy, int row, int col) { int pos = row * size + col; occupy[pos] = OCCUPY; path.push_back(SPoint(row, col)); word += tolower(board[pos]); if(!english.containsPrefix(word)) { word = word.substr(0, word.size() - 1); occupy[pos] = EMPTY; path.pop_back(); return; } if(word.size() >= 4 && InEnglish(word) && !InHumanWord(word)) { recordWordForPlayer(word, COMPUTER); humanword.push_back(word); showpath(); } //cout << word << ' ' << row << ' ' << col << endl; //Up if(row != 0 && occupy[pos - size] == EMPTY) SearchAll(word, occupy, row - 1, col); //Down if(row != size - 1 && occupy[pos + size] == EMPTY) SearchAll(word, occupy, row + 1, col); //Right if(col != size - 1 && occupy[pos + 1] == EMPTY) SearchAll(word, occupy, row, col + 1); //Left if(col != 0 && occupy[pos - 1] == EMPTY) SearchAll(word, occupy, row, col - 1); //UpRight if(row != 0 && col != size - 1 && occupy[pos - size + 1] == EMPTY) SearchAll(word, occupy, row - 1, col + 1); //UpLeft if(row != 0 && col != 0 && occupy[pos - size - 1] == EMPTY) SearchAll(word, occupy, row - 1, col - 1); //DownLeft if(row != size - 1 && col != 0 && occupy[pos + size - 1] == EMPTY) SearchAll(word, occupy, row + 1, col - 1); //DownRight if(row != size - 1 && col != size - 1 && occupy[pos + size + 1] == EMPTY) SearchAll(word, occupy, row + 1, col + 1); word = word.substr(0, word.size() - 1); path.pop_back(); occupy[pos] = EMPTY; }
bool RInBoard(const string &word, string &occupy, int row, int col, int index) { //cout << word << ' ' << row << ' ' << col << ' ' << index << endl; int pos = row * size + col; occupy[pos] = OCCUPY; path.push_back(SPoint(row, col)); if(tolower(word[index]) != tolower(board[pos])) { //cout << word[index] << ' ' << board[pos] << endl; occupy[pos] = EMPTY; path.pop_back(); return false; } //cout << word << endl; if(index == word.size() - 1) { showpath(); return true; } //Up if(row != 0 && occupy[pos - size] == EMPTY) { bool res = RInBoard(word, occupy, row - 1, col, index + 1); if(res) return true; } //Down if(row != size - 1 && occupy[pos + size] == EMPTY) { bool res = RInBoard(word, occupy, row + 1, col, index + 1); if(res) return true; } //Left if(col != 0 && occupy[pos - 1] == EMPTY) { bool res = RInBoard(word, occupy, row, col - 1, index + 1); if(res) return true; } //Right if(col != size - 1 && occupy[pos + 1] == EMPTY) { bool res = RInBoard(word, occupy, row, col + 1, index + 1); if(res) return true; } //UpRight if(row != 0 && col != size - 1 && occupy[pos - size + 1] == EMPTY) { bool res = RInBoard(word, occupy, row - 1, col + 1, index + 1); if(res) return true; } //UpLeft if(row != 0 && col != 0 && occupy[pos - size - 1] == EMPTY) { bool res = RInBoard(word, occupy, row - 1, col - 1, index + 1); if(res) return true; } //DownLeft if(row != size - 1 && col != 0 && occupy[pos + size - 1] == EMPTY) { bool res = RInBoard(word, occupy, row + 1, col - 1, index + 1); if(res) return true; } //DownRight if(row != size - 1 && col != size - 1 && occupy[pos + size + 1] == EMPTY) { bool res = RInBoard(word, occupy, row + 1, col + 1, index + 1); if(res) return true; } occupy[pos] = EMPTY; path.pop_back(); return false; }