コード例 #1
0
 public CellPanel(Cell c, TableController tableCtrl)
 {
     tableController = tableCtrl;
     cell = c;
     InitializeCellPanel();
     BuildCandidateView();   // This is the default view
     BuildResultView();
     BuildEditView();
     Refresh();
     this.MouseLeftButtonUp += new MouseButtonEventHandler(LeftClickOnPanel);
 }
コード例 #2
0
 public static IEnumerable<Cell> GetRowOfCell(Cell cell, List<List<Cell>> cells)
 {
     return GetRowByIndex(cell.Y, cells);
 }
コード例 #3
0
 public static IEnumerable<Cell> GetColumnOfCell(Cell cell, List<List<Cell>> cells)
 {
     return GetColumnByIndex(cell.X, cells);
 }
コード例 #4
0
 /**
  * Erase the new cell value from the same Column, Row and Box
  */
 protected void BasicStep(Cell cell)
 {
     InnerBasicStep(TableSearch.GetColumnByIndex(cell.X, table.Cells).ToList(), cell.Value);
     InnerBasicStep(TableSearch.GetRowByIndex(cell.Y, table.Cells).ToList(), cell.Value);
     InnerBasicStep(cell.Box.Cells, cell.Value);
 }
コード例 #5
0
        private List<List<Cell>> ParseMap(String map)
        {
            List<List<Cell>> table = new List<List<Cell>>();

            for (int y = 0; y < 9; y++)
            {
                List<Cell> row = new List<Cell>();
                for (int x = 0; x < 9; x++)
                {
                    int value;
                    if (int.TryParse(Convert.ToString(map[x + y * 9]), out value))
                    {
                        Cell cell = new Cell(x, y, value);
                        cell.IsDefault = (value > 0);
                        row.Add(cell);
                    }
                }
                table.Add(row);
            }
            return table;
        }
コード例 #6
0
        public bool CheckCellValidity(Cell cell)
        {
            //TODO:
            if (cell.Value == 0) return false;
            int count = 0;

            // Row
            foreach (var c in TableSearch.GetRowOfCell(cell, table.Cells))
            {
                if (c.Value == cell.Value) count++;
                if (count > 1) return false;
            }

            // Column
            count = 0;
            foreach (var c in TableSearch.GetColumnOfCell(cell, table.Cells))
            {
                if (c.Value == cell.Value) count++;
                if (count > 1) return false;
            }

            // Box
            count = 0;
            foreach (var c in cell.Box.Cells)
            {
                if (c.Value == cell.Value) count++;
                if (count > 1) return false;
            }
            return true;
        }
コード例 #7
0
        public void SolveTableBeforeGame(SolverController solver)
        {
            MakeCandidatesForTableCells();

            do {
                ClearAllExceptDefaults();
                solver.GetSolvedMap();
            } while (!CheckTable());

            solvedTable = new Table();
            foreach (var row in Table.Cells)
            {
                var sr = new List<Cell>();
                foreach (var cell in row)
                {
                    var sc = new Cell();
                    sc.Value = cell.Value;
                    sr.Add(sc);
                    if (!cell.IsDefault) cell.Value = 0;
                }
                solvedTable.Cells.Add(sr);
            }
            RenderTable();
        }
コード例 #8
0
        public void MakeCandidatesForCell(Cell cell)
        {
            if (cell.Candidates.Count > 0) cell.Candidates.Clear();
            if (cell.Value == 0)
            {
                for (int value = 1; value <= 9; value++)
                {
                    cell.Value = value; // testing
                    if (CheckCellValidity(cell)) cell.Candidates.Add(value);
                }
                cell.Value = 0;
                cell.Candidates.Sort();

                if (cellPanels.Count > 0) cell.Panel.Refresh();
            }
        }