private void UpdateDisplay(Puzzle puzzle)
        {
            foreach (var row in puzzle.Rows)
            {
                var aRow = new TableRow();
                aspTable.Rows.Add(aRow);

                foreach (var cell in row.Cells)
                {
                    var aCell = new TableCell();
                    aRow.Cells.Add(aCell);

                    switch (puzzle.Cells[cell.Key.X,cell.Key.Y].Value)
                    {
                        case 1:
                            aCell.BackColor = Color.Black;
                            break;
                        case -1:
                            aCell.BackColor = Color.LightGray;
                            break;
                        case 0:
                            aCell.BackColor = Color.White;
                            break;
                        default:
                            throw new Exception("Wrong Cell Value");
                    }
                }

            }
        }
示例#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);
                }
            }
        }
示例#3
0
 public void TestSetUp()
 {
     Puzzle = PuzzleFactory.Instance().MakePuzzle(5, 5, new List<Line>
     {
         PuzzleFactory.Instance().MakeLine<Row>(new[] {1, 1}, 0),
         PuzzleFactory.Instance().MakeLine<Row>(new[] {5}, 1),
         PuzzleFactory.Instance().MakeLine<Row>(new[] {1, 1}, 2),
         PuzzleFactory.Instance().MakeLine<Row>(new[] {5}, 3),
         PuzzleFactory.Instance().MakeLine<Row>(new[] {1, 1}, 4),
         PuzzleFactory.Instance().MakeLine<Column>(new[] {1, 1}, 0),
         PuzzleFactory.Instance().MakeLine<Column>(new[] {5}, 1),
         PuzzleFactory.Instance().MakeLine<Column>(new[] {1, 1}, 2),
         PuzzleFactory.Instance().MakeLine<Column>(new[] {5}, 3),
         PuzzleFactory.Instance().MakeLine<Column>(new[] {1, 1}, 4)
     });
 }
示例#4
0
        private void AddGridLine(Puzzle puzzle, bool isRow, int num)
        {
            var location = start;
            var size = new Size(1, 1);

            if (isRow)
            {
                location.Y += gridSize * num;
                size.Width += puzzle.Width * gridSize;
            }
            if (!isRow)
            {
                location.X += gridSize * num;
                size.Height += puzzle.Height * gridSize;
            }

            Shape gridline;

            string type = size.Height == 1 ? "hori" : "vert";
            string name = String.Format("{0}Gridline_{1}", type, num);

            if (this.solutionPanel.Controls.ContainsKey(name))
            {
                gridline = (Shape)this.solutionPanel.Controls[name];
                gridline.Show();
            }
            else
            {
                gridline = new Shape
                {
                    Location = location,
                    Name = name
                };
                gridline.ShapeColor = (num % 5 == 0) ? Color.Black : Color.LightPink;
                this.solutionPanel.Controls.Add(gridline);
                gridLines.Add(gridline);
            }
            gridline.Size = size;
        }
示例#5
0
        private void UpdateDisplay(Puzzle puzzle)
        {
            RemoveGrid();

            for (int row = 0; row < puzzle.Height; row++)
            {
                AddGridLine(puzzle, true, row);
                AddLabel(puzzle, true, row);
                for (int col = 0; col < puzzle.Width; col++)
                {
                    AddGridLine(puzzle, false, col);
                    AddLabel(puzzle, false, col);
                    var p = new Point(row, col);
                    AddBox(p);

                    switch (puzzle.Cells[col, row].Value)
                    {
                        case 1:
                            boxes[p].BackColor = Color.Black;
                            break;
                        case -1:
                            boxes[p].BackColor = Color.LightGray;
                            break;
                        case 0:
                            boxes[p].BackColor = Color.White;
                            break;
                        default:
                            throw new Exception("Wrong Cell Value");
                    }
                }
                AddGridLine(puzzle, true, puzzle.Height);
                AddGridLine(puzzle, false, puzzle.Width);
            }
        }
示例#6
0
        private void AddLabel(Puzzle puzzle, bool isRow, int num)
        {
            Point p = start;
            string type;
            string clues;
            if (isRow)
            {
                clues = puzzle.GetRowClues(num);
                type = "hori";
            }
            else
            {
                clues = puzzle.GetColumnClues(num);
                type = "vert";
            }

            string name = String.Format("{0}Label{1}", type, num);

            Label label;

            if (this.solutionPanel.Controls.ContainsKey(name))
            {
                label = (Label)this.solutionPanel.Controls[name];
                label.Show();
            }
            else
            {
                label = new Label
                {
                    Name = name,
                    Font = new Font("Microsoft Sans Serif", 7),
                    AutoSize = true
                };

                this.solutionPanel.Controls.Add(label);
            }

            label.Text = clues;
            labels.Add(label);

            if (isRow)
            {
                p.Offset(-label.Width - 5, gridSize * num + 3);
            }
            else
            {
                p.Offset(gridSize * num + 3, -label.Height - 5);
            }

            label.Location = p;
        }