示例#1
0
        /// <summary>
        /// Simulate one iteration of the algorithm
        /// </summary>
        /// <param name="cave"></param>
        /// <returns></returns>
        public Cave doSimulation(Cave cave)
        {
            Cell[,] copyMap = cave._celullarMap;

            for (int x = 0; x < Utility.WIDTH; x++)
            {
                for (int y = 0; y < Utility.HEIGTH; y++)
                {
                    if (!cave.IsBorderCell(x, y))
                    {
                        if (cave._celullarMap[x, y].state == Utility.STATE.Rock)
                        {
                            if (CustomRandomNumberGenerator.GetRandom() < this._growthHorizontalChance)
                            {
                                copyMap[x - 1, y].state = Utility.STATE.Rock;
                            }
                            if (CustomRandomNumberGenerator.GetRandom() < this._growthHorizontalChance)
                            {
                                copyMap[x + 1, y].state = Utility.STATE.Rock;
                            }
                            if (CustomRandomNumberGenerator.GetRandom() < this._growthVerticalChance)
                            {
                                copyMap[x, y + 1].state = Utility.STATE.Rock;
                            }
                        }
                    }
                }
            }

            cave._celullarMap = copyMap;
            return(cave);
        }
 public void NextAction()
 {
     if (this._isAlive)
     {
         if (_age > _maxLifetime)
         {
             this._isAlive = false;
         }
         else if (_age > _minLifetime && _age < _maxLifetime)
         {
             if (CustomRandomNumberGenerator.GetRandom() < _lifetimeDeathChance)
             {
                 this._isAlive = false;
             }
             else
             {
                 Move();
             }
         }
         else
         {
             Move();
         }
         _age++;
     }
 }
 /// <summary>
 /// Initialize the cave by setting random cells to active;
 /// </summary>
 /// <returns>New initialized map</returns>
 public Cave InitializeCave(Cave cave)
 {
     for (int x = 0; x < Utility.WIDTH; x++)
     {
         for (int y = 0; y < Utility.HEIGTH; y++)
         {
             if (!cave.IsBorderCell(x, y))
             {
                 if (CustomRandomNumberGenerator.GetRandom() < this._wallChance)
                 {
                     cave._celullarMap[x, y].state = Utility.STATE.Rock;
                 }
             }
             else
             {
                 cave._celullarMap[x, y].state = Utility.STATE.Rock;
             }
         }
     }
     return(cave);
 }
 private void Move()
 {
     if (this._age == 0)
     {
         this._y--;
     }
     else
     {
         if (CustomRandomNumberGenerator.GetRandom() < _growthChanceNorth)
         {
             this._y--;
         }
         else if (CustomRandomNumberGenerator.GetRandom() < _growthChanceWest)
         {
             this._x--;
         }
         else if (CustomRandomNumberGenerator.GetRandom() < _growthChanceEast)
         {
             this._x++;
         }
     }
 }
        /// <summary>
        /// Initialize the cave by setting random cells to active;
        /// </summary>
        /// <returns>New initialized map</returns>
        public Cave InitializeCave(Cave cave)
        {
            for (int x = 0; x < Utility.WIDTH; x++)
            {
                for (int y = _upperFloorLimit; y < _lowerFloorLimit; y++)
                {
                    if (!cave.IsBorderCell(x, y))
                    {
                        if (!(CustomRandomNumberGenerator.GetRandom() < this._activeChanceOnCrust))
                        {
                            cave._celullarMap[x, y].state = Utility.STATE.Rock;
                        }
                    }
                    else
                    {
                        cave._celullarMap[x, y].state = Utility.STATE.Rock;
                    }
                }

                for (int y = _lowerFloorLimit; y < Utility.HEIGTH; y++)
                {
                    if (!cave.IsBorderCell(x, y))
                    {
                        if (!(CustomRandomNumberGenerator.GetRandom() < this._activeChanceGround))
                        {
                            cave._celullarMap[x, y].state = Utility.STATE.Rock;
                        }
                    }
                    else
                    {
                        cave._celullarMap[x, y].state = Utility.STATE.Rock;
                    }
                }
            }
            return(cave);
        }