Skip to content

Commit 5dcf22f

Browse files
committed
energy bug fix
1 parent a07d830 commit 5dcf22f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

ocean/robocode/bots.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ struct BotMem {
8282
// target this tick. Until first scan, last_scan_tick == 0 and decisions
8383
// are skipped.
8484
float last_x, last_y, last_heading, last_v;
85-
int last_energy_seen;
85+
float last_energy_seen;
8686
int last_scan_tick;
8787
int radar_dir; // ±1, the direction the radar is currently sweeping
8888
int radar_reversals; // beep-boop's lost-lock reversal counter
@@ -340,8 +340,8 @@ static void bot_step(Robocode* env, int bot_idx) {
340340
if (scanned == t) {
341341
Robot* tgt = &env->robots[t];
342342
// Detect target fire from energy drop BEFORE overwriting last_energy_seen.
343-
int drop = m->last_scan_tick > 0 ? (m->last_energy_seen - tgt->energy) : 0;
344-
bool fired = (drop > 0 && drop <= 3);
343+
float drop = m->last_scan_tick > 0 ? (m->last_energy_seen - tgt->energy) : 0.0f;
344+
bool fired = (drop > 0.0f && drop <= 3.0f);
345345
if (env->bot_policy == BOT_SURFER && fired) {
346346
m->orbit_dir = -m->orbit_dir;
347347
m->last_dir_change_tick = m->tick;

ocean/robocode/robocode.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct Robot {
9090
float power_mult;
9191
int bullet_idx;
9292
float gun_heat;
93-
int energy;
93+
float energy;
9494
};
9595

9696
typedef struct Client Client;
@@ -486,7 +486,7 @@ void c_reset(Robocode* env) {
486486
robot->gun_heading = 0;
487487
robot->radar_heading = 0;
488488
robot->radar_heading_prev = 0;
489-
robot->energy = 100;
489+
robot->energy = 100.0f;
490490
robot->gun_heat = 3;
491491
robot->bullet_idx = 0;
492492
if (idx < env->num_agents) {
@@ -780,7 +780,7 @@ void c_render(Robocode* env) {
780780
DrawTexturePro(client->atlas, radar_rect, dest_rect, origin, robot.radar_heading+90, WHITE);
781781
DrawTexturePro(client->atlas, gun_rect, dest_rect, origin, robot.gun_heading+90, WHITE);
782782

783-
DrawText(TextFormat("%i", robot.energy), robot.x-16, robot.y-48, 12, WHITE);
783+
DrawText(TextFormat("%.1f", robot.energy), robot.x-16, robot.y-48, 12, WHITE);
784784
}
785785

786786
for (int i = 0; i < (env->num_agents + env->num_bots)*NUM_BULLETS; i++) {

0 commit comments

Comments
 (0)