Here is my updated game. For some reason, the board now completely fills when a shape hits the bottom of the screen. Why is this occurring?

import sys
import pygame
import random

# Initialize Pygame
pygame.init()

# Define constants
SCREEN\_WIDTH, SCREEN\_HEIGHT = 800, 600
BACKGROUND\_COLOR = (0, 0, 0)
GRID\_SIZE = 30
GRID\_WIDTH, GRID\_HEIGHT = SCREEN\_WIDTH // GRID\_SIZE, SCREEN\_HEIGHT // GRID\_SIZE

# Define shapes
SHAPES = [
 # T shape
 [
 [1, 1, 1],
 [0, 1, 0],
 ],
 # I shape
 [
 [1, 1, 1, 1],
 ],
 # O shape
 [
 [1, 1],
 [1, 1],
 ],
 # L shape
 [
 [1, 1, 1],
 [1, 0, 0],
 ],
 # J shape
 [
 [1, 1, 1],
 [0, 0, 1],
 ],
 # S shape
 [
 [0, 1, 1],
 [1, 1, 0],
 ],
 # Z shape
 [
 [1, 1, 0],
 [0, 1, 1],
 ],
]

# Define game functions
def draw\_shape(screen, shape, x, y):
 shape\_color = (255, 255, 255) # White color for the shape

 for i, row in enumerate(shape):
 for j, cell in enumerate(row):
 if cell: # If the cell is part of the shape (has a value of 1)
 # Calculate the screen position of the cell
 screen\_x = (x + j) \* GRID\_SIZE
 screen\_y = (y + i) \* GRID\_SIZE

 # Draw a rectangle on the screen for the cell
 pygame.draw.rect(screen, shape\_color, (screen\_x, screen\_y, GRID\_SIZE, GRID\_SIZE))

 # Optionally, draw a border around the cell
 border\_color = (0, 0, 0) # Black color for the border
 border\_thickness = 2
 pygame.draw.rect(screen, border\_color, (screen\_x, screen\_y, GRID\_SIZE, GRID\_SIZE), border\_thickness)
def check\_collision(board, shape, x, y):
 for i, row in enumerate(shape):
 for j, cell in enumerate(row):
 if cell: # If the cell is part of the shape (has a value of 1)
 # Check if the cell is out of the grid boundaries
 if x + j < 0 or x + j >= GRID\_WIDTH or y + i < 0 or y + i >= GRID\_HEIGHT:
 return True

 # Check if the cell is overlapping an occupied cell on the board
 if board[y + i][x + j] != -1:
 return True

 return False
def clear\_lines(board):
 new\_board = []
 lines\_cleared = 0

 for row in board:
 if not all(cell for cell in row): # If the row is not full
 new\_board.append(row) # Keep the row in the new board
 else:
 lines\_cleared += 1 # Increment the lines\_cleared counter

 # Add empty rows to the top of the new board to maintain the same size
 empty\_row = [0 for \_ in range(GRID\_WIDTH)]
 for \_ in range(lines\_cleared):
 new\_board.insert(0, empty\_row.copy())

 return new\_board, lines\_cleared

def rotate(shape):
 # Get the dimensions of the shape
 num\_rows = len(shape)
 num\_cols = len(shape[0])

 # Create a new shape with dimensions swapped
 rotated\_shape = [[0 for \_ in range(num\_rows)] for \_ in range(num\_cols)]

 # Iterate over the cells of the original shape
 for i, row in enumerate(shape):
 for j, cell in enumerate(row):
 if cell: # If the cell is part of the shape (has a value of 1)
 # Calculate the position of the cell in the rotated shape
 new\_i = j
 new\_j = num\_rows - 1 - i

 # Copy the cell to the rotated shape
 rotated\_shape[new\_i][new\_j] = 1

 return rotated\_shape

# Main game loop
def main():
 screen = pygame.display.set\_mode((SCREEN\_WIDTH, SCREEN\_HEIGHT))
 pygame.display.set\_caption("Tetris")

 clock = pygame.time.Clock()

 # Initialize the game state
 board = [[-1 for \_ in range(GRID\_WIDTH)] for \_ in range(GRID\_HEIGHT)]
 current\_shape = random.choice(SHAPES)
 shape\_x, shape\_y = GRID\_WIDTH // 2 - len(current\_shape[0]) // 2, 0
 game\_over = False

 # Main game loop
 while not game\_over:
 screen.fill(BACKGROUND\_COLOR)

 # Handle user input
 for event in pygame.event.get():
 if event.type == pygame.QUIT:
 pygame.quit()
 sys.exit()

 if event.type == pygame.KEYDOWN:
 if event.key == pygame.K\_LEFT:
 if not check\_collision(board, current\_shape, shape\_x - 1, shape\_y):
 shape\_x -= 1
 elif event.key == pygame.K\_RIGHT:
 if not check\_collision(board, current\_shape, shape\_x + 1, shape\_y):
 shape\_x += 1
 elif event.key == pygame.K\_DOWN:
 if not check\_collision(board, current\_shape, shape\_x, shape\_y + 1):
 shape\_y += 1
 elif event.key == pygame.K\_UP:
 rotated\_shape = rotate(current\_shape)
 if not check\_collision(board, rotated\_shape, shape\_x, shape\_y):
 current\_shape = rotated\_shape

 # Update game state
 if not check\_collision(board, current\_shape, shape\_x, shape\_y + 1):
 shape\_y += 1
 else:
 # Merge the current shape with the board
 shape\_index = SHAPES.index(current\_shape)
 for i, row in enumerate(current\_shape):
 for j, cell in enumerate(row):
 if cell:
 board[shape\_y + i][shape\_x + j] = shape\_index

 # Clear lines and update the board
 board, lines\_cleared = clear\_lines(board)

 # Create a new shape and check for game over
 current\_shape = random.choice(SHAPES)
 shape\_x, shape\_y = GRID\_WIDTH // 2 - len(current\_shape[0]) // 2, 0
 if check\_collision(board, current\_shape, shape\_x, shape\_y):
 game\_over = True

 # Draw game elements on the screen
 draw\_shape(screen, current\_shape, shape\_x, shape\_y)
 for i, row in enumerate(board):
 for j, cell in enumerate(row):
 if cell != -1:
 draw\_shape(screen, SHAPES[cell], j, i)

 pygame.display.flip()
 clock.tick(4) # Adjust the speed of the game by changing the number
if \_\_name\_\_ == "\_\_main\_\_":
 main()
제가 업데이트한 게임입니다. 어떤 이유에서인지 이제 도형이 화면 하단에 닿으면 보드가 완전히 채워집니다. 왜 이런 현상이 발생하나요?

import sys
import pygame
import random

# 파이게임 초기화
pygame.init()

# 상수 정의
화면\_폭, 화면\_높이 = 800, 600
배경\_색 = (0, 0, 0)
그리드\_size = 30
grid\_width, grid\_height = screen\_width // grid\_size, screen\_height // grid\_size

# 도형 정의
SHAPES = [
 # T 도형
 [
 [1, 1, 1],
 [0, 1, 0],
 ],
 # I 도형
 [
 [1, 1, 1, 1],
 ],
 # O 도형
 [
 [1, 1],
 [1, 1],
 ],
 # L 모양
 [
 [1, 1, 1],
 [1, 0, 0],
 ],
 # J 모양
 [
 [1, 1, 1],
 [0, 0, 1],
 ],
 # S 모양
 [
 [0, 1, 1],
 [1, 1, 0],
 ],
 # Z 도형
 [
 [1, 1, 0],
 [0, 1, 1],
 ],
]

# 게임 함수 정의
def draw\_shape(screen, shape, x, y):
 shape\_color = (255, 255, 255) # 도형의 흰색 색상

 for i, row in enumerate(shape):
 for j, cell in enumerate(row):
 if cell: # 셀이 도형의 일부인 경우(값이 1인 경우)
 # 셀의 화면 위치를 계산합니다.
 screen\_x = (x + j) \* GRID\_SIZE
 screen\_y = (y + i) \* GRID\_SIZE

 # 셀의 화면에 직사각형을 그립니다.
 pygame.draw.rect(screen, shape\_color, (screen\_x, screen\_y, GRID\_SIZE, GRID\_SIZE))

 # 선택적으로 셀 주위에 테두리를 그립니다.
 border\_color = (0, 0, 0) # 테두리의 검정색
 border\_thickness = 2
 pygame.draw.rect(screen, border\_color, (screen\_x, screen\_y, GRID\_SIZE, GRID\_SIZE), border\_thickness)
def check\_collision(board, shape, x, y):
 for i, row in enumerate(shape):
 for j, cell in enumerate(row):
 if cell: # 셀이 도형의 일부인 경우(값이 1인 경우)
 # 셀이 그리드 경계를 벗어났는지 확인합니다.
 x + j < 0이거나 x + j >= GRID\_WIDTH 또는 y + i < 0이거나 y + i >= GRID\_HEIGHT인 경우:
 반환 True

 # 셀이 보드에서 점유된 셀과 겹치는지 확인합니다.
 if board[y + i][x + j] != -1:
 return True

 return False
def clear\_lines(board):
 new\_board = []
 lines\_cleared = 0

 보드의 행에 대해
 if not all(행의 셀에 대해 셀): # 행이 가득 차 있지 않은 경우
 new\_board.append(row) # 새 보드에 행을 유지합니다.
 else:
 lines\_cleared += 1 # lines\_cleared 카운터 증가

 # 새 보드의 상단에 빈 행을 추가하여 동일한 크기를 유지합니다.
 empty\_row = [0 for \_ in range(GRID\_WIDTH)]]
 for \_ in range(lines\_cleared):
 new\_board.insert(0, empty\_row.copy())

 return new\_board, lines\_cleared

def rotate(shape):
 # 도형의 치수를 가져옵니다.
 num\_rows = len(모양)
 num\_cols = len(shape[0])

 # 치수가 바뀐 새 도형을 만듭니다.
 rotated\_shape = [[범위(num\_rows) 내 \_에 대해 0] 범위(num\_cols) 내 \_에 대해]

 # 원래 도형의 셀을 반복합니다.
 for i, row in enumerate(shape):
 for j, cell in enumerate(row):
 if cell: # 셀이 도형의 일부인 경우(값이 1인 경우)
 # 회전된 도형에서 셀의 위치를 계산합니다.
 new\_i = j
 new\_j = num\_rows - 1 - i

 # 셀을 회전된 도형에 복사합니다.
 rotated\_shape[new\_i][new\_j] = 1

 반환 회전된\_도형

# 메인 게임 루프
def main():
 screen = pygame.display.set\_mode((SCREEN\_WIDTH, SCREEN\_HEIGHT))
 pygame.display.set\_caption("테트리스")

 clock = pygame.time.Clock()

 # 게임 상태 초기화
 board = [[범위(GRID\_WIDTH) 내 \_에 대해 -1] 범위(GRID\_HEIGHT) 내 \_에 대해]
 current\_shape = random.choice(SHAPES)
 shape\_x, shape\_y = GRID\_WIDTH // 2 - len(current\_shape[0]) // 2, 0
 game\_over = False

 # 메인 게임 루프
 게임\_오버가 아닌 동안:
 screen.fill(BACKGROUND\_COLOR)

 # 사용자 입력 처리
 pygame.event.get()의 event에 대해:
 if event.type == pygame.QUIT:
 pygame.quit()
 sys.exit()

 event.type == pygame.KEYDOWN:
 if event.key == pygame.K\_LEFT:
 if not check\_collision(board, current\_shape, shape\_x - 1, shape\_y):
 shape\_x -= 1
 elif event.key == pygame.K\_RIGHT:
 not check\_collision(board, current\_shape, shape\_x + 1, shape\_y):
 shape\_x += 1
 elif event.key == pygame.K\_DOWN:
 not check\_collision(board, current\_shape, shape\_x, shape\_y + 1):
 shape\_y += 1
 elif event.key == pygame.K\_UP:
 회전된\_도형 = 회전(현재\_도형)
 check\_collision(보드, 회전된\_도형, 모양\_x, 모양\_y):
 현재\_도형 = 회전된\_도형

 # 게임 상태 업데이트
 check\_collision(board, current\_shape, shape\_x, shape\_y + 1):
 shape\_y += 1
 else:
 # 현재 모양을 보드와 병합
 shape\_index = SHAPES.index(current\_shape)
 for i, row in enumerate(current\_shape):
 for j, cell in enumerate(row):
 if cell:
 board[shape\_y + i][shape\_x + j] = shape\_index

 # 줄을 지우고 보드를 업데이트합니다.
 board, lines\_cleared = clear\_lines(board)

 # 새 도형을 만들고 게임 오버를 확인합니다.
 current\_shape = random.choice(SHAPES)
 shape\_x, shape\_y = GRID\_WIDTH // 2 - len(current\_shape[0]) // 2, 0
 if check\_collision(board, current\_shape, shape\_x, shape\_y):
 game\_over = True

 # 화면에 게임 요소 그리기
 draw\_shape(screen, current\_shape, shape\_x, shape\_y)
 for i, row in enumerate(board):
 for j, cell in enumerate(row):
 if cell != 