示例#1
0
    /// <summary>
    /// Simplifies the progress.
    /// </summary>
    /// <returns>The <see cref="SudokuProgress"/>.</returns>
    private SudokuProgress Simplify()
    {
        var valid = this.CheckValid();

        return(!valid
                   ? SudokuProgress.Failed
                   : this.rules.Aggregate(
                   SudokuProgress.NoProgress,
                   (current, rule) => SudokuTile.CombineSolvedState(current, rule.Solve(this.language))));
    }
示例#2
0
    void CreateCanvasLayout()
    {
        allTiles = new SudokuTile[numberOfCells, numberOfCells];

        for (int y = 0; y < numberOfCells; y++)
        {
            for (int x = 0; x < numberOfCells; x++)
            {
                SudokuTile newTile = Instantiate(tilePrefab, layoutGUI);
                newTile.SetValue(sudokuLayout[x, y]);
                allTiles[x, y] = newTile;
            }
        }
    }
示例#3
0
        public void ValueTooLarge()
        {
            SudokuTile Tile = new SudokuTile(1, 1, 9);

            try
            {
                Tile.Value = 10;
            }
            catch (Exception e)
            {
                if (!(e is  ArgumentOutOfRangeException))
                {
                    Assert.Fail("Correct exception not thrown");
                }
            }
        }
示例#4
0
    /// <summary>
    /// Opens the prompt.
    /// </summary>
    /// <param name="coord">The calling SudokuTile</param>
    public void ActivatePrompt(SudokuTile coord)
    {
        //update fields
        Coord          = coord;
        PreviousNumber = Coord.Value;
        Bitmap         = Coord.Bitmap;
        if (Bitmap == null || Bitmap.Length == 1)
        {
            Bitmap = new bool[, ] {
                { true }
            }
        }
        ;

        //render the bitmap as a texture
        Color[] colors = new Color[Bitmap.Length];
        for (int i = 0; i < Bitmap.GetLength(0); i++)
        {
            for (int j = 0; j < Bitmap.GetLength(1); j++)
            {
                colors[i + j * Bitmap.GetLength(0)] = Bitmap[i, j] ? Color.white : Color.black;
            }
        }

        var tex = new Texture2D(Bitmap.GetLength(0), Bitmap.GetLength(1));

        tex.filterMode = FilterMode.Point;
        tex.SetPixels(colors);
        tex.Apply();
        var ri = gameObject.GetComponentInChildren <RawImage>();

        ri.texture = tex;
        ri.GetComponent <AspectRatioFitter>().aspectRatio = Bitmap.GetLength(0) / (float)Bitmap.GetLength(1);

        //mark the original number if it was defined
        if (Coord.Defined)
        {
            foreach (var t in GetComponentsInChildren <Text>())
            {
                if (t.text == PreviousNumber.ToString())
                {
                    t.color = marked;
                    break;
                }
            }
        }
    }
示例#5
0
        public void SetValueWhenFixed()
        {
            SudokuTile Tile = new SudokuTile(1, 1, 9)
            {
                Fix = true
            };

            try
            {
                Tile.Value = 2;
            }
            catch (Exception e)
            {
                if (!(e is InvalidOperationException))
                {
                    Assert.Fail("Correct exception not thrown");
                }
            }
        }
示例#6
0
    /// <summary>
    /// Called when the user presses a digit or exits the prompt.
    /// </summary>
    /// <param name="number">The number the user pressed. -1 for pressing the back button or equivalent.</param>
    public void Choose(int number)
    {
        if (number != -1 && number != PreviousNumber) //check if the sudoku really needs updating
        {
            Coord.Value   = number;
            Coord.Defined = number > 0;
            if (Coord.Defined)
            {
                Coord.Display();
            }
            else
            {
                Coord.Hide();
            }

            //remove old identification from the array of saved bitmaps
            if (PreviousNumber != 0)
            {
                bool[][,] oldBitmapsRow = new bool[TakePicture.Instance.storedBitmaps[PreviousNumber].Length - 1][, ];
                bool skip = true;
                for (int i = 0; i < TakePicture.Instance.storedBitmaps[PreviousNumber].Length; i++)
                {
                    if (skip && TakePicture.Instance.storedBitmaps[PreviousNumber][i] == Bitmap)
                    {
                        skip = false;
                    }
                    else if (skip && i == oldBitmapsRow.Length) //do not remove anything if there was no identical bitmap stored
                    {
                        break;
                    }
                    else
                    {
                        oldBitmapsRow[i - (skip ? 0 : 1)] = TakePicture.Instance.storedBitmaps[PreviousNumber][i];
                    }
                }

                if (!skip)
                {
                    TakePicture.Instance.storedBitmaps[PreviousNumber] = oldBitmapsRow;
                }
            }

            //append new bitmap
            if (number != 0)
            {
                bool[][,] newBitmapsRow = new bool[TakePicture.Instance.storedBitmaps[number].Length + 1][, ];
                System.Array.Copy(TakePicture.Instance.storedBitmaps[number], newBitmapsRow, TakePicture.Instance.storedBitmaps[number].Length);
                newBitmapsRow[newBitmapsRow.Length - 1]    = Bitmap;
                TakePicture.Instance.storedBitmaps[number] = newBitmapsRow;
            }

            RecalculateSudoku();
        }
        //reset fields and close the prompt
        Coord          = null;
        PreviousNumber = -1;
        Bitmap         = null;
        gameObject.GetComponentInChildren <RawImage>().texture = Texture2D.whiteTexture;
        foreach (var t in GetComponentsInChildren <Text>())
        {
            t.color = standard;
        }
        gameObject.SetActive(false);
    }