Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Premature gameover on line clear #1

Closed
0xjmux opened this issue Mar 21, 2024 · 4 comments · Fixed by #2
Closed

Premature gameover on line clear #1

0xjmux opened this issue Mar 21, 2024 · 4 comments · Fixed by #2
Assignees

Comments

@0xjmux
Copy link
Owner

0xjmux commented Mar 21, 2024

I'm going to try out issues for bug resolution just to get the hang of it.

So far, this seems to happen most with I_PIECE, but idk if that's a necessary part of it.

game.log from a game where this happened:

Global piece locations are: {[24, 7] [25, 7] [26, 7] [27, 7] }
Gravity tick activated systime=200069, last tick=16: piece moved down
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
Global piece locations are: {[25, 7] [26, 7] [27, 7] [28, 7] }
Gravity tick activated systime=400097, last tick=200069: piece moved down
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
display_board()
Global piece locations are: {[26, 7] [27, 7] [28, 7] [29, 7] }
Gravity tick activated: move down failed
Piece stopped falling at loc row=26, col=7
check_and_clear: checking row 26
check_and_clear: checking row 27
check_and_clear: checking row 28
check_and_clear: checking row 29
smallest value in array {26, 28, 29, } is 26!
clearing 3 rows with top_row=26
Score updated for 3 lines cleared. Score = 4300, Level = 3     Lines cleared since last level=2
Global piece locations are: {[1, 9] [2, 8] [2, 9] [3, 8] }

Gravity tick activated: move down failed

Piece stopped falling at loc row=1, col=8
check_and_clear: checking row 1
check_and_clear: checking row 2
check_and_clear: checking row 2
check_and_clear: checking row 3
smallest value in array {2, 2, } is 2!
clearing 2 rows with top_row=2
Score updated for 2 lines cleared. Score = 5200, Level = 3     Lines cleared since last level=4
game over detected, returning false from tg_tick
Deallocating tetris game

The first sign of a problem is that "Gravity tick activated" line - for some reason it thinks it can't move the piece down when it's at the top of the board, and that causes the crash.

That print statement is in check_do_piece_gravity(), but the source of the problem has to be at/near check_valid_move(tg, T_DOWN).

@0xjmux 0xjmux self-assigned this Mar 21, 2024
0xjmux added a commit that referenced this issue Mar 21, 2024
I think this fixes Issue #1; I was mistakenly updating the
highest_occupied_cell twice, once correctly in clear_rows() and then
once in the wrong direction in update_score(). Since it was updated
twice, it would never move down when rows were cleared - resulting in
the highest cell only climbing during gameplay, eventually reaching the
gameover condition.

#1
@0xjmux 0xjmux mentioned this issue Mar 21, 2024
@0xjmux 0xjmux closed this as completed in #2 Mar 21, 2024
0xjmux added a commit that referenced this issue Mar 21, 2024
* also fix an issue regarding ini parsing - now when a game board is
  prettyprinted to a .ini file, all lines are prepended with comments so
  there aren't parsing errors during reading.
* existing ini files were updated to reflect this change, as was
  print_board_state()
* test_clearRowsDumpedGame_2() was created to piece-by-piece manually
  step through the game state process of lowering a piece and clearing
  the associated rows.
* Helper functions were added to tetris_test_helpers() to simplify the
  process of testing the whole game board for invalid states (like
  filled rows being left over after a row clear).
@0xjmux
Copy link
Owner Author

0xjmux commented Mar 22, 2024

Not resolved - similar crash occurred on a 4 row clear in a game a couple minutes ago - see test/files/final-gamestate-4row-clear-premat-gameover.ini

It looks like some weirdness is causing incorrect bit values to show up at the top of the file, which prevents the new piece from moving down - triggering the game over condition. Need to figure out what is causing the corruption in the first place.

@0xjmux 0xjmux reopened this Mar 22, 2024
@0xjmux
Copy link
Owner Author

0xjmux commented Mar 22, 2024

  • possible cause might be clearing lines down to row 31
  • it seems to happen right around when the level increases, so maybe it's the change in level that's doing it?

@0xjmux
Copy link
Owner Author

0xjmux commented Mar 23, 2024

Issue possibly fixed in 6a23430, but until i've gone through several rounds of testing trying to break it will leave this open.

@0xjmux
Copy link
Owner Author

0xjmux commented Mar 25, 2024

Commit 6a2340 fixed this issue.
As I stated in the commit, the problem and fix were:

* clear_rows modified so it won't try to move rows above the top of the
  board down, which is a possible cause of the premature crash as a
  result of garbage data I've been seeing (Issue https://github.com/0xjmux/tetris/pull/2). Garbage data ends up in the
  first few rows, pieces can't move down into it, they stop falling, and
  then the game_over condition activates.
    * to fix this, added another loop to clear_rows() so that it stops
      once it would start touching the top of the board, and will fill
      rows at the top with BG_COLOR without trying to read OOB

@0xjmux 0xjmux closed this as completed Mar 25, 2024
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 a pull request may close this issue.

1 participant