bool MoveTurretOrShoot( Tank * pEnemy, Tank & self, World & world, model::Move& move, double offset ) { double angle_to_enemy = self.GetTurretAngleTo(*pEnemy); if (angle_to_enemy + offset > ( MIN_ANGLE) ) { move.set_turret_turn(1.0); } else if (angle_to_enemy + offset < ( -MIN_ANGLE ) ) { move.set_turret_turn(-1.0); } else { //vector<Tank> t = world.tanks(); //if ( ! EnemyBlocked(pEnemy, self, t) ) /* decide to shoot here, path may block */ //{ /* burst if we almoust alone */ if ( EnemyIsWalkingDead( pEnemy ) || self.premium_shell_count() > 3 ) { move.set_fire_type(PREMIUM_PREFERRED); } else { move.set_fire_type(REGULAR_FIRE); } return true; //} } return false; }
void Action::applyAction(model::Move &move) { if (left < 100) move.set_left_track_power(left); if (right < 100) move.set_right_track_power(right); if (turretRotate < 100) move.set_turret_turn(turretRotate); if (fireType != model::UNKNOWN_FIRE) move.set_fire_type(fireType); }
void MyStrategy::BackwardMove(const model::Car& self, const model::World& world, const model::Game& game, model::Move& move) { m_BacwardTick--; if (m_BacwardTick < 0) { m_bBackwardMove = false; move.setEnginePower(0.75); move.setWheelTurn(0); m_ForvardTick = 0; } else { move.setEnginePower(-1); if (m_BacwardTick < BACWARD_DUR / 3) { move.setEnginePower(1); move.setWheelTurn(m_BackwardWheelAngle); } else move.setWheelTurn(m_BackwardWheelAngle); if (m_BacwardTick < BACWARD_DUR / 6) { move.setBrake(true); move.setWheelTurn(0); } } }
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 GoToUnit( Unit * pBonus, Tank & self, model::Move & move ) { double orig_angle = self.GetAngleTo(*pBonus); double angle = orig_angle; double fangle = fabs(orig_angle); double dist = self.GetDistanceTo( *pBonus ); double MIN_ANGLE_B = dist*0.0005; double direction = 1.0; if (orig_angle > PI_D_2) { angle = M_PI - fangle; direction = -1.0; } if (orig_angle < -PI_D_2) { angle = fangle - M_PI; direction = -1.0; } if (fangle > PI_D_2) { if ( angle > MIN_ANGLE_B ) { move.set_left_track_power(-self.engine_power()); move.set_right_track_power( self.engine_power() - self.engine_rear_power_factor() ); //(.75); } else if ( angle < -MIN_ANGLE_B ) { move.set_left_track_power(self.engine_power() - self.engine_rear_power_factor() );//(.75); move.set_right_track_power(-self.engine_power()); } else { move.set_left_track_power(direction*1); move.set_right_track_power(direction*1); } } else { if ( angle > MIN_ANGLE_B ) { move.set_left_track_power(self.engine_power() - self.engine_rear_power_factor() );//(.75); move.set_right_track_power(-self.engine_power()); } else if ( angle < -MIN_ANGLE_B ) { move.set_left_track_power(-self.engine_power()); move.set_right_track_power( self.engine_power() - self.engine_rear_power_factor() ); //(.75); } else { move.set_left_track_power(direction*1); move.set_right_track_power(direction*1); } } }