コード例 #1
0
ファイル: SandPile.cs プロジェクト: JoeMooreBrk/SandPile
 public void Add(SandPile SBToAdd, bool FullTopple = false)
 {
     if (SBToAdd.Width != Width)
     {
         throw new Exception("Cannot add a sandpile of different width: " + Width + " vs " + SBToAdd.Width);
     }
     if (SBToAdd.Height != Height)
     {
         throw new Exception("Cannot add a sandpile of different height: " + Height + " vs " + SBToAdd.Height);
     }
     for (int thisColNum = 0; thisColNum <= Width - 1; thisColNum++)
     {
         for (int thisRowNum = 0; thisRowNum <= Height - 1; thisRowNum++)
         {
             int thisVal = SBToAdd.SandPileArray[thisColNum, thisRowNum];
             SandPileArray[thisColNum, thisRowNum] += thisVal;
         }
     }
     // After an add, need to check inset.  Only way to ensure that inset follows is to know that what was added was inset.
     if (InSet != InSetStatus.NoCheck)
     {
         InSet = CheckInSet();
     }
     if (FullTopple)
     {
         ToppleMe();
     }
 }
コード例 #2
0
ファイル: SandPile.cs プロジェクト: JoeMooreBrk/SandPile
 private SandPile(
     int[][] Elements,
     int _Width,
     int _Heigh,
     bool isZero,
     InSetStatus _inSet) :
     this(ArrayOfArrays2TwoDim(Elements, _Width, 3), _Width, 3, isZero, _inSet)
 {
 }
コード例 #3
0
ファイル: SandPile.cs プロジェクト: JoeMooreBrk/SandPile
        public InSetStatus CheckInSet()
        {
            if (MyZero == null)
            {
                return(InSetStatus.NoZero);
            }
            InSet = InSetStatus.NoCheck;
            SandPile meCopy = (SandPile)this.Clone();

            meCopy.Add(MyZero);
            if (this.CompareFullyToppled(meCopy) == 0)
            {
                return(InSetStatus.InSet);
            }
            else
            {
                return(InSetStatus.NotInSet);
            }
        }
コード例 #4
0
ファイル: SandPile.cs プロジェクト: JoeMooreBrk/SandPile
 private SandPile(int[,] Elements,
                  int _Width         = 3,
                  int _Height        = 3,
                  bool isZero        = false,
                  InSetStatus _inSet = InSetStatus.Unknown)
 {
     Width  = _Width;
     Height = _Height;
     if (Elements.GetLowerBound(0) != 0)
     {
         throw new Exception("Index of first dimension of array (Width) must be zero");
     }
     if (Elements.GetUpperBound(0) + 1 != Width)
     {
         throw new Exception("Width is " + Width + ". but first dimension of array is " + Elements.GetUpperBound(0) + 1);
     }
     if (Elements.GetLowerBound(1) != 0)
     {
         throw new Exception("Index of 2nd dimension (Height) of array must be zero");
     }
     if (Elements.GetUpperBound(1) + 1 != Height)
     {
         throw new Exception("Height is " + Height + ". but second dimension of array is " + Elements.GetUpperBound(1) + 1);
     }
     SandPileArray = Elements;
     if (!isZero)
     {
         MyZero = GetZero();
     }
     if (_inSet == InSetStatus.Unknown)
     {
         InSet = CheckInSet();
     }
     else
     {
         InSet = _inSet;
     }
 }