Example #1
0
 public Move(int l,int c, Cell old,Cell newV)
 {
     line=l;
     column = c;
     oldValue = old;
     newValue = newV;
 }
        public override Sudoku generate()
        {
            int level = 1;
            switch (m_level)
            {
                case GameLevel.EASY:
                    level = 1;
                    break;
                case GameLevel.Normal:
                    level = 2;
                    break;
                case GameLevel.HARD:
                    level = 3;
                    break;
                case GameLevel.EXTREM:
                    level = 4;
                    break;
                default:
                    level = 2;
                break;
            }

            SudokuPuzzle gererator = new SudokuPuzzle();
            string sudoku = gererator.GetPuzzle(level);
            string solution = gererator.getPossible();

            Sudoku result = new Sudoku();
            for (int i = 0; i < 9;i++ )
            {
                for (int j = 0; j < 9; j++)
                {
                    int valeur = Int16.Parse(sudoku.Substring(i * 9 + j, 1));
                    CellFlag flags;
                    if (valeur==0)
                    {
                        flags=CellFlag.SAISIE;
                    }else{
                        flags=CellFlag.FIXE;
                    }
                    Cell cell = new Cell(flags, valeur, Int16.Parse(solution.Substring(i * 9 + j, 1)));
                    //cell.CellSolution = Int16.Parse(solution.Substring(i * 9 + j, 1));
                    result.Update(i, j, cell);
                }
            }
            return result;
        }
Example #3
0
        //public void Update(int line_p, int column_p, int value_p)
        //{
        //    Update(line_p, column_p, value_p, false);
        //}
        //public void Update(int line_p, int column_p, int value_p, bool verifieMove)
        //{
        //    if (line_p > m_line || column_p > m_col)
        //        throw new ArgumentOutOfRangeException();
        //    if (verifieMove)
        //    {
        //        if (!IsValidUpdate(line_p, column_p, value_p))
        //            throw new IllegalSudokuMove();
        //    }
        //    int index = line_p * m_col + column_p;
        //    if (m_sudokuGrid[index].CellValeur == 0 || (m_sudokuGrid[index].CellType & CellFlag.SAISIE) == CellFlag.SAISIE)
        //    {
        //        m_sudokuGrid[index] = new Cell();
        //        m_sudokuGrid[index].CellType = CellFlag.SAISIE;
        //        m_sudokuGrid[index].CellValeur = value_p;
        //        hasChanged = true;
        //        if (GridChanged!=null)
        //        {
        //            GridChanged(this, new SudokuMoveEvent(new Update(line_p,column_p,));
        //        }
        //    }
        //}
        public void Update(int line_p, int column_p, Cell value_p)
        {
            if (line_p > m_line || column_p > m_col)
                throw new ArgumentOutOfRangeException();
            int index = line_p * m_col + column_p;

            m_sudokuGrid[index] = value_p;
        }