Board (model.game.board)¶
model.game.board
¶
Chessboard representation managing piece layout, bounds, and piece movements.
Board
¶
Represents a chessboard and tracks piece positions and captures.
Source code in src/model/game/board.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
__init__(dimensions=(8, 8), setup_pieces=True)
¶
Initialize a chessboard.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensions
|
Tuple[int, int]
|
Board dimensions as (rows, cols) tuple (default: (8, 8)). |
(8, 8)
|
setup_pieces
|
bool
|
Whether to initialize pieces in standard positions (default: True). |
True
|
Source code in src/model/game/board.py
get_piece_at(position)
¶
Retrieve the piece located at the specified board position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Tuple[int, int]
|
Tuple of (row, col) coordinates. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Piece]
|
Piece instance at the position, or None if empty or out of bounds. |
Source code in src/model/game/board.py
is_within_bounds(row, col)
¶
Check if coordinates lie within the board boundaries.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
row
|
int
|
0-indexed board row. |
required |
col
|
int
|
0-indexed board column. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if (row, col) is within bounds, False otherwise. |
Source code in src/model/game/board.py
move_piece(start_pos, end_pos)
¶
Move a piece from start_pos to end_pos, tracking captured pieces.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_pos
|
Tuple[int, int]
|
Source (row, col) coordinates. |
required |
end_pos
|
Tuple[int, int]
|
Target (row, col) coordinates. |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the piece was successfully moved, False if invalid or empty start. |
Source code in src/model/game/board.py
replace_piece(position, new_piece)
¶
Replace a piece at the given position (e.g. during pawn promotion).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Tuple[int, int]
|
Target (row, col) coordinate. |
required |
new_piece
|
Piece
|
Replacement Piece instance. |
required |
Source code in src/model/game/board.py
set_piece_at(position, piece)
¶
Place or remove a piece at a specified position.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
position
|
Tuple[int, int]
|
Tuple of (row, col) coordinates. |
required |
piece
|
Optional[Piece]
|
Piece instance to place, or None to clear square. |
required |
Source code in src/model/game/board.py
setup_default_board()
¶
Initialize the board with standard 8x8 chess starting positions.