Пример #1
0
        public static new async Task <OptimisedNode[][]> FromIntArrayAsync(int[][] data)
        {
            var size       = data.Length;
            var squareSize = (int)Math.Sqrt(size);
            var output     = new OptimisedNode[size][];

            for (var i = 0; i < size; i++)
            {
            }

            for (var y = 0; y < size; y++)
            {
                for (var x = 0; x < size; x++)
                {
                    output[x] ??= new OptimisedNode[size];
                    output[x][y] = new OptimisedNode()
                    {
                        Starting = data[x][y] != 0,
                        Value    = data[x][y],
                        X        = x,
                        Y        = y,
                        Z        = (int)(Math.Floor(y / (decimal)squareSize) * squareSize + Math.Floor(x / (decimal)squareSize)),
                        NextX    = x == size - 1 ? 0: x + 1,
                        NextY    = x == size - 1 ? y + 1 : y
                    };
                }
            }
            return(output);
        }
Пример #2
0
 public void AddNode(OptimisedNode node)
 {
     Nodes.Add(node);
     if (node.Value != 0)
     {
         Blacklist(node.Value);
         mutable[node.Value - 1] = false;
     }
 }
Пример #3
0
        public async Task Init(INode[][] rawGrid)
        {
            if (!Helper.IsValidSudoku(rawGrid))
            {
                throw new ArgumentException("Provided data is not a valid sudoku grid.");
            }
            timerInit.Start();

            steps       = 0;
            size        = rawGrid.Length;
            workingData = new OptimisedNode[size][];
            rows        = new OptimisedNodeGroup[size];
            cols        = new OptimisedNodeGroup[size];
            sqrs        = new OptimisedNodeGroup[size];

            for (var i = 0; i < size; i++)
            {
                workingData[i] = new OptimisedNode[size];
                rows[i]        = new OptimisedNodeGroup(size)
                {
                    Id = i
                };
                cols[i] = new OptimisedNodeGroup(size)
                {
                    Id = i
                };
                sqrs[i] = new OptimisedNodeGroup(size)
                {
                    Id = i
                };
            }

            for (var y = 0; y < size; y++)
            {
                for (var x = 0; x < size; x++)
                {
                    var rawCell = rawGrid[x][y];
                    var cell    = new OptimisedNode()
                    {
                        X        = x,
                        Y        = y,
                        Z        = rawCell.Z,
                        Value    = rawCell.Value,
                        NextX    = x == (size - 1) ? 0 : x + 1,
                        NextY    = x == (size - 1) ? y + 1 : y,
                        Starting = rawCell.Starting,
                        Row      = rows[y],
                        Col      = cols[x],
                        Sqr      = sqrs[rawCell.Z],
                    };
                    workingData[x][y] = cell;

                    rows[y].AddNode(cell);
                    cols[x].AddNode(cell);
                    sqrs[cell.Z].AddNode(cell);
                }
            }
            playbackData = new Queue <IPlaybackStep>();

            timerInit.Stop();
            Ready = true;
        }