From c785e2c93ab70e33732d6351318575bce2162eb2 Mon Sep 17 00:00:00 2001 From: daphne-cornelisse Date: Thu, 27 Aug 2026 09:13:03 -0700 Subject: [PATCH 1/3] Ensure light mechanics match original exactly. --- ocean/craftax_clean/craftax_clean.h | 44 ++++++++++++++--------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/ocean/craftax_clean/craftax_clean.h b/ocean/craftax_clean/craftax_clean.h index 44d04cefe3..3b23db90cc 100644 --- a/ocean/craftax_clean/craftax_clean.h +++ b/ocean/craftax_clean/craftax_clean.h @@ -2833,6 +2833,11 @@ static void draw_tile(int tex_id, int x, int y, int px) { DrawTexturePro(textures, src, dst, (Vector2){0, 0}, 0.0f, WHITE); } +static int map_lit(const State* state, int level, int wr, int wc) { + return (unsigned)wr < MAP_SIZE && (unsigned)wc < MAP_SIZE + && state->light_map[level][wr][wc] > 12; +} + static int projectile_tex(int ptype, int dr, int dc) { if (ptype == PROJECTILE_DAGGER) { return TEX_PROJ_DAGGER; @@ -2885,10 +2890,8 @@ static void draw_agent_obs(Craftax* env, int panel_x, int panel_y, int wc = pc + (vc - rc); int dst_x = grid_x + vc * px; int dst_y = grid_y + vr * px; - int lit = (unsigned)wr < MAP_SIZE && (unsigned)wc < MAP_SIZE - && state->light_map[level][wr][wc] > 12; - if (!lit) { - DrawRectangle(dst_x, dst_y, px, px, BLACK); + if (!map_lit(state, level, wr, wc)) { + draw_tile(BLOCK_DARKNESS, dst_x, dst_y, px); continue; } int block = state->map[level][wr][wc]; @@ -2922,9 +2925,8 @@ static void draw_agent_obs(Craftax* env, int panel_x, int panel_y, int col = projectiles->position[i][1]; int vr = row - pr + rr; int vc = col - pc + rc; - int lit = (unsigned)row < MAP_SIZE && (unsigned)col < MAP_SIZE - && state->light_map[level][row][col] > 12; - if (vr < 0 || vr >= OBS_ROWS || vc < 0 || vc >= OBS_COLS || !lit) { + if (vr < 0 || vr >= OBS_ROWS || vc < 0 || vc >= OBS_COLS + || !map_lit(state, level, row, col)) { continue; } int dr = directions[level][i][0]; @@ -3091,18 +3093,15 @@ void puf_render(Craftax* env) { int dst_x = origin_x + vc * TEX_DRAW_PX; int dst_y = vr * TEX_DRAW_PX; - int in_map = wr >= 0 && wr < MAP_SIZE && wc >= 0 && wc < MAP_SIZE; - int block = BLOCK_OUT_OF_BOUNDS; - if (in_map) { - block = env->state.map[level][wr][wc]; + if (!map_lit(&env->state, level, wr, wc)) { + draw_tile(BLOCK_DARKNESS, dst_x, dst_y, TEX_DRAW_PX); + continue; } + int block = env->state.map[level][wr][wc]; if (block < 0 || block >= NUM_BLOCK_TYPES) { block = BLOCK_INVALID; } draw_tile(block, dst_x, dst_y, TEX_DRAW_PX); - if (!in_map) { - continue; - } int item = env->state.item_map[level][wr][wc]; if (item > ITEM_NONE) { draw_tile(TEX_ITEM_BASE + item, dst_x, dst_y, TEX_DRAW_PX); @@ -3112,7 +3111,8 @@ void puf_render(Craftax* env) { if (find_mob_at(&env->state, level, wr, wc, &mob_class, &slot)) { int type_id = mobs_for_class(&env->state, level, mob_class) ->type_id[slot]; - draw_tile(mob_tex_base[mob_class] + type_id, dst_x, dst_y, TEX_DRAW_PX); + draw_tile(mob_tex_base[mob_class] + type_id, dst_x, dst_y, + TEX_DRAW_PX); } } } @@ -3128,9 +3128,12 @@ void puf_render(Craftax* env) { if (!projectiles->mask[i]) { continue; } - int vr = projectiles->position[i][0] - top_row; - int vc = projectiles->position[i][1] - left_col; - if (vr < 0 || vr >= RENDER_ROWS || vc < 0 || vc >= RENDER_COLS) { + int wr = projectiles->position[i][0]; + int wc = projectiles->position[i][1]; + int vr = wr - top_row; + int vc = wc - left_col; + if (vr < 0 || vr >= RENDER_ROWS || vc < 0 || vc >= RENDER_COLS + || !map_lit(&env->state, level, wr, wc)) { continue; } int dr = directions[level][i][0]; @@ -3153,11 +3156,6 @@ void puf_render(Craftax* env) { draw_tile(player_tex, origin_x + half_c * TEX_DRAW_PX, half_r * TEX_DRAW_PX, TEX_DRAW_PX); - if (env->state.light_level < 1.0f) { - unsigned char alpha = (unsigned char)((1.0f - env->state.light_level) * 140.0f); - DrawRectangle(origin_x, 0, view_w, view_h, (Color){0, 0, 40, alpha}); - } - int floor_bar_h = 16; int cell_w = view_w / NUM_LEVELS; DrawRectangle(origin_x, 0, view_w, floor_bar_h, (Color){18, 18, 18, 230}); From 44c252d16214963a650626ea710c4ac8be2e043d Mon Sep 17 00:00:00 2001 From: daphne-cornelisse Date: Thu, 27 Aug 2026 09:17:52 -0700 Subject: [PATCH 2/3] Delete remaining profiling code. --- ocean/craftax_clean/craftax_clean.h | 68 ----------------------------- 1 file changed, 68 deletions(-) diff --git a/ocean/craftax_clean/craftax_clean.h b/ocean/craftax_clean/craftax_clean.h index 3b23db90cc..ec24121d7b 100644 --- a/ocean/craftax_clean/craftax_clean.h +++ b/ocean/craftax_clean/craftax_clean.h @@ -14,55 +14,6 @@ typedef float obs_t; #include #include -#ifdef CRAFTAX_CLEAN_PROFILE -#define CLEAN_PROF_ZONES 9 -static const char* clean_prof_names[CLEAN_PROF_ZONES] = { - "floor+craft", - "do", - "place+shoot+potion", - "book+enchant+move", - "update_mobs", - "spawn", - "plants+intrinsics", - "reward+reset", - "obs", -}; -static uint64_t clean_prof_ticks[CLEAN_PROF_ZONES]; -static uint64_t clean_prof_count[CLEAN_PROF_ZONES]; - -static inline uint64_t clean_prof_now(void) { - return __builtin_ia32_rdtsc(); -} - -static inline void clean_prof_add(int zone, uint64_t t0) { - clean_prof_ticks[zone] += clean_prof_now() - t0; - clean_prof_count[zone]++; -} - -void clean_prof_report(void) { - uint64_t total = 0; - for (int i = 0; i < CLEAN_PROF_ZONES; i++) { - total += clean_prof_ticks[i]; - } - fprintf(stderr, "\n=== puf_step zones ===\n"); - for (int i = 0; i < CLEAN_PROF_ZONES; i++) { - double pct = total ? 100.0 * (double)clean_prof_ticks[i] / (double)total : 0.0; - fprintf(stderr, "%-22s %6.2f%% %lu calls ticks=%lu\n", - clean_prof_names[i], pct, (unsigned long)clean_prof_count[i], - (unsigned long)clean_prof_ticks[i]); - } -} - -#define CLEAN_PROF_START() uint64_t _z0 = 0 -#define CLEAN_ZONE(n) do { _z0 = clean_prof_now(); } while (0) -#define CLEAN_ZONE_END(n) clean_prof_add((n), _z0) -#else -#define CLEAN_PROF_START() -#define CLEAN_ZONE(n) -#define CLEAN_ZONE_END(n) -#define clean_prof_report() -#endif - #define ACT_SIZES {ATN_DIM} #define NUM_ATNS 1 #ifdef PUFFERCPU_EVAL_MAIN @@ -1837,7 +1788,6 @@ void puf_step(Craftax* env) { if (craftax_clean_human_controls(env) < 0) { return; } - CLEAN_PROF_START(); env->agents[0].rewards[0] = 0.0f; env->agents[0].terminals[0] = 0.0f; int action = env->agents[0].actions[0]; @@ -1863,7 +1813,6 @@ void puf_step(Craftax* env) { action = ACTION_NOOP; } - CLEAN_ZONE(0); int level = state->player_level; int row = state->player_position[0]; int col = state->player_position[1]; @@ -2007,9 +1956,7 @@ void puf_step(Craftax* env) { inv->armour[idx] = 2; state->achievements[ACH_MAKE_DIAMOND_ARMOUR] = 1; } - CLEAN_ZONE_END(0); - CLEAN_ZONE(1); Rng interact_rng = rng_key(&step_rng); int direction[2]; @@ -2168,9 +2115,7 @@ void puf_step(Craftax* env) { state->chests_opened[level] |= block == BLOCK_CHEST; } } - CLEAN_ZONE_END(1); - CLEAN_ZONE(2); action_to_direction(state->player_direction, direction); row = state->player_position[0] + direction[0]; col = state->player_position[1] + direction[1]; @@ -2294,9 +2239,7 @@ void puf_step(Craftax* env) { } state->achievements[ACH_DRINK_POTION] = 1; } - CLEAN_ZONE_END(2); - CLEAN_ZONE(3); Rng book_rng = rng_key(&step_rng); bool reading = action == ACTION_READ_BOOK && state->inventory.books > 0; @@ -2407,9 +2350,7 @@ void puf_step(Craftax* env) { if (direction[0] != 0 || direction[1] != 0) { state->player_direction = action; } - CLEAN_ZONE_END(3); - CLEAN_ZONE(4); Rng mobs_rng = rng_key(&step_rng); level = state->player_level; @@ -2428,9 +2369,7 @@ void puf_step(Craftax* env) { update_projectile_set(state, false); rng_key(&mobs_rng); update_projectile_set(state, true); - CLEAN_ZONE_END(4); - CLEAN_ZONE(5); Rng spawn_rng = rng_key(&step_rng); level = state->player_level; @@ -2519,9 +2458,7 @@ void puf_step(Craftax* env) { } } } - CLEAN_ZONE_END(5); - CLEAN_ZONE(6); for (int plant = 0; plant < MAX_GROWING_PLANTS; plant++) { if (!state->growing_plants_mask[plant]) { continue; @@ -2657,7 +2594,6 @@ void puf_step(Craftax* env) { state->achievements[ACH_MAKE_IRON_SWORD] |= state->inventory.sword >= 3; state->achievements[ACH_MAKE_DIAMOND_SWORD] |= state->inventory.sword >= 4; update_log_state(env); - CLEAN_ZONE_END(6); store_rng(state, rng_key(&step_rng)); state->timestep += 1; @@ -2667,7 +2603,6 @@ void puf_step(Craftax* env) { done = state->player_health <= 0.0f || state->timestep >= DEFAULT_MAX_TIMESTEPS; } while (!done && (state->is_sleeping || state->is_resting)); - CLEAN_ZONE(7); float reward = 0.0f; for (int i = 0; i < NUM_ACHIEVEMENTS; i++) { int delta = state->achievements[i] - initial_achievements[i]; @@ -2717,11 +2652,8 @@ void puf_step(Craftax* env) { generate_world_from_key(&env->state, world_key); } } - CLEAN_ZONE_END(7); - CLEAN_ZONE(8); compute_observations(env); - CLEAN_ZONE_END(8); } void puf_init(Env* env, Dict* kwargs) { From f8d23246d7aec00e79d0a2d2b33b802d2bc4b974 Mon Sep 17 00:00:00 2001 From: daphne-cornelisse Date: Thu, 27 Aug 2026 13:20:15 -0700 Subject: [PATCH 3/3] Better config? --- config/craftax_clean.ini | 42 +++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/config/craftax_clean.ini b/config/craftax_clean.ini index b560b9461b..1e0409f1a8 100644 --- a/config/craftax_clean.ini +++ b/config/craftax_clean.ini @@ -2,52 +2,46 @@ env_name = craftax_clean [vec] -total_agents = 2048 +total_agents = 4096 num_buffers = 16 num_threads = 16 [env] reset_pool_size = 32 -action_mask = 0 +action_mask = 1 [train] -total_timesteps = 1_872_097_150 -learning_rate = 0.00179971103 -ent_coef = 0.0000203385534 -gamma = 0.997127712 -gae_lambda = 0.960012317 -horizon = 64 +total_timesteps = 429_130_004 +learning_rate = 0.00883168 +ent_coef = 0.000194094 +gamma = 0.986552 +gae_lambda = 0.861994 +horizon = 128 minibatch_size = 65536 -replay_ratio = 3.26567292 -clip_coef = 0.207467377 -vf_coef = 2.66733265 -vf_clip_coef = 0.01 -max_grad_norm = 0.496576279 -momentum = 0.961853921 +replay_ratio = 1.39199 +clip_coef = 0.172376 +vf_coef = 2.46606 +vf_clip_coef = 1.37661 +max_grad_norm = 0.239896 +momentum = 0.908417 [policy] -hidden_size = 1024 -num_layers = 4 +hidden_size = 512 +num_layers = 2.88843 [sweep] metric = score metric_distribution = linear goal = maximize -max_suggestion_cost = 1200 +max_suggestion_cost = 3600 max_runs = 1200 gpus = -1 downsample = 15 prune_pareto = True early_stop_quantile = 0.3 -[sweep.env.action_mask] -distribution = int_uniform -min = 0 -max = 1 -scale = auto - [sweep.train.total_timesteps] distribution = log_normal min = 3e7 -max = 1e10 +max = 1e11 scale = time