예제 #1
0
 public DataNode(ColumnNode column, int id)
 {
     Column = column;
     ID     = id;
     Left   = this;
     Right  = this;
     Up     = this;
     Down   = this;
 }
예제 #2
0
        public ColumnNode choose_next_column()
        {
            int        size    = int.MaxValue;
            ColumnNode nextCol = new ColumnNode(-1);
            ColumnNode j       = header.Right.Column;

            while (j != header)
            {
                if (j.Size < size)
                {
                    nextCol = j;
                    size    = j.Size;
                }
                j = j.Right.Column;
            }
            return(nextCol);
        }
예제 #3
0
        public ColumnNode createLinkedList(int[,] grid)
        {
            //create a circular doubly linked link representing the given sudoku
            var columns = new List <ColumnNode>();

            for (int col_ind = 0; col_ind < 324; col_ind++)
            {
                ColumnNode col = new ColumnNode(col_ind);
                col.Right    = h;
                col.Left     = h.Left;
                h.Left.Right = col;
                h.Left       = col;
                columns.Add(col);
            }

            for (int x = 0; x < 9; x++)
            {
                for (int y = 0; y < 9; y++)
                {
                    if (grid[x, y] == 0)
                    {
                        for (int d = 0; d < 9; d++)
                        {
                            //this cell is blank so add all possibilities
                            form_links(columns, x, y, d);
                        }
                    }
                    else
                    {
                        //clue exists in this location so add only for that possibility
                        int d = grid[x, y] - 1;
                        form_links(columns, x, y, d);
                    }
                }
            }
            return(h);
        }
예제 #4
0
 public DLX(ColumnNode h)
 {
     this.h = h;
 }
예제 #5
0
 public AlgorithmX(ColumnNode h)
 {
     header = h;
 }