protected List <string> GetSyllableList(string[] Cells, int size, bool fetchAll, bool filterEdges, bool asGroups) { List <string> List = new List <string>(); for (int index = 0; index < Cells.Length; index++) { string cell = Cells[index]; if (cell == "") { continue; } Neighbor Neighbor = BoardUtil.FindNeighbors(index, size); string r = Neighbor.Right != -1 ? Cells[Neighbor.Right] : ""; string l = Neighbor.Left != -1 ? Cells[Neighbor.Left] : ""; string t = Neighbor.Top != -1 ? Cells[Neighbor.Top] : ""; string b = Neighbor.Bottom != -1 ? Cells[Neighbor.Bottom] : ""; if (!fetchAll) { if ((r != "" || l != "") && (t != "" || b != "")) { if (!filterEdges) { string x = asGroups ? cell : "(" + cell + ")"; if (!List.Contains(x)) { List.Add(x); } } } else { if (filterEdges) { string x = asGroups ? cell : "(" + cell + ")"; if (!List.Contains(x)) { List.Add(x); } } } } else { string x = asGroups ? cell : "(" + cell + ")"; if (!List.Contains(x)) { List.Add(x); } } } return(List); }
protected static List <Word> GetSyllableList2(string[] Cells, int size, bool filter, bool free) { List <Word> List = new List <Word>(); for (int index = 0; index < Cells.Length; index++) { string cell = Cells[index]; if (cell == "") { continue; } var Neighbor = BoardUtil.FindNeighbors(index, size); string r = Neighbor.Right != -1 ? Cells[Neighbor.Right] : ""; string l = Neighbor.Left != -1 ? Cells[Neighbor.Left] : ""; string t = Neighbor.Top != -1 ? Cells[Neighbor.Top] : ""; string b = Neighbor.Bottom != -1 ? Cells[Neighbor.Bottom] : ""; if (filter) { if ((r != "" || l != "") && (t != "" || b != "")) { } else { string x = free ? cell : "(" + cell + ")"; List.Add(new Word { Tiles = x, Index = index }); } } else { string x = free ? cell : "(" + cell + ")"; List.Add(new Word { Tiles = x, Index = index }); } } return(List); }
static List <ProbableWord> WordsAt(string[] Cells, int size, int index) { List <ProbableWord> List = new List <ProbableWord>(); Neighbor Neighbor = BoardUtil.FindNeighbors(index, size); string r = Neighbor.Right != -1 ? Cells[Neighbor.Right] : ""; string l = Neighbor.Left != -1 ? Cells[Neighbor.Left] : ""; string t = Neighbor.Top != -1 ? Cells[Neighbor.Top] : ""; string b = Neighbor.Bottom != -1 ? Cells[Neighbor.Bottom] : ""; List <Word> Lefties = new List <Word>(); List <Word> Righties = new List <Word>(); if (r != "") { //Move Right.. Righties.Add(new Word { Tiles = r, Index = Neighbor.Right }); int index_ = Neighbor.Right; bool flg = true; while (flg) { Neighbor n = BoardUtil.FindNeighbors(index_, size); string r_ = n.Right != -1 ? Cells[n.Right] : ""; if (r_ == "") { flg = false; break; } Righties.Add(new Word { Tiles = r_, Index = n.Right }); index_ = n.Right; } } if (l != "") { //Move Left.. Lefties.Add(new Word { Tiles = l, Index = Neighbor.Left }); int index_ = Neighbor.Left; bool flg = true; while (flg) { Neighbor n = BoardUtil.FindNeighbors(index_, size); string l_ = n.Left != -1 ? Cells[n.Left] : ""; if (l_ == "") { flg = false; break; } Lefties.Add(new Word { Tiles = l_, Index = n.Left }); index_ = n.Left; } } List <Word> Topies = new List <Word>(); List <Word> Downies = new List <Word>(); if (t != "") { //Move Top.. Topies.Add(new Word { Tiles = t, Index = Neighbor.Top }); int index_ = Neighbor.Top; bool flg = true; while (flg) { Neighbor n = BoardUtil.FindNeighbors(index_, size); string t_ = n.Top != -1 ? Cells[n.Top] : ""; if (t_ == "") { flg = false; break; } Topies.Add(new Word { Tiles = t_, Index = n.Top }); index_ = n.Top; } } if (b != "") { //Move Bottom.. Downies.Add(new Word { Tiles = b, Index = Neighbor.Bottom }); int index_ = Neighbor.Bottom; bool flg = true; while (flg) { Neighbor n = BoardUtil.FindNeighbors(index_, size); string d_ = n.Bottom != -1 ? Cells[n.Bottom] : ""; if (d_ == "") { flg = false; break; } Downies.Add(new Word { Tiles = d_, Index = n.Bottom }); index_ = n.Bottom; } } Topies.Reverse(); Lefties.Reverse(); if (Topies.Count + Downies.Count > 0) { ProbableWord Vertical = MakeAWord(Topies, new Word { Tiles = Cells[index], Index = index }, Downies); List.Add(Vertical); } if (Lefties.Count + Righties.Count > 0) { ProbableWord Harizontal = MakeAWord(Lefties, new Word { Tiles = Cells[index], Index = index }, Righties); List.Add(Harizontal); } return(List); }
protected static ProbableMove TryHarizontal(int Mode, int Star, string[] Cells, int size, int Index, int offset, string[] Pre, string[] Centers, string[] Post) { List <Word> Moves = new List <Word>(); int PreCount = Pre.Length; int PostCount = Post.Length; string[] NewCells = (string[])Cells.Clone(); List <int> Impacted = new List <int>(); if (Pre.Length != 0) { for (int x = Pre.Length - 1; x >= 0; x--) { Neighbor n = BoardUtil.FindNeighbors(Index - x, size); if (n.Left != -1) { NewCells[n.Left] += Pre[x]; Impacted.Add(n.Left); if (Pre[x] == null) { continue; } Moves.Add(new Word { Tiles = Pre[x], Index = n.Left }); } else { return(new ProbableMove { Words = new List <ProbableWord>(), Direction = "H", Moves = new List <Word>() }); } } } if (Centers.Length != 0) { for (int c = 0; c < Centers.Length; c++) { int cellIndex = Index + c; if (cellIndex == -1 || Centers[c] == "") { continue; } NewCells[cellIndex] += Centers[c]; Impacted.Add(cellIndex); if (Centers[c] == null) { continue; } Moves.Add(new Word { Tiles = Centers[c], Index = cellIndex }); } } if (Post.Length != 0) { for (int x = 0; x < Post.Length; x++) { Neighbor n = BoardUtil.FindNeighbors(Index + offset + x, size); if (n.Right != -1) { NewCells[n.Right] += Post[x]; Impacted.Add(n.Right); if (Post[x] == null) { continue; } Moves.Add(new Word { Tiles = Post[x], Index = n.Right }); } else { return(new ProbableMove { Words = new List <ProbableWord>(), Direction = "H", Moves = new List <Word>() }); } } } List <ProbableWord> W = new List <ProbableWord>(); if (Star < 0 || (Star >= 0 && NewCells[Star].Trim() != "")) { foreach (int index in Impacted) { W.AddRange(WordsAt(NewCells, size, index)); } } return(new ProbableMove { Mode = Mode, Words = W, Moves = Moves, Direction = "H" }); }
protected static ProbableMove TryVertical(int Mode, int Star, string[] Cells, int size, int Index, int offset, string[] Pre, string[] Centers, string[] Post) { List <Word> Moves = new List <Word>(); int PreCount = Pre.Length; int PostCount = Post.Length; Point Pos = BoardUtil.Position(Index, size); string[] NewCells = (string[])Cells.Clone(); List <int> Impacted = new List <int>(); if (Pre.Length != 0) { for (int x = Pre.Length - 1; x >= 0; x--) { int cellIndex = BoardUtil.Abs(Pos.X - x, Pos.Y, size); Neighbor n = BoardUtil.FindNeighbors(cellIndex, size); if (n.Top != -1) { NewCells[n.Top] += Pre[x]; Impacted.Add(n.Top); if (Pre[x] == null) { continue; } Moves.Add(new Word { Tiles = Pre[x], Index = n.Top }); } else { return(new ProbableMove { Words = new List <ProbableWord>(), Direction = "V", Moves = new List <Word>() }); } } } if (Centers.Length != 0) { for (int c = 0; c < Centers.Length; c++) { int cellIndex = BoardUtil.Abs(Pos.X + c, Pos.Y, size); if (cellIndex == -1 || Centers[c] == "") { continue; } NewCells[cellIndex] += Centers[c]; Impacted.Add(cellIndex); if (Centers[c] == null) { continue; } Moves.Add(new Word { Tiles = Centers[c], Index = cellIndex }); } } if (Post.Length != 0) { for (int x = 0; x < Post.Length; x++) { int cellIndex = BoardUtil.Abs(Pos.X + offset + x, Pos.Y, size); Neighbor n = BoardUtil.FindNeighbors(cellIndex, size); if (n.Bottom != -1) { //string temp = Join(Post[x], Seperator); NewCells[n.Bottom] += Post[x]; Impacted.Add(n.Bottom); if (Post[x] == null) { continue; } Moves.Add(new Word { Tiles = Post[x], Index = n.Bottom }); } else { return(new ProbableMove { Words = new List <ProbableWord>(), Direction = "V", Moves = new List <Word>() }); } } } List <ProbableWord> W = new List <ProbableWord>(); if (Star < 0 || (Star >= 0 && NewCells[Star].Trim() != "")) { foreach (int index in Impacted) { W.AddRange(WordsAt(NewCells, size, index)); } } return(new ProbableMove { Mode = Mode, Words = W, Moves = Moves, Direction = "V" }); }