steven-pereira / 2048-game

2048 Game built on the web for fun.
0 stars 0 forks source link

Enhance Random Tile Generator Algorithm #4

Open steven-pereira opened 2 years ago

steven-pereira commented 2 years ago

There's an edge case that's causing the random tile generator to fail.

jameshuber15 commented 2 years ago

I think it's going forever since you have the || case in the for loop so once uniqueTileSet is set to true the loop will be infinite.

jameshuber15 commented 2 years ago

I think you meant to use break instead of continue.

steven-pereira commented 2 years ago

Yeah it goes forever if it never finds an open spot for sure, I actually just added a isGameBoardFull check prior to trying to adding new random random tiles.

The continue looks like leftover from a previous refactor. It's not meant as a break cause i do want to keep trying to find an empty spot.

This implementation in general was a quick one at the time. I'll clean it up :)

steven-pereira commented 2 years ago

Love this by the way! :)