Ejemplo n.º 1
0
 //multiply
 public FourCube Multiply(double v)
 {
     CubeCell[,,,] newCubeCells = new CubeCell[4, 9, 9, 9];
     for (int cube = 0; cube < 4; cube++)
     {
         for (int row = 0; row < 9; row++)
         {
             for (int col = 0; col < 9; col++)
             {
                 for (int azimuth = 0; azimuth < 9; azimuth++)
                 {
                     if (cubeCells[cube, row, col, azimuth].GetIsClue() != true)
                     {
                         newCubeCells[cube, row, col, azimuth] = new CubeCell(v * cubeCells[cube, row, col, azimuth].GetConfidence(), false);
                     }
                     else
                     {
                         newCubeCells[cube, row, col, azimuth] = new CubeCell(cubeCells[cube, row, col, azimuth].GetConfidence(), true);
                     }
                 }
             }
         }
     }
     return(new FourCube(newCubeCells));
 }
Ejemplo n.º 2
0
 //minus 2 four-cube
 public FourCube Minus(FourCube fc)
 {
     CubeCell[,,,] newCubeCells = new CubeCell[4, 9, 9, 9];
     for (int cube = 0; cube < 4; cube++)
     {
         for (int row = 0; row < 9; row++)
         {
             for (int col = 0; col < 9; col++)
             {
                 for (int azimuth = 0; azimuth < 9; azimuth++)
                 {
                     if (cubeCells[cube, row, col, azimuth].GetIsClue() != true && fc.GetCubeCells()[cube, row, col, azimuth].GetIsClue() != true)
                     {
                         newCubeCells[cube, row, col, azimuth] = new CubeCell();
                         newCubeCells[cube, row, col, azimuth].SetConfidence(cubeCells[cube, row, col, azimuth].GetConfidence() - fc.GetCubeCells()[cube, row, col, azimuth].GetConfidence());
                     }
                     else
                     {
                         newCubeCells[cube, row, col, azimuth] = new CubeCell(cubeCells[cube, row, col, azimuth].GetConfidence(), true);
                     }
                 }
             }
         }
     }
     return(new FourCube(newCubeCells));
 }
Ejemplo n.º 3
0
        //equalizer
        public FourCube Equalizer()
        {
            Column[,,] equalizerColumns = new Column[9, 9, 9];
            //extract and perform equalizer on cloumns
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    for (int azimuth = 0; azimuth < 9; azimuth++)
                    {
                        CubeCell[] equalizedCubeCells = new CubeCell[4];
                        for (int cube = 0; cube < 4; cube++)
                        {
                            equalizedCubeCells[cube] = cubeCells[cube, row, col, azimuth];
                        }
                        Column c = new Column(equalizedCubeCells);
                        equalizerColumns[row, col, azimuth] = c.Equalizer();
                    }
                }
            }

            //create a blank fourcube
            CubeCell[,,,] newCubeCells = new CubeCell[4, 9, 9, 9];
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    for (int azimuth = 0; azimuth < 9; azimuth++)
                    {
                        for (int cube = 0; cube < 4; cube++)
                        {
                            newCubeCells[cube, row, col, azimuth] = cubeCells[cube, row, col, azimuth].Copy();
                        }
                    }
                }
            }

            //replace in a new fourcube
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    for (int azimuth = 0; azimuth < 9; azimuth++)
                    {
                        for (int cube = 0; cube < 4; cube++)
                        {
                            newCubeCells[cube, row, col, azimuth] = equalizerColumns[row, col, azimuth].GetCubeCells()[cube];
                        }
                    }
                }
            }

            return(new FourCube(newCubeCells));
        }
 public FourCube(int [,] Sudoku)
 {
     /*Init all the cubcells with conf = 0 and clue = false*/
     for (int c = 0; c < 4; c++)
     {
         for (int row = 0; row < 9; row++)
         {
             for (int column = 0; column < 9; column++)
             {
                 for (int azimuthal = 0; azimuthal < 9; azimuthal++)
                 {
                     cubeCells[c, azimuthal, column, row] = new CubeCell
                     {
                         confidence = 0,
                         isClue     = false
                     };
                 }
             }
         }
     }
     for (int c = 0; c < 4; c++)
     {
         for (int row = 0; row < 9; row++)
         {
             for (int column = 0; column < 9; column++)
             {
                 for (int azimuthal = 0; azimuthal < 9; azimuthal++)
                 {
                     if (Sudoku[row, column] != 0 && azimuthal != Sudoku[row, column] - 1)
                     {
                         cubeCells[c, azimuthal, column, row] = new CubeCell
                         {
                             confidence = 0,
                             isClue     = true
                         };
                     }
                     else if (Sudoku[row, column] != 0 && azimuthal == Sudoku[row, column] - 1)
                     {
                         int digit = Sudoku[row, column];
                         SetRowCubeCells(row, digit, c, column);
                         SetColumnCubeCells(column, digit, c, row);
                         SetBlockCubeCells(digit, row, column, c);
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 //constructor
 public FourCube()
 {
     cubeCells = new CubeCell[4, 9, 9, 9];
     for (int row = 0; row < 9; row++)
     {
         for (int col = 0; col < 9; col++)
         {
             for (int azimuth = 0; azimuth < 9; azimuth++)
             {
                 for (int cube = 0; cube < 4; cube++)
                 {
                     cubeCells[cube, row, col, azimuth] = new CubeCell();
                 }
             }
         }
     }
 }
 private void SetColumnCubeCells(int column, int digit, int cc, int row) //[cube numebr] [azimuthal] [columm] [row]
 {
     for (int r = 0; r < 9; r++)
     {
         if (r == row)
         {
             cubeCells[cc, digit - 1, column, r] = new CubeCell
             {
                 confidence = 1,
                 isClue     = true
             };
         }
         else
         {
             cubeCells[cc, digit - 1, column, r] = new CubeCell
             {
                 confidence = 0,
                 isClue     = true
             };
         }
     }
 }
 private void SetRowCubeCells(int row, int digit, int cc, int col)  //[cube numebr] [azimuthal] [columm] [row]
 {
     for (int column = 0; column < 9; column++)
     {
         if (column == col)
         {
             cubeCells[cc, digit - 1, column, row] = new CubeCell
             {
                 confidence = 1,
                 isClue     = true
             };
         }
         else
         {
             cubeCells[cc, digit - 1, column, row] = new CubeCell
             {
                 confidence = 0,
                 isClue     = true
             };
         }
     }
 }
Ejemplo n.º 8
0
        //equalizer
        public Column Equalizer()
        {
            double sum = 0;

            CubeCell[] newCells = new CubeCell[4];
            for (int i = 0; i < cubeCells.Length; i++)
            {
                sum += cubeCells[i].GetConfidence();
            }

            for (int i = 0; i < cubeCells.Length; i++)
            {
                if (cubeCells[i].GetIsClue() == true)
                {
                    newCells[i] = new CubeCell(sum / 4, true);
                }
                else
                {
                    newCells[i] = new CubeCell(sum / 4, false);
                }
            }
            return(new Column(newCells));
        }
Ejemplo n.º 9
0
        //selector
        public Column Selector()
        {
            CubeCell[] newCells = new CubeCell[9];
            CubeCell   winner   = cubeCells[0];

            for (int i = 1; i < 10; i++)
            {
                if (winner.GetIsClue() == true && winner.GetConfidence() == 1)
                {
                    newCells[i - 1] = new CubeCell(1, true);
                    if (i < 9)
                    {
                        for (int j = i; j < 9; j++)
                        {
                            newCells[j] = cubeCells[j].Copy();
                        }
                    }

                    break;
                }
                else if (winner.GetIsClue() == true && winner.GetConfidence() == 0)
                {
                    newCells[i - 1] = winner.Copy();
                    winner          = cubeCells[i];
                }
                else if (winner.GetIsClue() != true)
                {
                    int nrOfNonClueCellWithBiggerConfidence = 0;
                    for (int j = i; j < 9; j++)
                    {
                        if (cubeCells[j].GetIsClue() == false && winner.GetConfidence() < cubeCells[j].GetConfidence())
                        {
                            nrOfNonClueCellWithBiggerConfidence++;
                        }
                    }

                    if (nrOfNonClueCellWithBiggerConfidence == 0)
                    {
                        newCells[i - 1] = new CubeCell(1, false);
                        for (int j = i; j < 9; j++)
                        {
                            if (cubeCells[j].GetIsClue() == false)
                            {
                                newCells[j] = new CubeCell(0, false);
                            }
                            else
                            {
                                newCells[j] = cubeCells[j].Copy();
                            }
                        }
                        break;
                    }
                    else
                    {
                        newCells[i - 1] = new CubeCell(0, false);
                        winner          = cubeCells[i];
                    }
                }
            }
            return(new Column(newCells));
        }
        private void SetBlockCubeCells(int digit, int row, int column, int cn) //[cube numebr] [azimuthal] [columm] [row]
        {
            int rowRange    = 0;
            int columnRange = 0;
            int blockPart   = 0;

            //checking the row rang
            if (row <= 2)
            {
                rowRange = 0;
            }
            else if (row <= 5 && row >= 3)
            {
                rowRange = 1;
            }
            else if (row >= 6)
            {
                rowRange = 2;
            }
            //checing the column range
            if (column <= 2)
            {
                columnRange = 0;
            }
            else if (column <= 5 && column >= 3)
            {
                columnRange = 1;
            }
            else if (column >= 6)
            {
                columnRange = 2;
            }
            //assining the block part
            if (rowRange == 0 && columnRange == 0)
            {
                blockPart = 0;
            }
            else if (rowRange == 0 && columnRange == 1)
            {
                blockPart = 1;
            }
            else if (rowRange == 0 && columnRange == 2)
            {
                blockPart = 2;
            }
            else if (rowRange == 1 && columnRange == 0)
            {
                blockPart = 3;
            }
            else if (rowRange == 1 && columnRange == 1)
            {
                blockPart = 4;
            }
            else if (rowRange == 1 && columnRange == 2)
            {
                blockPart = 5;
            }
            else if (rowRange == 2 && columnRange == 0)
            {
                blockPart = 6;
            }
            else if (rowRange == 2 && columnRange == 1)
            {
                blockPart = 7;
            }
            else if (rowRange == 2 && columnRange == 2)
            {
                blockPart = 8;
            }
            //filling cubeCells parameter in its cube part
            switch (blockPart)
            {
            case 0:
                for (int r = 0; r < 3; r++)
                {
                    for (int c = 0; c < 3; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 1:
                for (int r = 0; r < 3; r++)
                {
                    for (int c = 3; c < 6; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 2:
                for (int r = 0; r < 3; r++)
                {
                    for (int c = 6; c < 9; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 3:
                for (int r = 3; r < 6; r++)
                {
                    for (int c = 0; c < 3; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 4:
                for (int r = 3; r < 6; r++)
                {
                    for (int c = 3; c < 6; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 5:
                for (int r = 3; r < 6; r++)
                {
                    for (int c = 6; c < 9; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 6:
                for (int r = 6; r < 9; r++)
                {
                    for (int c = 0; c < 3; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 7:
                for (int r = 6; r < 9; r++)
                {
                    for (int c = 3; c < 6; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;

            case 8:
                for (int r = 6; r < 9; r++)
                {
                    for (int c = 6; c < 9; c++)
                    {
                        if (r == row && c == column)
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 1,
                                isClue     = true
                            };
                        }
                        else
                        {
                            cubeCells[cn, digit - 1, c, r] = new CubeCell
                            {
                                confidence = 0,
                                isClue     = true
                            };
                        }
                    }
                }
                break;
            }
        }//end of SetBlockCubeCells
Ejemplo n.º 11
0
 public FourCube(SudokuGrid sudokuGrid)
 {
     this.originalSudokuGrid = sudokuGrid;
     cubeCells = new CubeCell[4, 9, 9, 9];
     for (int row = 0; row < 9; row++)
     {
         for (int col = 0; col < 9; col++)
         {
             for (int azimuth = 0; azimuth < 9; azimuth++)
             {
                 for (int cube = 0; cube < 4; cube++)
                 {
                     cubeCells[cube, row, col, azimuth] = new CubeCell();
                 }
             }
         }
     }
     for (int row = 0; row < 9; row++)
     {
         for (int col = 0; col < 9; col++)
         {
             if (originalSudokuGrid.GetCells()[row, col] != 0)
             {
                 int azimuthalIndex = originalSudokuGrid.GetCells()[row, col] - 1;
                 for (int cube = 0; cube < 4; cube++)
                 {
                     cubeCells[cube, row, col, azimuthalIndex] = new CubeCell(1, true);
                     for (int i = 0; i < 9; i++)
                     {
                         int baseRowIndex = (row / 3) * 3;
                         int offsetRow    = i / 3;
                         int baseColIndex = (col / 3) * 3;
                         int offsetCol    = i % 3;
                         //block
                         if (baseRowIndex + offsetRow != row && baseColIndex + offsetCol != col)
                         {
                             cubeCells[cube, baseRowIndex + offsetRow, baseColIndex + offsetCol, azimuthalIndex] = new CubeCell(0, true);
                         }
                         //row
                         if (i != row)
                         {
                             cubeCells[cube, i, col, azimuthalIndex] = new CubeCell(0, true);
                         }
                         //col
                         if (i != col)
                         {
                             cubeCells[cube, row, i, azimuthalIndex] = new CubeCell(0, true);
                         }
                         //azimuth
                         if (i != azimuthalIndex)
                         {
                             cubeCells[cube, row, col, i] = new CubeCell(0, true);
                         }
                     }
                 }
             }
             else
             {
                 for (int cube = 0; cube < 4; cube++)
                 {
                     for (int azimuthalIndex = 0; azimuthalIndex < 9; azimuthalIndex++)
                     {
                         //cubeCells[cube, row, col, azimuthalIndex].GetIsClue() != true
                         if (cubeCells[cube, row, col, azimuthalIndex].GetIsClue() != true)
                         {
                             cubeCells[cube, row, col, azimuthalIndex] = new CubeCell();
                         }
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 12
0
        ////selector
        public FourCube Selector()
        {
            CubeCell[,,,] newCubeCells = new CubeCell[4, 9, 9, 9];
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    for (int azimuth = 0; azimuth < 9; azimuth++)
                    {
                        for (int cube = 0; cube < 4; cube++)
                        {
                            newCubeCells[cube, row, col, azimuth] = cubeCells[cube, row, col, azimuth].Copy();
                        }
                    }
                }
            }

            //row
            Column[,] rowColumns = new Column[9, 9];
            for (int row = 0; row < 9; row++)
            {
                for (int azimuth = 0; azimuth < 9; azimuth++)
                {
                    CubeCell[] cellsForSelect = new CubeCell[9];
                    for (int col = 0; col < 9; col++)
                    {
                        cellsForSelect[col] = cubeCells[0, row, col, azimuth];
                    }
                    Column c = new Column(cellsForSelect);
                    rowColumns[row, azimuth] = c.Selector();
                }
            }

            //replace rows in a new 4-dimensional array
            for (int row = 0; row < 9; row++)
            {
                for (int azimuth = 0; azimuth < 9; azimuth++)
                {
                    for (int col = 0; col < 9; col++)
                    {
                        newCubeCells[0, row, col, azimuth] = rowColumns[row, azimuth].GetCubeCells()[col];
                    }
                }
            }

            //column
            Column[,] columnColumns = new Column[9, 9];
            for (int col = 0; col < 9; col++)
            {
                for (int azimuth = 0; azimuth < 9; azimuth++)
                {
                    CubeCell[] cellsForSelect = new CubeCell[9];
                    for (int row = 0; row < 9; row++)
                    {
                        cellsForSelect[row] = cubeCells[1, row, col, azimuth];
                    }
                    Column c = new Column(cellsForSelect);
                    columnColumns[col, azimuth] = c.Selector();
                }
            }

            //replace columns in a new 4-dimensional array
            for (int col = 0; col < 9; col++)
            {
                for (int azimuth = 0; azimuth < 9; azimuth++)
                {
                    for (int row = 0; row < 9; row++)
                    {
                        newCubeCells[1, row, col, azimuth] = columnColumns[col, azimuth].GetCubeCells()[row];
                    }
                }
            }

            //block
            Column[,,] blockColumn = new Column[9, 3, 3];
            for (int azimuth = 0; azimuth < 9; azimuth++)
            {
                for (int row = 0; row < 7; row += 3)
                {
                    for (int col = 0; col < 7; col += 3)
                    {
                        CubeCell[] cellsForSelect = new CubeCell[9];
                        for (int i = 0; i < 9; i++)
                        {
                            int baseRowIndex = (row / 3) * 3;
                            int offsetRow    = i / 3;
                            int baseColIndex = (col / 3) * 3;
                            int offsetCol    = i % 3;

                            cellsForSelect[i] = cubeCells[2, baseRowIndex + offsetRow, baseColIndex + offsetCol, azimuth];
                        }
                        Column c = new Column(cellsForSelect);
                        blockColumn[azimuth, row / 3, col / 3] = c.Selector();
                    }
                }
            }

            //replace the block-column in a new fourcube
            for (int azimuth = 0; azimuth < 9; azimuth++)
            {
                for (int row = 0; row < 7; row += 3)
                {
                    for (int col = 0; col < 7; col += 3)
                    {
                        for (int i = 0; i < 9; i++)
                        {
                            int baseRowIndex = (row / 3) * 3;
                            int offsetRow    = i / 3;
                            int baseColIndex = (col / 3) * 3;
                            int offsetCol    = i % 3;
                            newCubeCells[2, baseRowIndex + offsetRow, baseColIndex + offsetCol, azimuth]
                                = blockColumn[azimuth, row / 3, col / 3].GetCubeCells()[i];
                        }
                    }
                }
            }

            //azimuthal
            Column[,] azimuthalColumns = new Column[9, 9];
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    CubeCell[] cellsForSelect = new CubeCell[9];
                    for (int azimuth = 0; azimuth < 9; azimuth++)
                    {
                        cellsForSelect[azimuth] = cubeCells[3, row, col, azimuth];
                    }
                    Column c = new Column(cellsForSelect);
                    azimuthalColumns[row, col] = c.Selector();
                }
            }

            //replace azimuthal in a new 4-dimensional array
            for (int row = 0; row < 9; row++)
            {
                for (int col = 0; col < 9; col++)
                {
                    for (int azimuth = 0; azimuth < 9; azimuth++)
                    {
                        newCubeCells[3, row, col, azimuth] = azimuthalColumns[row, col].GetCubeCells()[azimuth];
                    }
                }
            }

            return(new FourCube(newCubeCells));
        }