public CrunchedWord4Grid Crunch(Word4Grid input) { SortedTable <Word4> .Index r1 = this.table.Find(input.Row1); SortedTable <Word4> .Index r2 = this.table.Find(input.Row2); SortedTable <Word4> .Index r3 = this.table.Find(input.Row3); SortedTable <Word4> .Index r4 = this.table.Find(input.Row4); SortedTable <Word4> .Index c1 = this.table.Find(input.Column1); SortedTable <Word4> .Index c2 = this.table.Find(input.Column2); SortedTable <Word4> .Index c3 = this.table.Find(input.Column3); SortedTable <Word4> .Index c4 = this.table.Find(input.Column4); CrunchedWord4Grid crunchedGrid; int c = r1.CompareTo(c1); if (c == 0) { c = r2.CompareTo(c2); if (c == 0) { c = r3.CompareTo(c3); } } if (c > 0) { crunchedGrid = new CrunchedWord4Grid(c1, c2, c3, c4, r1, r2, r3, r4); } else { crunchedGrid = new CrunchedWord4Grid(r1, r2, r3, r4, c1, c2, c3, c4); } return(crunchedGrid); }
private void DoColumn3(Word4 column3, Word4Grid grid, Action <Word4Grid> onFound) { if (this.allowDuplicateWords || (!grid.Row1.Equals(column3) && !grid.Column1.Equals(column3) && !grid.Row2.Equals(column3) && !grid.Column2.Equals(column3) && !grid.Row3.Equals(column3))) { grid = new Word4Grid(grid.Row1, grid.Row2, grid.Row3, new Word4(grid.A30, grid.A31, column3.L4, '\0')); this.trie.Match3(grid.A30, grid.A31, grid.A32, w => this.DoRow4(w, grid, onFound)); } }
private void DoColumn2(Word4 column2, Word4Grid grid, Action <Word4Grid> onFound) { if (this.allowDuplicateWords || (!grid.Row1.Equals(column2) && !grid.Column1.Equals(column2) && !grid.Row2.Equals(column2))) { grid = new Word4Grid(grid.Row1, grid.Row2, new Word4(grid.A20, column2.L3, '\0', '\0'), new Word4(grid.A30, column2.L4, '\0', '\0')); this.trie.Match2(grid.A20, grid.A21, w => this.DoRow3(w, grid, onFound)); } }
private void DoColumn1(Word4 column1, Word4Grid grid, Action <Word4Grid> onFound) { if (this.allowDuplicateWords || !grid.Row1.Equals(column1)) { grid = new Word4Grid(grid.Row1, new Word4(column1.L2, '\0', '\0', '\0'), new Word4(column1.L3, '\0', '\0', '\0'), new Word4(column1.L4, '\0', '\0', '\0')); this.trie.Match1(grid.A10, w => this.DoRow2(w, grid, onFound)); } }
private void DoRow4(Word4 row4, Word4Grid grid, Action <Word4Grid> onFound) { grid = new Word4Grid(grid.Row1, grid.Row2, grid.Row3, row4); if (this.allowDuplicateWords || (!grid.Row1.Equals(row4) && !grid.Column1.Equals(row4) && !grid.Row2.Equals(row4) && !grid.Column2.Equals(row4) && !grid.Row3.Equals(row4) && !grid.Column3.Equals(row4) && !grid.Column4.Equals(row4))) { if (this.trie.Contains(grid.Column4)) { onFound(grid); } } }
public static void Load(string line1, string line2, string line3, string line4, Action <Word4Grid> onGridFound) { string[] row1 = line1.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries); string[] row2 = line2.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries); string[] row3 = line3.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries); string[] row4 = line4.Split(SpaceChar, StringSplitOptions.RemoveEmptyEntries); int minLength = row1.Length; if (row2.Length < minLength) { minLength = row2.Length; } if (row3.Length < minLength) { minLength = row3.Length; } if (row4.Length < minLength) { minLength = row4.Length; } for (int i = 0; i < minLength; ++i) { if ((row1[i].Length == 4) && (row2[i].Length == 4) && (row3[i].Length == 4) && (row4[i].Length == 4)) { Word4 wr1 = new Word4(row1[i]); Word4 wr2 = new Word4(row2[i]); Word4 wr3 = new Word4(row3[i]); Word4 wr4 = new Word4(row4[i]); Word4Grid grid = new Word4Grid(wr1, wr2, wr3, wr4); onGridFound(grid); } } }
public void Find(Word4 input, Action <Word4Grid> onFound) { Word4Grid grid = new Word4Grid(input, new Word4(), new Word4(), new Word4()); this.trie.Match1(grid.A00, w => this.DoColumn1(w, grid, onFound)); }