static ProbableWord MakeAWord(List <Word> F1, Word C, List <Word> F2) { ProbableWord W = new ProbableWord(); List <TargetCell> List = new List <TargetCell>(); string ret = ""; foreach (Word s in F1) { ret = ret + s.Tiles.Replace(",", "") + ","; TargetCell Cell = new TargetCell { Target = s.Tiles, Index = s.Index }; List.Add(Cell); } { ret = ret + C.Tiles.Replace(",", "") + ","; TargetCell Cell = new TargetCell { Target = C.Tiles, Index = C.Index }; List.Add(Cell); } foreach (Word s in F2) { ret = ret + s.Tiles.Replace(",", "") + ","; TargetCell Cell = new TargetCell { Target = s.Tiles, Index = s.Index }; List.Add(Cell); } ret = ret.Trim(','); W.String = ret; W.Cells = List; return(W); }
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); }