public override void Tick(Events events) { if (Time==0) Partner = Center(); CheckPartnerMsgs(); if (ScannedEnemy()) Fire(FirePower); AdjustGunAccordingTo(TurnRobot()); Broadcast("_PP" + X.ToString(CultureInfo.InvariantCulture) + "|" + Y.ToString(CultureInfo.InvariantCulture)); }
public override void Tick(Events events) { if(Time == 0) TurnRadar(1); if (Time < 3) TurnGun(30); Accelerate(1); Turn(2); if(RobotsScanned().Count > 0) Fire(3.0m); }
public override void Tick(Events events) { if (Time == 0) TurnRadar(5) ; if (RobotsScanned().Count>0) Fire(3.0m); TurnGun(1); Turn(2); if (GotHit().Count>0) _lastHit = Time; if (_lastHit > 0 && Time - _lastHit < 20) Accelerate(1); else Stop(); }
public override void Tick(Events events) { if (Time == 0) _prev_health = Energy; if (events.RobotsScanned.Count == 0) _radar_scan = Math.Min(_radar_scan*1.5, _max_radar_scan); else _radar_scan = Math.Max(_radar_scan*0.5, _min_radar_scan); if (Math.Abs(_radar_scan) < _max_radar_scan - 0.1) _rt = (Time/2%2 < 1 ? -_radar_scan/2.0 : _radar_scan/2.0); _wanted_radar_turn += _rt; firing_solution(events); if (events.GotHit.Count > 0) { _racc_dir = _racc_dir/Math.Abs(_racc_dir); _hit = 20; } else { _hit--; } _hit = -1; if (_hit < 0) _racc_dir = (int) ((_min_distance.HasValue && _min_distance.Value < 450) ? DoubleMath.sign(_racc_dir) : Math.Sin(Time*0.1 + rand()*0.2)); Accelerate((int) _racc_dir); if (approaching_wall()) _wanted_turn = 60*_rturn_dir; else if (_target_heading.HasValue && _wanted_turn <= 1) _wanted_turn = heading_distance( ((_min_distance.HasValue && _min_distance.Value < 450) ? (90 - DoubleMath.sign(_rturn_dir)*45)*-DoubleMath.sign(_racc_dir) : 0) + Heading, (double) (90 + _target_heading)); else if (rand() < 0.3) _wanted_turn += rand()*10*DoubleMath.sign(_racc_dir)*_rturn_dir; else if (rand() < 0.01) _rturn_dir *= -1; else if (rand() < 0.01) _racc_dir *= -1; turn_hull(); turn_turret(); turn_radar_dish(); _prev_health = Energy; }
protected Robot() { Events = new Events(); Actions = new Actions(); State = new State(); }
public abstract void Tick(Events events);
private void firing_solution(Events events) { if (events.RobotsScanned.Count > 0) { var last = (_target_positions.Count > 0) ? _target_positions[_target_positions.Count - 1] : new Vector(0, 0); var robotsScanned = new List<Vector>(); foreach (var d in events.RobotsScanned) { var tx = X + Math.Cos(DoubleMath.deg2rad((RadarHeading - Math.Abs(_radar_scan)/2.0)))*d; var ty = Y - Math.Sin(DoubleMath.deg2rad(RadarHeading - Math.Abs(_radar_scan)/2.0))*d; robotsScanned.Add(new Vector(tx, ty)); } var minRadius = double.MaxValue; Vector position = null; foreach (var pos in robotsScanned) { var radius = (pos - last).r(); if (radius < minRadius) { minRadius = radius; position = pos; } } _target_positions.Add(position); _min_distance = null; if (robotsScanned.Count > 0) { _min_distance = int.MaxValue; foreach (var distance in events.RobotsScanned) if (distance < _min_distance) _min_distance = distance; } } if (_target_positions.Count > 10) Shift(_target_positions); if (_target_positions.Count == 0) _min_distance = null; _target_heading = target_heading(); double? gtd = null; if (_target_heading.HasValue) gtd = heading_distance(GunHeading, (double) _target_heading); _firepower = 100.0m/(_vsd.HasValue ? (decimal) _vsd.Value : 1500m)/7.0m; Fire(_firepower*0.2m); if (_on_target) Fire(_firepower); if (gtd.HasValue && Math.Abs(gtd.Value) < _firing_threshold) { _wanted_gun_turn = gtd.Value; _on_target = true; } else { _wanted_gun_turn = gtd.HasValue ? gtd.Value : (gun_radar_distance()/3.0); _on_target = false; } }
public override void Tick(Events events) { Fire(0.1m); //event processing if (events.RobotsScanned.Count > 0) { var dist = events.RobotsScanned[0]; var data = RadToXy(MidRadarHeading(), dist); _points.Add(new PointTime(data.X, data.Y, Time)); if (_points.Count > HistorySize || Time - _points[0].ktime >= HistoryTimeout) ShiftPoints(); _lastSeenTime = Time; _radarSpeed = 1; _trackMul = 1; HeadRadarTo(MidRadarHeading()); _direction = 1; } //moving Predx = null; Predy = null; if (events.GotHit.Count > 0) { _lasthitcount += 1; } else if (_lasthitcount2) { _lasthitcount2 = false; _lasthitcount = 0; } else { _lasthitcount2 = true; } if (((OnWall() || (_lasthitcount >= Hitaway) || Rand(1) < Randturn) && Time - _lastchange > Timeout) || _lasthitcount >= Hitaway*4) { _lasthitcount2 = false; _lasthitcount = 0; _lastchange = Time; _moveDirection *= -1; } Halt(); Accelerate(8); Predcurrent(); var yc = Predy.HasValue? Y - Predy.Value : 0.0; var xc = Predx.HasValue ? Predx.Value - X : 0.0; var deg = RobotMath.ToDeg(Math.Atan2(yc, xc)) + 90*_moveDirection; var hyp = Math.Sqrt(yc*yc + xc*xc); if (hyp < Sdiff) deg += Outfactor*_moveDirection; else if (hyp > Sdiff + Size) deg -= Infactor*_moveDirection; deg += Rand(Randomize); deg -= Rand(Randomize); HeadTo(deg); //aiming if (_points.Count >= MinPoints) { Predcurrent(); hyp = hypot(Predx.HasValue?Predx.Value:0 - X,Predy.HasValue?Predy.Value:0 - Y); var steps = (hyp - 20)/BulletSpeed; var f = Predict(Time + steps + 1); var gh = RobotMath.ToDeg(Math.Atan2(Y - f.Y, f.X - X)) + Rand(7) - 3; HeadGunTo(gh); } //#scanning if (Time - _lastSeenTime >= TrackTimeout || _points.Count < MinPoints) { Say("Searching,"); if (RadarReady()) { turn_radar(_radarSpeed); _radarSpeed *= -ScanSwitch; } } else { Say("Seek and Destroy!"); if (RadarReady()) { Predcurrent(); yc = Predy.HasValue ? Y - Predy.Value : 0; xc = Predx.HasValue ? Predx.Value - X : 0; deg = RobotMath.ToDeg(Math.Atan2(yc, xc)); var dist = hypot(yc, xc); var signs = new[] {-0.5, -1.5, -0.5, 0.5, 1.5, 0.5}; var sign = signs[_direction%6]; _direction += 1; deg += (TrackRange*_trackMul*sign)/dist; _trackMul *= ScanSwitch2; HeadRadarTo(deg); } } FinalPoint(); FinalTurn(); }