Ejemplo n.º 1
0
        public void verifyAppearance()
        {
            for (int i = 0; i < this.size; i++)
            {
                for (int j = 0; j < this.size; j++)
                {
                    Cell myCell = grid[i, j];
                    if (!myCell.ExistsInItsEnsemble())
                    {
                        //                       myCell.add(MesEnsembleColumn[j], MesEnsembleLine[i], MesEnsembleSector[indexSector]);
                        grid[i, j] = myCell;
                    }
                    else
                    {
                        error = String.Format("grille : {3} {4}la cellule à l'index {0},{1} a une valeur semblable dans sa ligne, dans sa colonne ou dans son secteur", i, j, this.name, Environment.NewLine);

                        this.Log(ModeText.Error, error);
                        NotifyPropertyChanged("TextLog");

                        this.isValid = false;
                        break;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void verifyIntegrityOfAllSudoku()
        {
            int size = 0;

            using (StreamReader file = new StreamReader(path)) {
                this.delimiter = file.ReadLine();
                do
                {
                    String name     = file.ReadLine();
                    String date     = file.ReadLine();
                    String required = file.ReadLine();
                    size = required.Length;
                    Cell[,] tableCell = new Cell[size, size];

                    String          error             = String.Empty;
                    bool            getError          = false;
                    bool            isFullyOfPoint    = true;
                    List <Ensemble> MesEnsembleLine   = new List <Ensemble>();
                    List <Ensemble> MesEnsembleColumn = new List <Ensemble>();
                    List <Ensemble> MesEnsembleSector = new List <Ensemble>();

                    Cell myCell;
                    int  numberOfDots = 0;
                    for (int i = 0; i < size; i++)
                    {
                        verifyEnsemble(MesEnsembleLine, i);
                        String[] tempLine = Utility.SplitWithSeparatorEmpty(file.ReadLine());
                        for (int j = 0; j < size; j++)
                        {
                            verifyEnsemble(MesEnsembleColumn, j);

                            double sqrtNumber  = Math.Sqrt((Convert.ToDouble(size)));
                            int    indexSector = ((int)(Math.Floor(i / sqrtNumber) * sqrtNumber + Math.Floor(j / sqrtNumber)));
                            verifyEnsemble(MesEnsembleSector, indexSector);
                            myCell = new Cell(MesEnsembleColumn[j], MesEnsembleLine[i], MesEnsembleSector[indexSector], tempLine[j], new List <String>(Utility.SplitWithSeparatorEmpty(required)), i, j, this.observers);;

                            if (required.Contains(tempLine[j]) || tempLine[j].Equals("."))
                            {
                                if (!tempLine[j].Equals("."))
                                {
                                    isFullyOfPoint = false;
                                }
                                else
                                {
                                    numberOfDots++;
                                }

                                tableCell[i, j] = myCell;
                                if (!myCell.ExistsInItsEnsemble())
                                {
                                    myCell.addItsEnsemble();
                                }
                                else
                                {
                                    if (getError == false)
                                    {
                                        getError = true;
                                        error    = String.Format("grille : {2} {3}la cellule à l'index ({0} , {1}) a une valeur semblable dans sa ligne, dans sa colonne ou dans son secteur", i, j, name, Environment.NewLine);
                                    }
                                }
                            }
                            else
                            {
                                if (getError == false)
                                {
                                    error    = String.Format("grill : {0} {1} la cellule à l'index ({2}, {3}) n'est pas comprise dans les valeurs requises {4} {5}, Values {6}", name, Environment.NewLine, i, j, required, Environment.NewLine, tempLine[j]);
                                    getError = true;
                                }
                            }
                        }
                    }


                    List <String> maListe = new List <string>(Utility.SplitWithSeparatorEmpty(required));
                    this.ModelList.Add(new CellsGrid(tableCell, maListe, date, name, this.observers));
                    this.ModelList.Last().numberOfDots = numberOfDots;
                    GridSelected = this.modelList.Last();
                    this.Log(ModeText.Warning, GridSelected.name);
                    //  Console.Out.WriteLine( this.modelList.Last().ToString());

                    if (!error.Equals(String.Empty))
                    {
                        this.modelList.Last().isValid = false;
                        this.Log(ModeText.Warning, error);
                        getError = true;
                    }

                    if ((Convert.ToInt32(Math.Floor(Math.Sqrt(this.modelList.Last().size)))) != Convert.ToInt32(Math.Sqrt(this.modelList.Last().size)))
                    {
                        this.modelList.Last().isValid = false;
                        error = "(format non supporté, devrait être 9x9, 16x16 ou 25x25).";
                        this.Log(ModeText.Warning, error);
                        this.modelList.Last().error += error;
                    }
                    else
                    {
                        if (isFullyOfPoint == true)
                        {
                            this.modelList.Last().isValid = false;
                            error = "c'est une grille de point.";
                            this.Log(ModeText.Warning, error);
                            this.modelList.Last().error += error;
                        }
                        else
                        {
                            this.modelList.Last().isValid = true;
                        }
                    }

                    String line = String.Empty;
                    do
                    {
                        line = file.ReadLine();
                        if (string.IsNullOrEmpty(line))
                        {
                            line = String.Empty;
                        }
                    }while (!file.EndOfStream && !line[0].Equals(this.delimiter[0]));

                    this.Log(ModeText.Warning, "next Sudoku");
                }while (!file.EndOfStream);
            }
        }