当前位置: 首页>>代码示例>>C#>>正文


C# Robocode.ScannedRobotEvent类代码示例

本文整理汇总了C#中Robocode.ScannedRobotEvent的典型用法代码示例。如果您正苦于以下问题:C# ScannedRobotEvent类的具体用法?C# ScannedRobotEvent怎么用?C# ScannedRobotEvent使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ScannedRobotEvent类属于Robocode命名空间,在下文中一共展示了ScannedRobotEvent类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnScannedRobot

        //When the robot sees another
        public override void OnScannedRobot(ScannedRobotEvent evnt)
        {
            /*
            double angleToEnemy = Robocode.Util.Utils.ToRadians(GunHeading) + evnt.BearingRadians;
            double radarTurn = Robocode.Util.Utils.NormalRelativeAngle(angleToEnemy - Robocode.Util.Utils.ToRadians(RadarHeading));
            double extraTurn = Math.Min(Math.Atan(36.0 / evnt.Distance), Rules.RADAR_TURN_RATE_RADIANS);

            radarTurn += (radarTurn < 0 ? -extraTurn : extraTurn);
            TurnRadarRight(Robocode.Util.Utils.ToRadians(radarTurn));
            */

            /*
            if (GunHeading < RadarHeading)
            {
                double diff = RadarHeading - GunHeading;
                TurnGunRight(diff);
                TurnRadarLeft(diff);
            }
            else
            {
                double diff = GunHeading - RadarHeading;
                TurnGunLeft(diff);
                TurnRadarRight(diff);
            }
            */
            System.Pr
            Fire(0.1);
        }
开发者ID:NithBeswick,项目名称:Dethbot,代码行数:29,代码来源:Deth.cs

示例2: Aim

        public void Aim(ScannedRobotEvent evnt)
        {
            var enemyAbsoluteBearing = Utilities.GetAbsoluteBearing(_robot.HeadingRadians, evnt.BearingRadians);
            var enemyX = _robot.X + evnt.Distance * Math.Sin(enemyAbsoluteBearing);
            var enemyY = _robot.Y + evnt.Distance * Math.Cos(enemyAbsoluteBearing);
            var enemyVelocity = evnt.Velocity;
            var enemyHeading = evnt.HeadingRadians;

            var A = (enemyX - _robot.X) / enemyVelocity;
            var B = enemyVelocity/enemyVelocity * Math.Sin(enemyHeading);
            var C = (enemyY - _robot.Y) / enemyVelocity;
            var D = enemyVelocity/enemyVelocity * Math.Cos(enemyHeading);

            var a = A * A + C * C;
            var b = 2d * (A * B + C * D);
            var c = (B * B + D * D - 1d);
            var discriminator = b*b - 4*a*c;

            if (discriminator > 0d)
            {
                var t1 = 2 * a / (-b - Math.Sqrt(discriminator));
                var t2 = 2 * a / (-b + Math.Sqrt(discriminator));
                var t = Math.Min(t1, t2) >= 0d ? Math.Min(t1, t2) : Math.Max(t1, t2);

                var valueX = enemyX + enemyVelocity * t * Math.Sin(enemyHeading);
                var endX = Limit(valueX, Utilities.ROBOT_WIDTH/2d, 800d - Utilities.ROBOT_WIDTH/2d);

                var valueY = enemyY + enemyVelocity * t * Math.Cos(enemyHeading);
                var endY = Limit(valueY, Utilities.ROBOT_WIDTH / 2d, 800d - Utilities.ROBOT_WIDTH / 2d);

                var gunTurn = Math.Atan2(endX - _robot.X, endY - _robot.Y) - _robot.GunHeadingRadians;
                _robot.SetTurnGunRightRadians(Utils.NormalRelativeAngle(gunTurn));
            }
        }
开发者ID:jeffjohnson9046,项目名称:robocode-net,代码行数:34,代码来源:AnotherTargeter.cs

示例3: OnScannedRobot

        /// <summary>
        ///   Fire when we see a robot
        /// </summary>
        public override void OnScannedRobot(ScannedRobotEvent e)
        {
            // demonstrate feature of debugging properties on RobotDialog
            DebugProperty["lastScannedRobot"] = e.Name + " at " + e.Bearing + " degrees at time " + Time;

            Fire(1);
        }
开发者ID:khangnguyen,项目名称:robocode,代码行数:10,代码来源:PaintingRobot.cs

示例4: OnScannedRobotBehavior

        public void OnScannedRobotBehavior(ScannedRobotEvent enemy)
        {
            Console.WriteLine("On scanned robot");
            Robot.Stop();
            double fireStrength = 3;
            if (enemy.Distance < 200)
            {
                Robot.Fire(fireStrength);
                Robot.Scan();
            }
            if (enemy.Heading > Robot.Heading)
            {
                Robot.TurnTo((enemy.Heading - Robot.Heading) + enemy.Velocity * 5, Helpers.TurnType.Robot);
            }
            else
            {
                Robot.TurnTo((Robot.Heading - enemy.Heading) + enemy.Velocity * 5, Helpers.TurnType.Robot);
            }
            if (enemy.Distance > 100)
            {
                Robot.Ahead(enemy.Distance / 2);
            }
            Robot.Scan();
            //this.SetTurnGunRight(10);
            //this.SetTurnGunRight(20);

            //Scan();
            Robot.Resume();
        }
开发者ID:brettwgreen,项目名称:Robocode,代码行数:29,代码来源:OrbisBehavior.cs

示例5: OnScannedRobot

        /// <summary>
        ///   onScannedRobot:  We have a target.  Go get it.
        /// </summary>
        public override void OnScannedRobot(ScannedRobotEvent e)
        {
            if (e.Name.ToLower().StartsWith("jury")) return;
            Console.WriteLine(e.Name);
            // Calculate exact location of the robot
            double absoluteBearing = Heading + e.Bearing;
            double bearingFromGun = Utils.NormalRelativeAngleDegrees(absoluteBearing - GunHeading);

            // If it's close enough, fire!
            if (Math.Abs(bearingFromGun) <= 3)
            {
                TurnGunRight(bearingFromGun);
                // We check gun heat here, because calling Fire()
                // uses a turn, which could cause us to lose track
                // of the other robot.
                if (GunHeat == 0)
                {
                    Fire(Math.Min(3 - Math.Abs(bearingFromGun), Energy - .1));
                }
            }
            else
            {
                // otherwise just set the gun to turn.
                // Note:  This will have no effect until we call scan()
                TurnGunRight(bearingFromGun);
            }
            // Generates another scan event if we see a robot.
            // We only need to call this if the gun (and therefore radar)
            // are not turning.  Otherwise, scan is called automatically.
            if (bearingFromGun == 0)
            {
                Scan();
            }
        }
开发者ID:kontur-edu,项目名称:intern-2014,代码行数:37,代码来源:EvilTrack.cs

示例6: OnScannedRobot

 public override void OnScannedRobot(ScannedRobotEvent e)
 {
     SetTurnRadarLeft(RadarTurnRemaining);
     SetTurnGunRightRadians(
         Utils.NormalRelativeAngle(e.BearingRadians + HeadingRadians - GunHeadingRadians));
     SetFire(3);
 }
开发者ID:EamonnACI,项目名称:ACI-SpaceRace,代码行数:7,代码来源:FairPlay.cs

示例7: OnScannedRobot

        public override void OnScannedRobot(ScannedRobotEvent e)
        {
            if (IsTeammate(e.Name))
            {
                return;
            }

            if (e.Distance < 300)
            {
                Fire(Rules.MAX_BULLET_POWER);
            }
            else
            {
                Fire(1);
                SetAhead(100);
                Fire(Rules.MAX_BULLET_POWER);
                SetAhead(100);
                Fire(Rules.MAX_BULLET_POWER);
            }

            if (e.Energy > 50 && Energy < 50)
            {
                mode = "huiga";
            }
        }
开发者ID:rlamunoz,项目名称:DotNetRobocode,代码行数:25,代码来源:Demoledor.cs

示例8: OnScannedRobot

        public override void OnScannedRobot(ScannedRobotEvent e)
        {
            // Calculate exact location of the robot
            double absoluteBearing = Heading + e.Bearing;
            double bearingFromGun = Utils.NormalRelativeAngle(absoluteBearing - GunHeading);

            // If it's close enough, fire!
            if (Math.Abs(bearingFromGun) <= 3)
            {
                TurnGunRight(bearingFromGun);
                // We check gun heat here, because calling Fire()
                // uses a turn, which could cause us to lose track
                // of the other robot.
                if (GunHeat == 0 && bullet == null)
                {
                    Bullet lbullet = FireBullet(Math.Min(3 - Math.Abs(bearingFromGun), Energy - .1));

                    bullet = lbullet;
                }
            } // otherwise just set the gun to turn.
                // Note:  This will have no effect until we call Scan()
            else
            {
                TurnGunRight(bearingFromGun);
            }
            // Generates another scan event if we see a robot.
            // We only need to call this if the gun (and therefore radar)
            // are not turning.  Otherwise, scan is called automatically.
            if (bearingFromGun == 0)
            {
                Scan();
            }
        }
开发者ID:markthor,项目名称:robocode,代码行数:33,代码来源:WatchBullets.cs

示例9: SetEnemyData

		public void SetEnemyData(ScannedRobotEvent newEnemyData,
								 Point2D newPosition)
		{
			// First we set the stuff that depends on last updates' values:
			long deltaTime = newEnemyData.Time - Time;
			TurnRateRadians = Utils.NormalRelativeAngle(newEnemyData.HeadingRadians - HeadingRadians) / deltaTime;
			Acceleration = (newEnemyData.Velocity - Velocity) / deltaTime;

			// General data:
			Time = newEnemyData.Time;
			
			// Compared-to-us data:
			BearingRadians = newEnemyData.BearingRadians;
			Distance = newEnemyData.Distance;

			// Enemy specific data:
			Name = newEnemyData.Name;
			Energy = newEnemyData.Energy;
			Position = newPosition;
			Velocity = newEnemyData.Velocity;
			HeadingRadians = newEnemyData.HeadingRadians;

			//La til en LockOn, som blir true vær gang radaren har gått over motstanderne.
			LockOn = true;
		}
开发者ID:Alexander144,项目名称:Robocode-Dr.Robo,代码行数:25,代码来源:EnemyData.cs

示例10: OnScannedRobot

 public override void OnScannedRobot(ScannedRobotEvent e)
 {
     // We fire the gun with bullet power = 1
     Fire(Rules.MAX_BULLET_POWER);
     double angle = degtorad(Heading);
     // Calculate the coordinates of the robot
     targetX = (int)(X + Math.Sin(angle) * e.Distance);
     targetY = (int)(Y + Math.Cos(angle) * e.Distance);
 }
开发者ID:stdcallua,项目名称:Robots,代码行数:9,代码来源:Dog.cs

示例11: OnScannedRobot

 public override void OnScannedRobot(ScannedRobotEvent evnt)
 {
     // Enemy attributes
     lastEnemyVelocity = evnt.Velocity;
     lastEnemyEnergy = evnt.Energy;
     lastEnemyHeading = evnt.Heading;
     lastEnemyBearing = evnt.Bearing;
     lastEnemyDistance = evnt.Distance;
     RunProgram(TableRexPrograms.onScannedRobot);
 }
开发者ID:aladaris,项目名称:GeisenBots,代码行数:10,代码来源:EisenBot.cs

示例12: OnScannedRobot

        public override void OnScannedRobot(ScannedRobotEvent e)
        {
            if (IsTeammate(e.Name))
            {
                return;
            }

            if (_shotsFired < 3)
            {

                double angleToEnemy = e.Bearing;
                // Calculate the angle to the scanned robot
                double angle = DegreeToRadian(_robotStatus.Heading + angleToEnemy % 360);
                Console.WriteLine(angle);

                // Calculate the coordinates of the robot
                double enemyX = (_robotStatus.X + Math.Sin(angle) * e.Distance);
                double enemyY = (_robotStatus.Y + Math.Cos(angle) * e.Distance);

                // calculate firepower based on distance
                double firePower = Math.Min(500 / e.Distance, 3);
                // calculate speed of bullet
                double bulletSpeed = 20 - firePower * 3;
                // distance = rate * time, solved for time
                long time = (long)(e.Distance / bulletSpeed);

                // calculate gun turn to predicted x,y location
                double futureX = GetEstimatedXPosition(enemyX, e.Velocity, e.Heading, time);
                double futureY = GetEstimatedXPosition(enemyY, e.Velocity, e.Heading, time);

                //double absDeg = AbsoluteBearing(X, Y, futureX, futureY);
                double absDeg = AbsoluteBearing(X, Y, enemyX, enemyY);
                // non-predictive firing can be done like this:
                //double absDeg = absoluteBearing(getX(), getY(), enemy.getX(), enemy.getY());

                // turn the gun to the predicted x,y location
                TurnGunRight(NormalizeBearing(absDeg - GunHeading));

                //TurnGunRight(Heading - GunHeading + e.Bearing);
                // if the gun is cool and we're pointed at the target, shoot!
                if (GunHeat == 0)
                {
                    Fire(Math.Min(400 / e.Distance, 4));
                }
                else
                {
                    TurnRight(e.Bearing);
                }

            }
            else
            {
                _shotsFired = 0;
            }
        }
开发者ID:rlamunoz,项目名称:DotNetRobocode,代码行数:55,代码来源:Franzer.cs

示例13: BotState

        public BotState(Robot bot, ScannedRobotEvent evnt)
        {
            var direction = bot.Heading + evnt.Bearing;

            this.Observer = bot;
            this.Energy = evnt.Energy;
            this.Location = Geometry.ShiftBy(bot.GetLocation(), direction, evnt.Distance, bot.GetArenaBounds());
            this.Heading = evnt.Heading;
            this.Velocity = evnt.Velocity;
            this.Turn = bot.Time;
        }
开发者ID:AdmiralRasmussen,项目名称:StyleAndGrace,代码行数:11,代码来源:BotState.cs

示例14: OnScannedRobot

        /// <summary>
        /// Determine what to do when another robot is detected by our radar.
        /// </summary>
        /// <param name="evnt">The <c>ScannedRobotEvent</c> args containing data about the robot that
        /// was detected.</param>
        public override void OnScannedRobot(ScannedRobotEvent evnt)
        {
            _treads.MakeDefensiveMove(evnt, _enemyPreviousEnergy);

            _sensors.Scan(evnt);

            _gun.Aim(evnt);

            var bulletPower = _gun.GetBulletPower(evnt);
            _gun.Fire(bulletPower);
        }
开发者ID:jeffjohnson9046,项目名称:robocode-net,代码行数:16,代码来源:OGRE_Test.cs

示例15: OnScannedRobot

 /// <summary>
 ///   onScannedRobot:  Fire!
 /// </summary>
 public override void OnScannedRobot(ScannedRobotEvent e)
 {
     Fire(2);
     // Note that scan is called automatically when the robot is moving.
     // By calling it manually here, we make sure we generate another scan event if there's a robot on the next
     // wall, so that we do not start moving up it until it's gone.
     if (peek)
     {
         Scan();
     }
 }
开发者ID:vodkhang,项目名称:RoboCode-Robots,代码行数:14,代码来源:Walls.cs


注:本文中的Robocode.ScannedRobotEvent类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。