Ejemplo n.º 1
0
        public PuzzleSolver(Puzzle puzzle)
        {
            this.puzzle = puzzle;

            lineSolvers = new List <LineSolver>();
            foreach (Line line in puzzle.Lines)
            {
                var lineSolver = new LineSolver(line);
                lineSolver.OwnerPuzzle = this;
                lineSolvers.Add(lineSolver);
            }
            cellSolvers = new List <CellSolver>();
            foreach (Cell cell in puzzle.Cells)
            {
                var cellSolver = new CellSolver(cell);
                cellSolver.OwnerPuzzle = this;
                cellSolvers.Add(cellSolver);
            }
            foreach (var row in lineSolvers.Where(l => l.line.IsRow))
            {
                foreach (var column in lineSolvers.Where(l => !l.line.IsRow))
                {
                    var cell = cellSolvers.Find(c => c.cell.Row == row.line && c.cell.Column == column.line);
                    row.cellSolvers.Add(cell);
                    foreach (var clue in row.clueSolvers)
                    {
                        clue.PossSections.First().Add(cell);
                    }
                    column.cellSolvers.Add(cell);
                }
            }
        }
Ejemplo n.º 2
0
        public PuzzleSolver(Puzzle puzzle)
        {
            this.puzzle = puzzle;

            lineSolvers = new List<LineSolver>();
            foreach (Line line in puzzle.Lines)
            {
                var lineSolver = new LineSolver(line);
                lineSolver.OwnerPuzzle = this;
                lineSolvers.Add(lineSolver);
            }
            cellSolvers = new List<CellSolver>();
            foreach (Cell cell in puzzle.Cells)
            {
                var cellSolver = new CellSolver(cell);
                cellSolver.OwnerPuzzle = this;
                cellSolvers.Add(cellSolver);
            }
            foreach (var row in lineSolvers.Where(l => l.line.IsRow))
            {
                foreach (var column in lineSolvers.Where(l => !l.line.IsRow))
                {
                    var cell = cellSolvers.Find(c => c.cell.Row == row.line && c.cell.Column == column.line);
                    row.cellSolvers.Add(cell);
                    foreach (var clue in row.clueSolvers)
                    {
                        clue.PossSections.First().Add(cell);
                    }
                    column.cellSolvers.Add(cell);
                }
            }
        }