コード例 #1
0
ファイル: Program.cs プロジェクト: taylorjg/TetrisCubeDlx
        private static void Main()
        {
            var puzzle       = new Puzzle();
            var internalRows = InternalRowBuilder.BuildInternalRows(puzzle);
            var dlxMatrix    = DlxMatrixBuilder.BuildDlxMatrix(puzzle, internalRows);

            var dlx      = new Dlx();
            var solution = dlx.Solve(dlxMatrix, rows => rows, row => row.Bits).FirstOrDefault();

            if (solution != null)
            {
                DumpSolutionSimple(solution, dlxMatrix);
                Console.WriteLine();
                DumpSolutionCube(puzzle, solution, dlxMatrix);
            }
        }
コード例 #2
0
        private void SolvePuzzleInBackground()
        {
            var internalRows = InternalRowBuilder.BuildInternalRows(_puzzle);
            var dlxMatrix    = DlxMatrixBuilder.BuildDlxMatrix(_puzzle, internalRows);

            var dlx = new Dlx(_cancellationToken);

            dlx.SearchStep += (_, searchStepEventArgs) =>
                              InvokeActionPassingSubsetOfInternalRows(
                internalRows,
                searchStepEventArgs.RowIndexes,
                _onSearchStep);

            var firstSolution = dlx.Solve(dlxMatrix, rows => rows, row => row.Bits).FirstOrDefault();

            if (firstSolution != null)
            {
                InvokeActionPassingSubsetOfInternalRows(
                    internalRows,
                    firstSolution.RowIndexes,
                    _onSolutionFound);
            }
        }