From f77dda29463f43d37694ab9a6683ffb685f743cc Mon Sep 17 00:00:00 2001 From: gabrielderome Date: Thu, 9 May 2024 23:22:13 -0400 Subject: [PATCH] fix score oopsi --- main.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/main.py b/main.py index 3e87985..e182770 100644 --- a/main.py +++ b/main.py @@ -32,15 +32,14 @@ def attempt_rotate(piece, board, i, j): return piece -def clear_rows(board): +def clear_rows(board, score): clear_indices = np.where(np.all(board == 1, axis=1))[0] if clear_indices.size > 0: board = np.delete(board, clear_indices, axis=0) new_rows = np.zeros((len(clear_indices), board.shape[1])) board = np.vstack([new_rows, board]) - global score - score = update_score(score, len(clear_indices)) - return board + score = update_score(score) + return board, score def calculate_shadow(piece, board, i, j): @@ -81,8 +80,8 @@ def game_over(board): board ) # Clear the board and continue or call sys.exit() to end -def update_score(score, cleared_rows): - return score + cleared_rows +def update_score(score): + return score + 1 def main(): @@ -123,13 +122,13 @@ def main(): i += 1 else: board = place_piece(current_piece, board, i, j) - board = clear_rows(board) + board, score = clear_rows(board, score) current_piece = PIECES[np.random.choice(piece_types)] i, j = 0, 4 elif command == "S": i = calculate_shadow(current_piece, board, i, j) board = place_piece(current_piece, board, i, j) - board = clear_rows(board) + board, score = clear_rows(board, score) current_piece = PIECES[np.random.choice(piece_types)] i, j = START_POS elif command == "G": @@ -140,7 +139,7 @@ def main(): i += 1 else: board = place_piece(current_piece, board, i, j) - board = clear_rows(board) + board, score = clear_rows(board, score) current_piece = PIECES[np.random.choice(piece_types)] i, j = START_POS