static void GetAllWords(Tile[] tiles, int index, TileWord candidate, List <TileWord> words) { if (!SubWordSet.Contains(candidate.Word)) { return; } tiles[index].IsTaken = true; if (WordSet.Contains(candidate.Word)) { words.Add(candidate); } for (int i = 0; i < 8; i++) { var row = index / 4 + (int)Math.Round(Math.Sin(Math.PI / 4 * (i - 2))); var col = index % 4 + (int)Math.Round(Math.Sin(Math.PI / 4 * i)); if (row >= 0 && row < 4 && col >= 0 && col < 4 && !tiles[row * 4 + col].IsTaken) { GetAllWords(tiles, row * 4 + col, candidate.Add(tiles[row * 4 + col]), words); } } tiles[index].IsTaken = false; }
public TileWord Add(Tile tile) { var result = new TileWord(this); result.Tiles.Add(tile); result.Word += tile.Letter; return(result); }
public TileWord(TileWord tileWord) { Word = tileWord.Word; Tiles = new List <Tile>(); foreach (var tile in tileWord.Tiles) { Tiles.Add(tile); } }