bool EnemyBlocked( Tank * pEnemy, Tank & self, vector<Tank> & t ) { double my_angle = self.GetAngleTo( *pEnemy ); double my_dist = self.GetDistanceTo( *pEnemy ); for (int i = 0; i < t.size(); ++i) { if (t[i].id() == pEnemy->id() || t[i].id() == self.id()) { continue; } double max_wh = std::max( t[i].width(), t[i].height() ); double alpha = fabs( self.GetAngleTo(t[i]) - my_angle ); double his_dist = self.GetDistanceTo( t[i] ); if (alpha > M_PI / 4) { continue; } double d_size = sin(alpha) * my_dist; if ( d_size <= max_wh/2 && his_dist < my_dist ) { return true; } } return false; }
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 ); }