コード例 #1
0
ファイル: Potential.cs プロジェクト: coni2k/SS
 internal Potential(Square square, Group group, Number number,PotentialTypes potentialType)
 {
     this.Square = square;
     this.SquareGroup = group;
     this.Number = number;
     this.PotentialType = potentialType;
 }
コード例 #2
0
ファイル: Square.cs プロジェクト: coni2k/SS
        internal Square(int id, Number number, Sudoku sudoku, Group horizantolGroup, Group verticalGroup, Group squareGroup)
        {
            this.Id = id;
            this.Fill(number, FillTypes.None);
            this.Sudoku = sudoku;

            //Groups
            _SquareGroups.Add(horizantolGroup);
            _SquareGroups.Add(verticalGroup);
            _SquareGroups.Add(squareGroup);
            //this.HorizontalTypeGroup = horizantolGroup;
            //this.VerticalTypeGroup = verticalGroup;
            //this.SquareTypeGroup = squareGroup;

            //Available numbers; assign all number, except zero
            _AvailableNumbers = new List<Number>(this.Sudoku.Size);
            foreach (var availableNumber in this.Sudoku.AllNumbersExceptZero)
                _AvailableNumbers.Add(availableNumber);
        }
コード例 #3
0
ファイル: Sudoku.cs プロジェクト: coni2k/SS
        void Init(int size)
        {
            //Id
            //this.Id = Guid.NewGuid();

            //Size
            this.Size = size;

            //All numbers; numbers will be created as the size of the sudoku (default 9 + zero value = 10)
            _AllNumbers = new List<Number>(Size + 1);

            //Zero first
            var zeroNumber = new Number(this, 0);
            _AllNumbers.Add(zeroNumber);

            //Other numbers
            for (int i = 1; i <= Size; i++)
            {
                var number = new Number(this, i);
                _AllNumbers.Add(number);
            }

            //All square groups
            _AllHorizontalTypeGroups = new List<Group>(Size);
            _AllVerticalTypeGroups = new List<Group>(Size);
            _AllSquareTypeGroups = new List<Group>(Size);

            for (int i = 1; i <= Size; i++)
            {
                //Generate the groups
                var horizontalGroup = new Group(i, GroupTypes.Horizontal, this);
                var verticalGroup = new Group(i, GroupTypes.Vertical, this);
                var squareGroup = new Group(i, GroupTypes.Square, this);

                //Register the events
                horizontalGroup.PotentialFound += new Potential.FoundEventHandler(PotentialSquare_Found);
                verticalGroup.PotentialFound += new Potential.FoundEventHandler(PotentialSquare_Found);
                squareGroup.PotentialFound += new Potential.FoundEventHandler(PotentialSquare_Found);

                //Add to the "all" lists
                _AllHorizontalTypeGroups.Add(horizontalGroup);
                _AllVerticalTypeGroups.Add(verticalGroup);
                _AllSquareTypeGroups.Add(squareGroup);
            }

            //All squares
            _AllSquares = new List<Square>(TotalSize);
            for (int i = 0; i < TotalSize; i++)
            {
                //Find the indexes of the current square's groups
                int horizontalGroupIndex = i / Size;
                int verticalGroupIndex = (i + 1) % Size == 0 ? Size - 1 : ((i + 1) % Size) - 1;
                int squareGroupIndex = (verticalGroupIndex / SquareRootOfSize) + ((horizontalGroupIndex / SquareRootOfSize) * SquareRootOfSize);

                //Get the groups
                var currentSquareHorizontalGroup = _AllHorizontalTypeGroups[horizontalGroupIndex];
                var currentSquareVerticalGroup = _AllVerticalTypeGroups[verticalGroupIndex];
                var currentSquareSquareGroup = _AllSquareTypeGroups[squareGroupIndex];

                //Generate the squares
                Square square = new Square(i + 1, zeroNumber, this, currentSquareHorizontalGroup, currentSquareVerticalGroup, currentSquareSquareGroup);
                square.NumberChanged += new Square.SquareEventHandler(Square_NumberChanged);
                square.PotentialSquareFound += new Potential.FoundEventHandler(PotentialSquare_Found);
                _AllSquares.Add(square);

                //Add the squares to their own groups
                currentSquareHorizontalGroup.AddSquare(square);
                currentSquareVerticalGroup.AddSquare(square);
                currentSquareSquareGroup.AddSquare(square);
            }

            //Potential squares
            _PotentialSquares = new List<Potential>();
        }