Ejemplo n.º 1
0
 public Rrr GetRrrByANumberOfCycles(Rrr newRrr, int i)
 {
     if (i > 0)
     {
         i--;
         Rrr r = new Rrr(newRrr.GetFourCubeAfter1RRRCycle());
         return(GetRrrByANumberOfCycles(r, i));
     }
     else
     {
         return(newRrr);
     }
 }
Ejemplo n.º 2
0
        private void btnPreviousStep_Click(object sender, EventArgs e)
        {
            if (fc != null || sudokuGrid != null)
            {
                if (nrOfSteps > 0)
                {
                    nrOfSteps--;

                    lbDigitSelection.Items.Clear();
                    lbRowSelection.Items.Clear();
                    lbColumnSelection.Items.Clear();
                    lbBlockSelection.Items.Clear();

                    Rrr      rrr            = new Rrr(fc);
                    Rrr      intermediate   = rrr.GetRrrByANumberOfCycles(rrr, nrOfSteps);
                    FourCube equalized4Cube = intermediate.GetFourCubeAfter1RRRCycle().Equalizer();
                    FourCube selector4Cube  = equalized4Cube.Selector();
                    int[,] row2D            = new int[9, 9];
                    int[,] column2D         = new int[9, 9];
                    int[,] block2D          = new int[9, 9];
                    int[,] azimuth2D        = new int[9, 9];
                    double[,] confidences2D = new double[9, 9];
                    int[]    azimuth1D     = new int[81];
                    double[] confidences1D = new double[81];

                    for (int row = 0; row < 9; row++)
                    {
                        for (int col = 0; col < 9; col++)
                        {
                            for (int azimuth = 0; azimuth < 9; azimuth++)
                            {
                                if (selector4Cube.GetCubeCells()[3, row, col, azimuth].GetConfidence() == 1)
                                {
                                    azimuth2D[row, col]     = azimuth + 1;
                                    confidences2D[row, col] = equalized4Cube.GetCubeCells()[3, row, col, azimuth].GetConfidence();
                                }
                                if (selector4Cube.GetCubeCells()[0, row, col, azimuth].GetConfidence() == 1)
                                {
                                    column2D[row, col] = azimuth + 1;
                                }
                                if (selector4Cube.GetCubeCells()[1, row, col, azimuth].GetConfidence() == 1)
                                {
                                    row2D[row, col] = azimuth + 1;
                                }
                                if (selector4Cube.GetCubeCells()[2, row, col, azimuth].GetConfidence() == 1)
                                {
                                    block2D[row, col] = azimuth + 1;
                                }
                            }
                        }
                    }



                    for (int x = 0; x < 9; x++)
                    {
                        for (int y = 0; y < 9; y++)
                        {
                            azimuth1D[9 * x + y]     = azimuth2D[x, y];
                            confidences1D[9 * x + y] = confidences2D[x, y];
                        }
                    }

                    for (int i = 1; i <= 81; i++)
                    {
                        if (this.Controls.ContainsKey("tb" + (i).ToString()))
                        {
                            TextBox tb = this.Controls["tb" + i.ToString()] as TextBox;
                            tb.Text = azimuth1D[i - 1].ToString();
                            if (confidences1D[i - 1] > 0 && confidences1D[i - 1] <= 0.2)
                            {
                                tb.ForeColor = Color.Pink;
                            }
                            else if (confidences1D[i - 1] > 0.2 && confidences1D[i - 1] <= 0.4)
                            {
                                tb.ForeColor = Color.Red;
                            }
                            else if (confidences1D[i - 1] > 0.4 && confidences1D[i - 1] <= 0.6)
                            {
                                tb.ForeColor = Color.Green;
                            }
                            else if (confidences1D[i - 1] > 0.6 && confidences1D[i - 1] <= 0.8)
                            {
                                tb.ForeColor = Color.Blue;
                            }
                            else if (confidences1D[i - 1] > 0.8 && confidences1D[i - 1] <= 1)
                            {
                                tb.ForeColor = Color.Black;
                            }
                        }
                    }

                    if (nrOfSteps >= chartDifference.Series["Differences from the previous step"].Points.Count)
                    {
                        chartDifference.Series["Differences from the previous step"].Points.RemoveAt(nrOfSteps - 1);
                        chartConfidence.Series["0-0.2"].Points.RemoveAt(nrOfSteps - 1);
                        chartConfidence.Series["0.2-0.4"].Points.RemoveAt(nrOfSteps - 1);
                        chartConfidence.Series["0.4-0.6"].Points.RemoveAt(nrOfSteps - 1);
                        chartConfidence.Series["0.6-0.8"].Points.RemoveAt(nrOfSteps - 1);
                        chartConfidence.Series["0.8-1"].Points.RemoveAt(nrOfSteps - 1);
                    }
                    else
                    {
                        chartDifference.Series["Differences from the previous step"].Points.RemoveAt(nrOfSteps);
                        chartConfidence.Series["0-0.2"].Points.RemoveAt(nrOfSteps);
                        chartConfidence.Series["0.2-0.4"].Points.RemoveAt(nrOfSteps);
                        chartConfidence.Series["0.4-0.6"].Points.RemoveAt(nrOfSteps);
                        chartConfidence.Series["0.6-0.8"].Points.RemoveAt(nrOfSteps);
                        chartConfidence.Series["0.8-1"].Points.RemoveAt(nrOfSteps);
                    }

                    //tables
                    for (int x = 0; x < 9; x++)
                    {
                        string s = ""; string row = ""; string col = ""; string block = "";
                        for (int y = 0; y < 9; y++)
                        {
                            s     += azimuth2D[x, y] + ", ";
                            row   += row2D[x, y] + ", ";
                            col   += column2D[x, y] + ", ";
                            block += block2D[x, y] + ", ";
                        }
                        lbDigitSelection.Items.Add(s);
                        lbRowSelection.Items.Add(row);
                        lbColumnSelection.Items.Add(col);
                        lbBlockSelection.Items.Add(block);
                    }
                }
            }
            else
            {
                MessageBox.Show("Please enter a puzzle");
            }
        }
Ejemplo n.º 3
0
        private void Step()
        {
            Rrr rrr          = new Rrr(fc);
            Rrr intermediate = rrr.GetRrrByANumberOfCycles(rrr, nrOfSteps);

            if (intermediate.IsReady() == false)
            {
                lbDigitSelection.Items.Clear();
                lbRowSelection.Items.Clear();
                lbColumnSelection.Items.Clear();
                lbBlockSelection.Items.Clear();

                FourCube equalized4Cube = intermediate.GetFourCubeAfter1RRRCycle().Equalizer();
                FourCube selector4Cube  = equalized4Cube.Selector();
                int[,] azimuth2D = new int[9, 9];
                int[,] row2D     = new int[9, 9];
                int[,] column2D  = new int[9, 9];
                int[,] block2D   = new int[9, 9];

                double[,] confidences2D = new double[9, 9];
                int[]    azimuth1D           = new int[81];
                double[] confidences1D       = new double[81];
                int      confidenceSmaller02 = 0;
                int      confidenceSmaller04 = 0;
                int      confidenceSmaller06 = 0;
                int      confidenceSmaller08 = 0;
                int      confidenceSmaller10 = 0;

                for (int row = 0; row < 9; row++)
                {
                    for (int col = 0; col < 9; col++)
                    {
                        for (int azimuth = 0; azimuth < 9; azimuth++)
                        {
                            if (selector4Cube.GetCubeCells()[3, row, col, azimuth].GetConfidence() == 1)
                            {
                                azimuth2D[row, col]     = azimuth + 1;
                                confidences2D[row, col] = equalized4Cube.GetCubeCells()[3, row, col, azimuth].GetConfidence();
                            }
                            if (selector4Cube.GetCubeCells()[0, row, col, azimuth].GetConfidence() == 1)
                            {
                                column2D[row, col] = azimuth + 1;
                            }
                            if (selector4Cube.GetCubeCells()[1, row, col, azimuth].GetConfidence() == 1)
                            {
                                row2D[row, col] = azimuth + 1;
                            }
                            if (selector4Cube.GetCubeCells()[2, row, col, azimuth].GetConfidence() == 1)
                            {
                                block2D[row, col] = azimuth + 1;
                            }
                        }
                    }
                }

                for (int x = 0; x < 9; x++)
                {
                    for (int y = 0; y < 9; y++)
                    {
                        azimuth1D[9 * x + y]     = azimuth2D[x, y];
                        confidences1D[9 * x + y] = confidences2D[x, y];
                    }
                }

                for (int i = 1; i <= 81; i++)
                {
                    if (this.Controls.ContainsKey("tb" + (i).ToString()))
                    {
                        TextBox tb = this.Controls["tb" + i.ToString()] as TextBox;
                        tb.Text = azimuth1D[i - 1].ToString();
                        if (confidences1D[i - 1] > 0 && confidences1D[i - 1] <= 0.2)
                        {
                            tb.ForeColor = Color.Pink; confidenceSmaller02++;
                        }
                        else if (confidences1D[i - 1] > 0.2 && confidences1D[i - 1] <= 0.4)
                        {
                            tb.ForeColor = Color.Red; confidenceSmaller04++;
                        }
                        else if (confidences1D[i - 1] > 0.4 && confidences1D[i - 1] <= 0.6)
                        {
                            tb.ForeColor = Color.Green; confidenceSmaller06++;
                        }
                        else if (confidences1D[i - 1] > 0.6 && confidences1D[i - 1] <= 0.8)
                        {
                            tb.ForeColor = Color.Blue; confidenceSmaller08++;
                        }
                        else if (confidences1D[i - 1] > 0.8 && confidences1D[i - 1] <= 1)
                        {
                            tb.ForeColor = Color.Black; confidenceSmaller10++;
                        }
                    }
                }


                //chart
                chartDifference.Series["Differences from the previous step"].Points.Add(intermediate.DifferenceCellsFromLastStep());
                //chartDifference.Series["Differences from the solution"].Points.Add(intermediate.DifferenceCellsFromSolution());

                chartConfidence.Series["0-0.2"].Points.Add(confidenceSmaller02);
                chartConfidence.Series["0.2-0.4"].Points.Add(confidenceSmaller04);
                chartConfidence.Series["0.4-0.6"].Points.Add(confidenceSmaller06);
                chartConfidence.Series["0.6-0.8"].Points.Add(confidenceSmaller08);
                chartConfidence.Series["0.8-1"].Points.Add(confidenceSmaller10);

                //tables
                for (int x = 0; x < 9; x++)
                {
                    string s = ""; string row = ""; string col = ""; string block = "";
                    for (int y = 0; y < 9; y++)
                    {
                        s     += azimuth2D[x, y] + ", ";
                        row   += row2D[x, y] + ", ";
                        col   += column2D[x, y] + ", ";
                        block += block2D[x, y] + ", ";
                    }
                    lbDigitSelection.Items.Add(s);
                    lbRowSelection.Items.Add(row);
                    lbColumnSelection.Items.Add(col);
                    lbBlockSelection.Items.Add(block);
                }
            }
        }
Ejemplo n.º 4
0
        private void Start()
        {
            bool isDone = false;

            while (!isDone)
            {
                if (fc != null && sudokuGrid != null)
                {
                    //inCriticalSection = true;
                    nrOfSteps++;
                    Rrr rrr          = new Rrr(fc);
                    Rrr intermediate = rrr.GetRrrByANumberOfCycles(rrr, nrOfSteps);
                    if (intermediate.IsReady() == false)
                    {
                        SetEmptyListBox(lbDigitSelection);
                        SetEmptyListBox(lbRowSelection);
                        SetEmptyListBox(lbColumnSelection);
                        SetEmptyListBox(lbBlockSelection);

                        FourCube equalized4Cube = intermediate.GetFourCubeAfter1RRRCycle().Equalizer();
                        FourCube selector4Cube  = equalized4Cube.Selector();
                        int[,] azimuth2D = new int[9, 9];
                        int[,] row2D     = new int[9, 9];
                        int[,] column2D  = new int[9, 9];
                        int[,] block2D   = new int[9, 9];

                        double[,] confidences2D = new double[9, 9];
                        int[]    azimuth1D           = new int[81];
                        double[] confidences1D       = new double[81];
                        int      confidenceSmaller02 = 0;
                        int      confidenceSmaller04 = 0;
                        int      confidenceSmaller06 = 0;
                        int      confidenceSmaller08 = 0;
                        int      confidenceSmaller10 = 0;

                        for (int row = 0; row < 9; row++)
                        {
                            for (int col = 0; col < 9; col++)
                            {
                                for (int azimuth = 0; azimuth < 9; azimuth++)
                                {
                                    if (selector4Cube.GetCubeCells()[3, row, col, azimuth].GetConfidence() == 1)
                                    {
                                        azimuth2D[row, col]     = azimuth + 1;
                                        confidences2D[row, col] = equalized4Cube.GetCubeCells()[3, row, col, azimuth].GetConfidence();
                                    }
                                    if (selector4Cube.GetCubeCells()[0, row, col, azimuth].GetConfidence() == 1)
                                    {
                                        column2D[row, col] = azimuth + 1;
                                    }
                                    if (selector4Cube.GetCubeCells()[1, row, col, azimuth].GetConfidence() == 1)
                                    {
                                        row2D[row, col] = azimuth + 1;
                                    }
                                    if (selector4Cube.GetCubeCells()[2, row, col, azimuth].GetConfidence() == 1)
                                    {
                                        block2D[row, col] = azimuth + 1;
                                    }
                                }
                            }
                        }

                        for (int x = 0; x < 9; x++)
                        {
                            for (int y = 0; y < 9; y++)
                            {
                                azimuth1D[9 * x + y]     = azimuth2D[x, y];
                                confidences1D[9 * x + y] = confidences2D[x, y];
                            }
                        }

                        for (int i = 1; i <= 81; i++)
                        {
                            if (this.Controls.ContainsKey("tb" + (i).ToString()))
                            {
                                TextBox tb = this.Controls["tb" + i.ToString()] as TextBox;
                                SetText(tb, azimuth1D[i - 1].ToString());
                                if (confidences1D[i - 1] > 0 && confidences1D[i - 1] <= 0.2)
                                {
                                    SetColor(tb, Color.Pink); confidenceSmaller02++;
                                }
                                else if (confidences1D[i - 1] > 0.2 && confidences1D[i - 1] <= 0.4)
                                {
                                    SetColor(tb, Color.Red); confidenceSmaller04++;
                                }
                                else if (confidences1D[i - 1] > 0.4 && confidences1D[i - 1] <= 0.6)
                                {
                                    SetColor(tb, Color.Green); confidenceSmaller06++;
                                }
                                else if (confidences1D[i - 1] > 0.6 && confidences1D[i - 1] <= 0.8)
                                {
                                    SetColor(tb, Color.Blue); confidenceSmaller08++;
                                }
                                else if (confidences1D[i - 1] > 0.8 && confidences1D[i - 1] <= 1)
                                {
                                    SetColor(tb, Color.Black); confidenceSmaller10++;
                                }
                            }
                        }


                        //chart
                        SetChart(chartDifference, "Differences from the previous step", intermediate.DifferenceCellsFromLastStep());
                        //chartLine.Series["Differences from the solution"].Points.Add(intermediate.DifferenceCellsFromSolution());

                        SetChart(chartConfidence, "0-0.2", confidenceSmaller02);
                        SetChart(chartConfidence, "0.2-0.4", confidenceSmaller04);
                        SetChart(chartConfidence, "0.4-0.6", confidenceSmaller06);
                        SetChart(chartConfidence, "0.6-0.8", confidenceSmaller08);
                        SetChart(chartConfidence, "0.8-1", confidenceSmaller10);

                        //tables
                        for (int x = 0; x < 9; x++)
                        {
                            string s = ""; string row = ""; string col = ""; string block = "";
                            for (int y = 0; y < 9; y++)
                            {
                                s     += azimuth2D[x, y] + ", ";
                                row   += row2D[x, y] + ", ";
                                col   += column2D[x, y] + ", ";
                                block += block2D[x, y] + ", ";
                            }
                            SetListBox(lbDigitSelection, s);
                            SetListBox(lbRowSelection, row);
                            SetListBox(lbColumnSelection, col);
                            SetListBox(lbBlockSelection, block);
                        }
                        isDone = intermediate.IsReady();
                        Thread.Sleep(timeSpan);
                    }
                    //inCriticalSection = false;
                }
                else
                {
                    MessageBox.Show("Please enter a puzzle");
                }
            }
        }