KingNook / 2048

https://kingnook.github.io/2048/
1 stars 0 forks source link

Random Crashes: Logic Error in move_<direction> #1

Closed KingNook closed 2 months ago

KingNook commented 2 months ago

self.any_valid_moves() is occasionally erroneously returning false

example start from grid.tiles = {(1, 0): 2, (2, 0): 4, (3, 0): 1, (0, 1): 4, (1, 1): 2, (2, 1): 1, (3, 1): 2, (1, 2): 2, (2, 2): 4, (3, 2): 2, (3, 3): 3, (2, 3): 1} and try to move left - this will end the game this can be verified by starting from grid.tiles = {(0, 0): 4, (1, 0): 3, (1, 1): 2, (2, 0): 4, (2, 1): 1, (2, 2): 4, (2, 3): 1, (3, 0): 1, (3, 1): 3, (3, 2): 3, (0, 3): 1} (grid after moving left) and calling grid.any_valid_moves() to see that this returns False

note the new grid after moving left seems correct

KingNook commented 2 months ago

note that grid.tiles = {(3, 3): 3, (2, 3): 1} also reproduces this

KingNook commented 2 months ago

ok so i had 1 run where it didn't crash so maybe it's a random seed issue?

KingNook commented 2 months ago

[x] [n] [n] [n] [x] [n] [n] [n] [z] [n] [n] [n] [z] [x] [x] [x]

x = fine z = n/a n = problem

seems like the problem is linked to where the next tile spawns

KingNook commented 2 months ago

so it seems like my logic in the any_valid_moves was backwards (and ong i have no clue how it worked in the first place) - move_up was returning True if the grid didn't change and False if it did which was backwards wrt the rest of the logic

i'll clean up the code then mark this closed