示例#1
0
        /// <summary>
        /// Move the creature one step
        /// </summary>
        /// <param name="water">True if the Creature is in water.</param>
        /// <returns>True if the creature has hit an obstacle in this round</returns>
        private bool MoveOne(out bool water)
        {
            var move = false;

            water = false;

            // First make sure there is no obstacle in the path
            if (CheckCollision())
            {
                if (!_hasHitObject)
                {
                    _hasHitObject = true;
                    return(true);
                }

                while (!move)
                {
                    if (CheckCollision())
                    {
                        Direction = GetRandomDirection();
                        continue;
                    }
                    move          = true;
                    _hasHitObject = false;
                }
            }

            // If there is territory in the next square
            if (_context.Layout.hasTerritory(XPos, YPos, Direction))
            {
                MoveDirection();
            }
            // If there is water in the next square
            else
            {
                // Check if the creature already is in the water
                if (!_context.Layout.hasTerritory(XPos, YPos))
                {
                    water = true;
                    if (Energy >= Species.MovingThreshold)
                    {
                        MoveDirection();
                    }
                }
                // Check if energy is below the swimming threshold
                else if (Energy <= Species.SwimmingThreshold)
                {
                    MoveDirection();
                    water = true;
                }
                else
                {
                    // If the creature does not want to swim yet, get another direction
                    move = false;
                    while (!move)
                    {
                        Direction = GetRandomDirection();
                        if (!_context.Layout.hasTerritory(XPos, YPos, Direction) ||
                            _context.HasSimObjects <Obstacle>(XPos, YPos, Direction))
                        {
                            continue;
                        }
                        move = true;
                        MoveDirection();
                    }
                }
            }
            return(false);
        }
示例#2
0
 public void HasSimObjectsTest()
 {
     Assert.IsTrue(_context.HasSimObjects(51, 56));
     Assert.IsFalse(_context.HasSimObjects(50, 50));
 }