public override BehaviourTreeStatus Tick() { AdvancedRobot tmpBot = this.bb.Robot; ScannedRobotEvent e = this.bb.CurrentEnemy.E; if (tmpBot.Time % 50 == 0) { //this.bb.MovementDirection *= -1; } if (this.bb.DirectHit) { tmpBot.SetBack(distance); this.bb.DirectHit = false; } if (e == null) { this.bb.Robot.SetTurnRadarRight(360); return(BehaviourTreeStatus.Success); } var gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (this.bb.Robot.Heading - this.bb.Robot.RadarHeading)); // If our target is too far away, turn and move toward it. if (e.Distance > 150) { gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (this.bb.Robot.Heading - this.bb.Robot.RadarHeading)); //tmpBot.SetTurnGunRight(gunTurnAmt); // Try changing these to setTurnGunRight, tmpBot.SetTurnLeft(normaliseBearing(e.Bearing + 90 - (15 * this.bb.MovementDirection))); // and see how much Tracker improves... // (you'll have to make Tracker an AdvancedRobot) tmpBot.SetAhead((e.Distance - 140) * this.bb.MovementDirection); return(BehaviourTreeStatus.Success); } // Our target is close. gunTurnAmt = Utils.NormalRelativeAngleDegrees(e.Bearing + (this.bb.Robot.Heading - this.bb.Robot.RadarHeading)); //tmpBot.SetTurnGunRight(gunTurnAmt); // Our target is too close! Back up. if (e.Distance < 100) { tmpBot.SetTurnLeft(normaliseBearing(e.Bearing + 90 - (15 * this.bb.MovementDirection))); // and see how much Tracker improves... this.bb.MovementDirection = 1; if (e.Bearing > -90 && e.Bearing <= 90) { this.bb.Robot.SetBack(distance * this.bb.MovementDirection); } else { this.bb.Robot.SetAhead(distance * this.bb.MovementDirection); } } //tmpBot.Ahead(distance * r); return(BehaviourTreeStatus.Success); }
internal void SetScannedRobot(ScannedRobotEvent evnt) { if (_target == null) { _target = new Enemy(evnt.Name); } if (!_target.Name.Equals(evnt.Name, StringComparison.OrdinalIgnoreCase)) { return; } _target.UpdateState(evnt, _self.X, _self.Y); var offset = Rectify(_target.Bearing + _self.Heading - _self.RadarHeading) * 1.5; _self.SetTurnRadarRight(offset); var power = GetGunPower(); offset = Rectify(_target.Bearing + _self.Heading - _self.GunHeading); // offset = AdjustGunOffset(offset, power); _self.SetTurnGunRight(offset); _self.SetFire(power); // var x = random.Next(_self.SentryBorderSize, (int)_self.BattleFieldWidth - _self.SentryBorderSize); // var y = random.Next(_self.SentryBorderSize, (int)_self.BattleFieldHeight - _self.SentryBorderSize); // var x = random.NextDouble() * (_self.BattleFieldWidth - _self.SentryBorderSize) + _self.SentryBorderSize / 2; // var y = random.NextDouble() * (_self.BattleFieldHeight - _self.SentryBorderSize) + _self.SentryBorderSize / 2; // var distance = Math.Sqrt((x - _self.X) * (x - _self.X) + (y - _self.Y) * (y - _self.Y)); // double angle = Math.Atan((x - _self.X) / (y - _self.Y)) * 180 / Math.PI - _self.Heading; var distance = random.Next(20, 40); double angle = GetMoveAngle(distance); //var tolerance = _self.SentryBorderSize; //if (_target.Distance < tolerance && // (_self.X > tolerance && _self.X < _self.BattleFieldWidth - tolerance) && // (_self.Y > tolerance && _self.Y < _self.BattleFieldHeight - tolerance)) // angle = Rectify(angle + 90); if (_self.TurnRemaining < 1) { _self.SetTurnRight(Rectify(angle)); } if (_self.DistanceRemaining < 10) { _self.SetAhead(distance); } }
public void Move(IEnumerable <Enemy> enemies, Enemy currentTarget, bool beeingHit) { var dest = GetDestination(enemies, currentTarget, false); var angleToTurn = MathHelpers.TurnRobotToPoint(_myRobot, dest); _myRobot.SetTurnRight(angleToTurn); double velocity = UnsafeMovement || beeingHit ? Config.MaxDistancePerTurn : Config.MaxDistancePerTurn / 4; if (Math.Abs(angleToTurn) > 90) { velocity = Config.MaxDistancePerTurn / 4; } _myRobot.SetAhead(velocity); }
public bool DoIt(AdvancedRobot robot) { if (!isSet) { isSet = true; m_startPoint = Geometry.MakePoint(robot.X, robot.Y); robot.SetAhead(10000); } if (robot.GetDistanceTo(m_startPoint) > Distance) { isSet = false; return(false); } //robot.Out.WriteLine("Radius: {0}, Angle: {1}, Velocity: {2}, TurnRemaining: {3}", Radius, Angle, m_maxVelocity, robot.TurnRemaining); return(true); }
/// <summary> /// Moves the robot ahead if there are no walls in the immediate vicinity /// </summary> /// <param name="robotPositionX"></param> /// <param name="robotPositionY"></param> /// <param name="direction"> should be 1 or -1</param> /// <param name="shouldRam"> if true robot will ram lower health enemies</param> /// <returns></returns> internal bool SetMoveAhead(double robotPositionX, double robotPositionY, double direction, bool shouldRam) { var width = _robot.BattleFieldWidth - (_robot.Width / 2); var height = _robot.BattleFieldHeight - (_robot.Height / 2); var velocity = AddBrakeVelocity(Math.Abs(_robot.Velocity)); var x = Math.Round(robotPositionX + Math.Sin(_robot.HeadingRadians) * (velocity * direction + direction)); var y = Math.Round(robotPositionY + Math.Cos(_robot.HeadingRadians) * (velocity * direction + direction)); if (x >= width || x <= (_robot.Width / 2) || y >= height || y <= (_robot.Height / 2)) { return(false); } //TODO ram enemies only if their health is lower _robot.SetAhead(direction * 30); return(true); }
public void Move(IEnumerable <Enemy> enemies, Enemy currentTarget, bool beeingHit) { var dest = GetDestination(enemies, currentTarget, false); var angleToTurn = MathHelpers.TurnRobotToPoint(_myRobot, dest); _myRobot.SetTurnRight(angleToTurn); var distance = Config.MaxDistancePerTurn; if (Math.Abs(angleToTurn) > 40) { distance = Config.MaxDistancePerTurn / 2; } else if (Math.Abs(angleToTurn) > 90) { distance = Config.MaxDistancePerTurn / 4; } _myRobot.SetAhead(distance); }
public bool DoIt(AdvancedRobot robot) { if (!isSet) { isSet = true; m_stopAngle = Utils.NormalAbsoluteAngleDegrees(robot.Heading + Angle); m_maxVelocity = Game.GetMaxVelocity(Radius); robot.MaxVelocity = m_maxVelocity; //robot.MaxTurnRate = robot.SetTurnRight(Angle); robot.SetAhead(1000); } if (robot.TurnRemaining == 0) { isSet = false; return(false); } //robot.Out.WriteLine("Radius: {0}, Angle: {1}, Velocity: {2}, TurnRemaining: {3}", Radius, Angle, m_maxVelocity, robot.TurnRemaining); return(true); }
public void Move(IEnumerable <Enemy> enemies, Enemy currentTarget, bool underAttack) { var dest = GetDestination(enemies, currentTarget, currentTarget?.JustShooted ?? false || underAttack); var angleToTurn = MathHelpers.TurnRobotToPoint(_myRobot, dest); double direction = 1; if (Math.Abs(angleToTurn) >= 120) { angleToTurn = 180 - angleToTurn; direction = -1; } var r = new Random(); _myRobot.SetTurnRight(angleToTurn); _myRobot.SetAhead( (ShouldChangeDirection ? r.Next((int)Config.MaxDistancePerTurn / 2, (int)Config.MaxDistancePerTurn) : Config.MaxDistancePerTurn) * direction); }
public override BehaviourTreeStatus Tick() { if (this.bb.CurrentEnemy == null || this.bb.Robot == null) { return(BehaviourTreeStatus.Failure); } ScannedRobotEvent e = this.bb.CurrentEnemy.E; AdvancedRobot r = this.bb.Robot; if (r.Time % RandomNumber(70, 110) == 0) { this.bb.MovementDirection *= -1; } // Calculate exact location of the robot double absoluteBearing = r.Heading + e.Bearing; double bearingFromGun = Utils.NormalRelativeAngleDegrees(absoluteBearing - r.GunHeading); double bearingFromRadar = Utils.NormalRelativeAngleDegrees(absoluteBearing - r.RadarHeading); //Spiral around our enemy. 90 degrees would be circling it (parallel at all times) double goalDirection = absoluteBearing - Math.PI / 2 * this.bb.MovementDirection; RectangleF fieldRect = new RectangleF(18, 18, (float)r.BattleFieldWidth - 36, (float)r.BattleFieldHeight - 36); while (!fieldRect.Contains((float)r.X + (float)Math.Sin(goalDirection) * 120, (float)r.Y + (float)Math.Cos(goalDirection) * 120)) { goalDirection += this.bb.MovementDirection * .1; //turn a little toward enemy and try again } double turn = Utils.NormalRelativeAngle(goalDirection - r.HeadingRadians); if (Math.Abs(turn) > Math.PI / 2) { turn = Utils.NormalRelativeAngle(turn + Math.PI); r.SetBack(100); //this.bb.MovementDirection = -1; } else { //this.bb.MovementDirection = 1; r.SetAhead(e.Distance - 140); } //r.SetTurnRightRadians(turn); // 80 and 100 make that we move a bit closer every turn. //r.SetAhead((e.Distance - 140) * this.bb.MovementDirection); if (this.bb.MovementDirection > 0) { r.SetTurnRight(Utils.NormalRelativeAngleDegrees(e.Bearing + 80)); } else { r.SetTurnRight(Utils.NormalRelativeAngleDegrees(e.Bearing + 100)); } // If it's close enough, fire! if (Math.Abs(bearingFromGun) <= 4) { //r.SetTurnGunRight(bearingFromGun); //r.SetTurnRadarRight(bearingFromRadar); // keep the radar focussed on the enemy // We check gun heat here, because calling fire() // uses a turn, which could cause us to lose track // of the other robot. // The close the enmy robot, the bigger the bullet. // The more precisely aimed, the bigger the bullet. //Don't fire us into disability, always save .1 if (r.GunHeat == 0 && r.Energy > .2) { //r.Fire(Math.Min(4.5 - Math.Abs(bearingFromGun) / 2 - e.Distance / 250, r.Energy - .1)); } } // otherwise just set the gun to turn. // else { r.SetTurnGunRight(bearingFromGun); r.SetTurnRadarRight(bearingFromRadar); } // Generates another scan event if we see a robot. // We only need to call this if the radar // is not turning. Otherwise, scan is called automatically. if (bearingFromGun == 0) { r.Scan(); } return(BehaviourTreeStatus.Success); }
public override BehaviourTreeStatus Tick() { AdvancedRobot tmpBot = this.bb.Robot; ScannedRobotEvent e = this.bb.CurrentEnemy.E; if (e == null) { return(BehaviourTreeStatus.Failure); } // Stay at right angles to the opponent tmpBot.SetTurnRight(e.Bearing + 90 - 30 * this.bb.MovementDirection); // If the bot has small energy drop, // assume it fired double changeInEnergy = this.bb.PreviousEnergy - e.Energy; if (changeInEnergy >= -3 && changeInEnergy <= 3) { // Dodge! this.bb.MovementDirection = -this.bb.MovementDirection; tmpBot.SetAhead((e.Distance / 4 + 25) * this.bb.MovementDirection); } // When a bot is spotted, // sweep the gun and radar this.bb.GunDirection = -this.bb.GunDirection; //tmpBot.TurnGunRight(360 * this.bb.GunDirection); // Track the energy level this.bb.PreviousEnergy = e.Energy; double xforce = 0; double yforce = 0; double force; double ang; /**The following four lines add wall avoidance. They will only * affect us if the bot is close to the walls due to the * force from the walls decreasing at a power 3.**/ xforce += 5000 / Math.Pow(getRange(tmpBot.X, tmpBot.Y, tmpBot.BattleFieldWidth, tmpBot.Y), 3); xforce -= 5000 / Math.Pow(getRange(tmpBot.X, tmpBot.Y, 0, tmpBot.X), 3); yforce += 5000 / Math.Pow(getRange(tmpBot.X, tmpBot.Y, tmpBot.X, tmpBot.BattleFieldHeight), 3); yforce -= 5000 / Math.Pow(getRange(tmpBot.X, tmpBot.Y, tmpBot.X, 0), 3); double angle = Utils.ToDegrees(absbearing(tmpBot.X, tmpBot.Y, tmpBot.X - xforce, tmpBot.Y - yforce)); double r = turnTo(angle); //distance = RandomNumber(80, 300); tmpBot.SetAhead(distance * r); //this.bb.Robot.Ahead(distance * angle); return(BehaviourTreeStatus.Success); }