Skip to content

Commit ca42086

Browse files
committed
add shield break reward
1 parent bcc803a commit ca42086

File tree

4 files changed

+13
-14
lines changed

4 files changed

+13
-14
lines changed

pufferlib/ocean/impulse_wars/env.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,6 @@ void resetEnv(iwEnv *e) {
680680
setupEnv(e);
681681
}
682682

683-
float computeShotReward(const droneEntity *drone, const weaponInformation *weaponInfo) {
684-
const float weaponForce = weaponInfo->fireMagnitude * weaponInfo->invMass;
685-
const float scaledForce = (weaponForce * (weaponForce * SHOT_HIT_REWARD_COEF)) + 0.25f;
686-
return scaledForce + computeHitStrength(drone);
687-
}
688-
689-
float computeExplosionReward(const droneEntity *drone) {
690-
return computeHitStrength(drone) * EXPLOSION_HIT_REWARD_COEF;
691-
}
692-
693683
float computeReward(iwEnv *e, droneEntity *drone) {
694684
float reward = 0.0f;
695685

@@ -712,20 +702,22 @@ float computeReward(iwEnv *e, droneEntity *drone) {
712702
droneEntity *enemyDrone = safe_array_get_at(e->drones, i);
713703
const bool onTeam = drone->team == enemyDrone->team;
714704

705+
// TODO: punish for hitting teammates?
715706
if (drone->stepInfo.shotHit[i] != 0.0f && !onTeam) {
716-
// subtract 1 from the weapon type because 1 is added so we
717-
// can use 0 as no shot was hit
718707
reward += drone->stepInfo.shotHit[i] * SHOT_HIT_REWARD_COEF;
719708
}
720709
if (drone->stepInfo.explosionHit[i] != 0.0f && !onTeam) {
721710
reward += drone->stepInfo.explosionHit[i] * EXPLOSION_HIT_REWARD_COEF;
722711
}
712+
if (drone->stepInfo.brokeShield[i] && !onTeam) {
713+
reward += SHIELD_BREAK_REWARD;
714+
}
723715

724716
if (e->numAgents == e->numDrones) {
725-
if (drone->stepInfo.shotTaken[i] != 0 && !onTeam) {
717+
if (drone->stepInfo.shotTaken[i] != 0) {
726718
reward -= drone->stepInfo.shotTaken[i] * SHOT_HIT_REWARD_COEF;
727719
}
728-
if (drone->stepInfo.explosionTaken[i] && !onTeam) {
720+
if (drone->stepInfo.explosionTaken[i]) {
729721
reward -= drone->stepInfo.explosionTaken[i] * EXPLOSION_HIT_REWARD_COEF;
730722
}
731723
}

pufferlib/ocean/impulse_wars/game.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,7 @@ void destroyDroneShield(iwEnv *e, shieldEntity *shield, const bool createPieces)
850850
droneAddEnergy(drone, DRONE_SHIELD_BREAK_ENERGY_COST);
851851
}
852852
drone->shield = NULL;
853+
e->stats[drone->idx].ownShieldBroken++;
853854

854855
b2DestroyBody(shield->bodyID);
855856
b2DestroyShape(shield->bufferShapeID, false);
@@ -2444,6 +2445,8 @@ uint8_t handleProjectileBeginContact(iwEnv *e, const entity *proj, const entity
24442445
if (shield->health <= 0.0f) {
24452446
droneEntity *parentDrone = safe_array_get_at(e->drones, projectile->droneIdx);
24462447
droneAddEnergy(parentDrone, DRONE_SHIELD_BREAK_ENERGY_REFILL);
2448+
parentDrone->stepInfo.brokeShield[shield->drone->idx] = true;
2449+
e->stats[parentDrone->idx].shieldsBroken++;
24472450
}
24482451

24492452
return false;

pufferlib/ocean/impulse_wars/settings.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ const float TEAMMATE_KILL_PUNISHMENT = -1.0f;
4343
const float DEATH_PUNISHMENT = 0.0f;
4444
const float ENERGY_EMPTY_PUNISHMENT = -0.75f;
4545
const float WEAPON_PICKUP_REWARD = 0.5f;
46+
const float SHIELD_BREAK_REWARD = 0.5f;
4647
const float SHOT_HIT_REWARD_COEF = 0.005f;
4748
const float EXPLOSION_HIT_REWARD_COEF = 0.005f;
4849
const float APPROACH_REWARD = 0.0f;

pufferlib/ocean/impulse_wars/types.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ typedef struct droneStepInfo {
215215
float explosionHit[_MAX_DRONES];
216216
float shotTaken[_MAX_DRONES];
217217
float explosionTaken[_MAX_DRONES];
218+
bool brokeShield[_MAX_DRONES];
218219
bool ownShotTaken;
219220
} droneStepInfo;
220221

@@ -311,6 +312,8 @@ typedef struct droneStats {
311312
float totalBursts;
312313
float burstsHit;
313314
float energyEmptied;
315+
float shieldsBroken;
316+
float ownShieldBroken;
314317
float selfKills;
315318
float kills;
316319
float wins;

0 commit comments

Comments
 (0)