Board¶
Board 클래스는 테트리스 게임 보드의 상태를 관리하고, 충돌 감지, 줄 클리어, 특징 계산 등의 기능을 제공합니다.
API Reference¶
Board ¶
Manages the Tetris game board state and operations.
Responsibilities: - Board state management (initialization, copying) - Collision detection - Line clearing - Feature extraction (holes, bumpiness, height)
Initialize a new board.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
height
|
int
|
Number of rows in the board |
20
|
width
|
int
|
Number of columns in the board |
10
|
Source code in rl_tetris/core/board.py
reset ¶
get_state ¶
Get a copy of the current board state.
Returns:
| Type | Description |
|---|---|
List[List[int]]
|
A deep copy of the board state |
set_state ¶
Set the board state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
List[List[int]]
|
The new board state |
required |
Source code in rl_tetris/core/board.py
check_collision ¶
Check if placing a piece at the given position would cause a collision.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
piece_shape
|
List[List[int]]
|
2D array representing the piece shape |
required |
x
|
int
|
Column position of the piece's top-left corner |
required |
y
|
int
|
Row position of the piece's top-left corner |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if collision occurs, False otherwise |
Source code in rl_tetris/core/board.py
place_piece ¶
Place a piece on the board (modifies board state).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
piece_shape
|
List[List[int]]
|
2D array representing the piece shape |
required |
x
|
int
|
Column position of the piece's top-left corner |
required |
y
|
int
|
Row position of the piece's top-left corner |
required |
Source code in rl_tetris/core/board.py
clear_full_rows ¶
Clear all full rows from the board and return the number cleared.
Returns:
| Type | Description |
|---|---|
int
|
Number of rows cleared |
Source code in rl_tetris/core/board.py
get_holes ¶
Count the number of holes in the board. A hole is an empty cell with at least one filled cell above it.
Returns:
| Type | Description |
|---|---|
int
|
Number of holes |
Source code in rl_tetris/core/board.py
get_bumpiness_and_height ¶
Calculate the bumpiness and total height of the board.
Bumpiness is the sum of absolute differences between adjacent column heights. Total height is the sum of all column heights.
Returns:
| Type | Description |
|---|---|
Tuple[int, int]
|
Tuple of (bumpiness, total_height) |
Source code in rl_tetris/core/board.py
get_column_heights ¶
Get the height of each column.
Returns:
| Type | Description |
|---|---|
List[int]
|
List of column heights |
Source code in rl_tetris/core/board.py
Usage Examples¶
기본 사용법¶
from rl_tetris.core import Board, Piece
# 보드 생성 (20x10)
board = Board(height=20, width=10)
board.reset()
# 피스 생성
piece = Piece(piece_type=0) # I 피스
# 충돌 검사
can_place = not board.check_collision(piece, x=5, y=18)
if can_place:
board.place_piece(piece, x=5, y=18)
# 줄 클리어
lines_cleared = board.clear_full_rows()
print(f"Cleared {lines_cleared} lines")
특징 추출¶
# 보드 특징 계산
holes = board.get_holes()
bumpiness, height = board.get_bumpiness_and_height()
heights = board.get_column_heights()
print(f"Holes: {holes}")
print(f"Bumpiness: {bumpiness}")
print(f"Total Height: {height}")
print(f"Column Heights: {heights}")
상태 관리¶
See Also¶
- Piece - 피스 관리
- Game - 게임 로직
- BoardFeatureExtractor - 특징 추출