Skip to content

Fix 2048 spawn count and add 16384 stat#493

Open
kywch wants to merge 1 commit intoPufferAI:4.0from
kywch:fix-2048-bug
Open

Fix 2048 spawn count and add 16384 stat#493
kywch wants to merge 1 commit intoPufferAI:4.0from
kywch:fix-2048-bug

Conversation

@kywch
Copy link
Contributor

@kywch kywch commented Feb 25, 2026

aminos9 at discord reported the 2048 bug (see https://discord.com/channels/1019421966429593712/1088863728646246491/1476191074581090425) , and it effectively gave agents a cheat skill.

The bug stems from a stale empty_count value when place_tile_at_random_cell is called within the c_step function. Specifically, when the board is full but a move creates new space through merges, the code attempts to spawn a tile before re-calculating the actual number of empty cells. Since place_tile_at_random_cell returns early if it sees an empty_count of zero, the environment fails to spawn a tile, leading to the missing tile behavior and significantly inflated move counts. Moving the update_stats_and_get_heuristic_rewards call to occur before the spawning logic will ensure that newly opened cells are correctly identified.

After fixing it, the 2048 game got much harder and the agent barely reached 32k after the same training setup.
https://wandb.ai/kywch/pufferlib/runs/wbic5igz?nw=nwuserkywch

As it 2048 became much harder, tracking 16378 tile is useful for tracking process, so added it to logging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant