public IEnumerable <ushort[]> GenerateAllBoards() { ushort[] board = new ushort[6]; int nrOfRows = this.validRows.Length; for (int row0 = 0; row0 < nrOfRows; row0 += 1) { for (int row1 = 0; row1 < nrOfRows; row1 += 1) { if (row1 == row0) { continue; } for (int row2 = 0; row2 < nrOfRows; row2 += 1) { if (row2 == row1 || row2 == row0) { continue; } for (int row3 = 0; row3 < nrOfRows; row3 += 1) { if (row3 == row2 || row3 == row1 || row3 == row0) { continue; } for (int row4 = 0; row4 < nrOfRows; row4 += 1) { if (row4 == row3 || row4 == row2 || row4 == row1 || row4 == row0) { continue; } for (int row5 = 0; row5 < nrOfRows; row5 += 1) { if (row5 == row4 || row5 == row3 || row5 == row2 || row5 == row1 || row5 == row0) { continue; } board[0] = validRows[row0]; board[1] = validRows[row1]; board[2] = validRows[row2]; board[3] = validRows[row3]; board[4] = validRows[row4]; board[5] = validRows[row5]; if (boardChecker.IsValid(board, fullMask)) { yield return(board); board = new ushort[6]; } } } } } } } }
public bool Solve(ushort[] rows, ushort[] masks) { ushort[] columns = new ushort[this.size]; ushort[] colMasks = new ushort[this.size]; //while (!BoardIsComplete(masks)) //{ int rowSolvers = 1; while (rowSolvers > 0) { rowSolvers = 0; Output?.PrintBoard(rows, masks, this.size); // Solve rows bool solving = true; while (solving) { solving = false; for (int iRow = 0; iRow < this.size; iRow += 1) { Debug.WriteLine($"{iRow} - ROW {rows[iRow].ToBinaryString(masks[iRow])}"); solving = solving || this.rowSolver.Solve(ref rows[iRow], ref masks[iRow], this.size); } if (solving) { rowSolvers += 1; } } boardSolver.Solve(rows, masks, size); Output?.PrintBoard(rows, masks, this.size); // Solve columns this.flipper.Flip(rows, ref columns, this.size); this.flipper.Flip(masks, ref colMasks, this.size); Output?.PrintBoard(columns, colMasks, this.size, horizontal: false); solving = true; while (solving) { solving = false; for (int iRow = 0; iRow < this.size; iRow += 1) { solving = solving || this.rowSolver.Solve(ref columns[iRow], ref colMasks[iRow], this.size); } if (solving) { rowSolvers += 1; } } boardSolver.Solve(columns, colMasks, size); Output?.PrintBoard(columns, colMasks, this.size, horizontal: false); this.flipper.Flip(columns, ref rows, this.size); this.flipper.Flip(colMasks, ref masks, this.size); if (!checker.IsValid(rows, masks)) { Output?.WarningIfNotValid(); } Iterations -= 1; if (Iterations <= 0) { return(false); } } //} return(checker.IsValid(rows, masks) && BoardIsComplete(masks)); }