コード例 #1
0
        private bool SolveRecursevly(MainGame matrix, int depth)
        {
            if (stopping)
            {
                return(false);
            }

            string originalState = matrix.Serialize();

            FillOnes(matrix);

            if (EmptySquares(matrix) == 0)
            {
                return(true);
            }

            var firstdeadSquares = matrix.board.FindFirstSquare(square =>
            {
                if (square.Value == SodukoSet.EmptyValue && square.GetFreeValues().Count == 0)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            });

            if (firstdeadSquares != null)
            {
                matrix.Deserialize(originalState);
                return(false);
            }

            SodukoSquare next = matrix.board.FindFirstSquare(square =>
            {
                return(square.Value == SodukoSet.EmptyValue);
            });

            var possiblevalues = next.GetFreeValues();

            foreach (string testValue in possiblevalues)
            {
                next.Value = testValue;
                int empty = EmptySquares(matrix);
                if (SolveRecursevly(matrix, depth + 1))
                {
                    return(true);
                }
            }

            matrix.Deserialize(originalState);
            return(false);
        }
コード例 #2
0
 public SodukoBoard3d()
 {
     Board = new SodukoSquare[9, 9, 9];
     for (int i = 0; i < 9; i++)
     {
         for (int j = 0; j < 9; j++)
         {
             for (int k = 0; k < 9; k++)
             {
                 Board[i, j, k] = new SodukoSquare(new Index(i, j, k));
             }
         }
     }
 }
コード例 #3
0
        internal string GetJson()
        {
            SodukoSquare[,] tmp = new SodukoSquare[9, 9];

            for (int i = 0; i < 9; i++)
            {
                for (int j = 0; j < 9; j++)
                {
                    tmp[i, j] = this[i, j];
                }
            }

            string res = JsonConvert.SerializeObject(tmp);

            return(res);
        }