Compare commits
No commits in common. "8850c5de8500e6ff1b3311d8864b75a0514c971d" and "069f98910e2b4ba4c107b72c36cd16cb9921c3ee" have entirely different histories.
8850c5de85
...
069f98910e
13
main.py
13
main.py
@ -38,8 +38,6 @@ def clear_rows(board):
|
|||||||
board = np.delete(board, clear_indices, axis=0)
|
board = np.delete(board, clear_indices, axis=0)
|
||||||
new_rows = np.zeros((len(clear_indices), board.shape[1]))
|
new_rows = np.zeros((len(clear_indices), board.shape[1]))
|
||||||
board = np.vstack([new_rows, board])
|
board = np.vstack([new_rows, board])
|
||||||
global score
|
|
||||||
score = update_score(score, len(clear_indices))
|
|
||||||
return board
|
return board
|
||||||
|
|
||||||
|
|
||||||
@ -50,7 +48,7 @@ def calculate_shadow(piece, board, i, j):
|
|||||||
return i
|
return i
|
||||||
|
|
||||||
|
|
||||||
def display_board(board, piece, i, j, score):
|
def display_board(board, piece, i, j):
|
||||||
display = board.copy()
|
display = board.copy()
|
||||||
shadow_i = calculate_shadow(piece, board, i, j)
|
shadow_i = calculate_shadow(piece, board, i, j)
|
||||||
n, m = piece.shape
|
n, m = piece.shape
|
||||||
@ -71,7 +69,7 @@ def display_board(board, piece, i, j, score):
|
|||||||
for row in display
|
for row in display
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
print(f"Score: {score}\n")
|
print()
|
||||||
|
|
||||||
|
|
||||||
def game_over(board):
|
def game_over(board):
|
||||||
@ -82,12 +80,7 @@ def game_over(board):
|
|||||||
) # Clear the board and continue or call sys.exit() to end
|
) # Clear the board and continue or call sys.exit() to end
|
||||||
|
|
||||||
|
|
||||||
def update_score(score, cleared_rows):
|
|
||||||
return score + cleared_rows
|
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
score = 0
|
|
||||||
board = np.zeros((20, 10), dtype=int)
|
board = np.zeros((20, 10), dtype=int)
|
||||||
piece_types = list(PIECES.keys())
|
piece_types = list(PIECES.keys())
|
||||||
current_piece = PIECES[np.random.choice(piece_types)]
|
current_piece = PIECES[np.random.choice(piece_types)]
|
||||||
@ -96,7 +89,7 @@ def main():
|
|||||||
auto_gravity = True # Auto-gravity enabled by default
|
auto_gravity = True # Auto-gravity enabled by default
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
display_board(board, current_piece, i, j, score)
|
display_board(board, current_piece, i, j)
|
||||||
if not check_placement(current_piece, board, *START_POS):
|
if not check_placement(current_piece, board, *START_POS):
|
||||||
board = game_over(board)
|
board = game_over(board)
|
||||||
continue
|
continue
|
||||||
|
Loading…
Reference in New Issue
Block a user