void MyStrategy::Move(Tank self, World world, model::Move& move) { if (world.tick() == 1) { FirstTick(self, world); } vector<Tank> t = world.tanks(); vector<Shell> s = world.shells(); vector<Bonus> b = world.bonuses(); double xForce = 0 , yForce = 0 ; for (int i = 0; i < t.size(); ++i) { if (self.id() == t[i].id()) continue; if (EnemyDead(&t[i])) continue; ForceModify( self, t[i], xForce, yForce, -1.0 ); } Bonus * pBonus = 0; if ( !TimeToHide( self, world, move ) ) { pBonus = get_need_id(g_need_id, b); //pBonus = GetNeededBonus( self, b ); if (!pBonus || ( pBonus->type() != MEDIKIT && HealthIsCritical(self) ) ) { pBonus = GetNeededBonus( self, b ); } } for (int i = 0; i < b.size(); ++i) { double bonusPower = 1.0; if (pBonus && b[i].id() == pBonus->id()) { bonusPower = 10000.0; } ForceModify( self, b[i], xForce, yForce, bonusPower ); } /* for (int i = 0; i < s.size(); ++i) { if (self.player_name() != s[i].player_name()) { ForceModify( self, s[i], xForce, yForce, -100000.0 ); } } */ double orig_angle = atan2(xForce, yForce); double angle = orig_angle; double fangle = fabs(angle); double MIN_ANGLE_B = M_PI/30.0; double dir = 1.0; double s_angle = self.angle(); if (orig_angle > PI_D_2) { angle = M_PI - fangle; dir = -1.0; } if (orig_angle < -PI_D_2) { angle = fangle - M_PI; dir = -1.0; } if (fangle > PI_D_2) { if ( angle > MIN_ANGLE_B ) { move.set_left_track_power(-1.0); move.set_right_track_power( .75 ); //(.75); } else if ( angle < -MIN_ANGLE_B ) { move.set_left_track_power(.75 );//(.75); move.set_right_track_power(-1.0); } else { move.set_left_track_power(dir*1); move.set_right_track_power(dir*1); } } else { if ( angle > MIN_ANGLE_B ) { move.set_left_track_power(.75 );//(.75); move.set_right_track_power(-1.0); } else if ( angle < -MIN_ANGLE_B ) { move.set_left_track_power(-1.0); move.set_right_track_power( .75 ); //(.75); } else { move.set_left_track_power(dir*1); move.set_right_track_power(dir*1); } } //move.set_left_track_power(0); //move.set_right_track_power(0); Shoot( self, world, move ); }
void Shoot(Tank & self, World & world, model::Move& move) { vector<Tank> t = world.tanks(); /* always keep tower to some enemy */ Tank * pEnemy = get_need_id(g_lock_id, t); if ( EnemyDead(pEnemy) ) { pEnemy = 0; } /* not locked to anyone, select some, or change target every 300 tick */ if (!pEnemy || world.tick() % 300 == 0) { Tank * pOldEnemy = pEnemy; pEnemy = get_best_enemy(self, t); if (pEnemy != pOldEnemy) { waves.clear(); stats.clear(); stats.resize(30); } } /* still bad luck ? */ if (!pEnemy) { /* MoveAlgo */ return; } double absBearing = self.GetAngleTo(*pEnemy); for (int i=0; i < waves.size(); i++) { if (waves[i].checkHit(self, pEnemy, world.tick())) { waves.erase(waves.begin() + i ); i--; } } double power = 16.7; double e_velocity = sqrt( pEnemy->speed_x()*pEnemy->speed_x() + pEnemy->speed_y()*pEnemy->speed_y() ); WaveBullet newWave( self.x(), self.y(), self.angle(), absBearing, power, direction, world.tick(), &stats ); int bestindex = 15; for (int i=0; i<30; ++i) { if (stats[bestindex] < stats[i]) { bestindex = i; } } double guessfactor = ( bestindex - ( (double)stats.size() - 1 )/2 ) / ( ( (double)stats.size() - 1) / 2) ; if (e_velocity > 0.01) { if ( sin( pEnemy->angle() - self.angle() ) < 0 ) { direction = -1; } else { direction = 1; } } double angleOffset = direction * guessfactor * newWave.maxEscapeAngle(); /* got lock? move turret! */ MoveTurretOrShoot( pEnemy, self, world, move, 0.0 ); waves.push_back(newWave); }