Ejemplo n.º 1
0
        /// <summary>
        /// Execute
        /// The second of the two required methods to implement
        /// The BotEngine will call this method once each game cycle allowing us
        /// to implement/execute our robot logic
        ///
        /// The sniper bot simply travels back and forth east and west, changing direction
        /// before hitting the arena wall
        /// </summary>
        public void Execute()
        {
            int range;

            // If speed is zero, start moving
            if (Arena.Speed(this) == 0)
            {
                Arena.Drive(this, Direction, 50);
                Trace("Bot sets speed to 50");
            }

            // If about to hit a wall, change direction 180 degrees
            if (Arena.LocationX(this) < 50 || Arena.LocationX(this) > Arena.ArenaWidth - 50)
            {
                Direction = Direction == 90 ? 270 : 90;
                Arena.Drive(this, Direction, 50);
                Trace(String.Format("Changing direction to {0}", Direction));
            }

            if ((range = Arena.Scan(this, _nextDegree, _resolution)) > 0)
            {
                if (Arena.Cannon(this, _nextDegree, range))
                {
                    Trace(String.Format("Firing Cannon at {0} degrees with a range of {1} Scanner resolution {2}", _nextDegree, range, _resolution));
                }
            }

            _nextDegree += 10;

            if (_nextDegree > 359)
            {
                _nextDegree = 0;
            }
            //Trace(String.Format("Next Degree: {0}", _nextDegree));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Execute
        /// The second of the two required methods to implement
        /// The BotEngine will call this method once each game cycle allowing us
        /// to execute our robot logic
        /// </summary>
        public void Execute()
        {
            // If no target
            if (_closestTarget == 9999)
            {
                _range = Arena.Scan(this, _scanDirection, 1);         // Look at a direction
            }

            // If target
            if (_range <= 700 && _range > 0)
            {
                // Set closestTarget flag
                _closestTarget = _range;

                // Fire!
                Arena.Cannon(this, _scanDirection, _range);

                // Check target again
                _range = Arena.Scan(this, _scanDirection, 1);
            }
            else
            {
                _scanDirection += 2;
                _closestTarget  = 9999;
            }

            // Check for damage incurred and if so, move
            if (_damage != Arena.Damage(this))
            {
                NewCorner();
                _damage        = Arena.Damage(this);
                _scanDirection = _scanStart;
            }

            // Check for any targets in range
            if (!_moving && _closestTarget == 9999)
            {
                // Nothing, move to new corner
                NewCorner();
                _scanDirection = _scanStart;
            }

            _damage = Arena.Damage(this);

            //while (_scanDirection < _scanStart + 90)
            //{
            //    // Scan through 90 degree range
            //    _range = Arena.Scan(this, _scanDirection, 1);         // Look at a direction

            //    if (_range <= 700 && _range > 0)
            //    {
            //        // Keep firing while in range
            //        while (_range > 0)
            //        {
            //            // Set closestTarget flag
            //            _closestTarget = _range;

            //            // Fire!
            //            Arena.Cannon(this, _scanDirection, _range);

            //            // Check target again
            //            _range = Arena.Scan(this, _scanDirection, 1);

            //            // Sustained several hits, go to new corner
            //            if (_damage + 15 > Arena.Damage(this))
            //                _range = 0;
            //        }

            //        // Back up scan, in case
            //        _scanDirection -= 10;
            //    }

            //    // Increment scan
            //    _scanDirection += 2;

            //    // Check for damage incurred and if so, move
            //    if (_damage != Arena.Damage(this))
            //    {
            //        NewCorner();
            //        _damage = Arena.Damage(this);
            //        _scanDirection = _scanStart;
            //    }
            //}

            //// Check for any targets in range
            //if (_closestTarget == 9999)
            //{
            //    // Nothing, move to new corner
            //    NewCorner();
            //    _damage = Arena.Damage(this);
            //    _scanDirection = _scanStart;
            //}
            //// Targets in range, resume
            //else
            //    _scanDirection = _scanStart;

            //_closestTarget = 9999;
        }