private void FindAllWords(StringBuilder curword, int i, int j) { curword.Append(LetterGrid[i, j].ASCIIChar); if (curword.Length < 15) { if (curword.Length >= 3) { if (EngLetterScoring.IsWord(curword)) { Word w = new Word(CurWordList); if (!WordsFromLetter.Contains(w)) { WordsFromLetter.Add(w); } } } if (EngLetterScoring.PartialExists(curword.ToString())) { if (i > 0) { if (j > 0) { FindAllWords(curword, i - 1, j - 1); } FindAllWords(curword, i - 1, j); if (j < WSGameState.gridsize - 1) { FindAllWords(curword, i - 1, j + 1); } } if (j > 0) { FindAllWords(curword, i, j - 1); } if (j < WSGameState.gridsize - 1) { FindAllWords(curword, i, j + 1); } if (i < WSGameState.gridsize - 1) { if (j > 0) { FindAllWords(curword, i + 1, j - 1); } FindAllWords(curword, i + 1, j); if (j < WSGameState.gridsize - 1) { FindAllWords(curword, i + 1, j + 1); } } } } curword.Remove(curword.Length - 1, 1); // one by one add each letter. If there is no match, then stop that branch }
private void FindAllWords(int i, int j, LetterProp lp) { if (CurrentWordFind.Exists(key => (key.i == i && key.j == j))) { return; } CurrentWordFind.Add(new WordElement(i, j, LetterGrid[i, j].letter)); CurWordList.Add(LetterGrid[i, j]); if (CurrentWordFind.Count < 20) { string _curword = CurrentWordString(); if (CurrentWordFind.Count >= 3) { if (EngLetterScoring.IsWord(_curword) && CurrentWordFind.Exists(key => key.i == lp.I && key.j == lp.J)) { Word w = new Word(CurWordList); if (!WordsFromLetter.Contains(w)) { WordsFromLetter.Add(w); } } } if (EngLetterScoring.PartialExists(_curword)) { if (i > 0) { if (j > 0) { FindAllWords(i - 1, j - 1, lp); } FindAllWords(i - 1, j, lp); if (j < WSGameState.gridsize - 1) { FindAllWords(i - 1, j + 1, lp); } } if (j > 0) { FindAllWords(i, j - 1, lp); } if (j < WSGameState.gridsize - 1) { FindAllWords(i, j + 1, lp); } if (i < WSGameState.gridsize - 1) { if (j > 0) { FindAllWords(i + 1, j - 1, lp); } FindAllWords(i + 1, j, lp); if (j < WSGameState.gridsize - 1) { FindAllWords(i + 1, j + 1, lp); } } } } CurrentWordFind.RemoveAt(CurrentWordFind.Count - 1); CurWordList.RemoveAt(CurWordList.Count - 1); }
public bool FindAnyWord(int i, int j) { bool ret = false; if (LetterGridUsed[i, j]) { return(false); } LetterGridUsed[i, j] = true; curword[curwordoff++] = LetterGridByte[i, j]; //Debug.WriteLine(i.ToString() + " " + j.ToString() + " " + CurrentWordString()); if (curwordoff <= 15) { string _curword = new string(curword, 0, curwordoff); if (EngLetterScoring.PartialExists(_curword)) { if (curwordoff >= 3) { if (EngLetterScoring.IsWord(_curword)) { ret = true; } } if (i > 0) { if (j > 0) { if (!ret && FindAnyWord(i - 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i - 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i - 1, j + 1)) { ret = true; } } } if (j > 0) { if (!ret && FindAnyWord(i, j - 1)) { ret = true; } } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i, j + 1)) { ret = true; } } if (i < WSGameState.gridsize - 1) { if (j > 0) { if (!ret && FindAnyWord(i + 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i + 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i + 1, j + 1)) { ret = true; } } } } } curword[curwordoff] = '\0'; curwordoff--; LetterGridUsed[i, j] = false; return(ret); }
// a z // t z public bool FindAnyWord2(int i, int j) { bool ret = false; if (CurrentWordFind.Exists(key => (key.i == i && key.j == j))) { return(false); } CurrentWordFind.Add(new WordElement(i, j, LetterGrid[i, j].letter)); //Debug.WriteLine(i.ToString() + " " + j.ToString() + " " + CurrentWordString()); if (CurrentWordFind.Count < 15) { string curword = CurrentWordString(); if (EngLetterScoring.PartialExists(curword)) { if (CurrentWordFind.Count >= 3) { if (EngLetterScoring.IsWord(curword)) { ret = true; } } if (i > 0) { if (j > 0) { if (!ret && FindAnyWord(i - 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i - 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i - 1, j + 1)) { ret = true; } } } if (j > 0) { if (!ret && FindAnyWord(i, j - 1)) { ret = true; } } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i, j + 1)) { ret = true; } } if (i < WSGameState.gridsize - 1) { if (j > 0) { if (!ret && FindAnyWord(i + 1, j - 1)) { ret = true; } } if (!ret && FindAnyWord(i + 1, j)) { ret = true; } if (j < WSGameState.gridsize - 1) { if (!ret && FindAnyWord(i + 1, j + 1)) { ret = true; } } } } } CurrentWordFind.RemoveAt(CurrentWordFind.Count - 1); return(ret); }