Piece (model.pieces.piece)¶
model.pieces.piece
¶
Base piece module defining the foundational Piece abstraction for chess.
Piece
¶
Base class for all chess pieces.
Attributes:
| Name | Type | Description |
|---|---|---|
_type |
The piece type descriptor (e.g. "pawn", "king", 1, -1). |
|
_vectors |
List of relative coordinate move offsets (row_delta, col_delta). |
|
_attack_vectors |
List of relative coordinate attack offsets. |
|
_can_jump |
Boolean indicating whether piece can leap over other pieces. |
|
_name |
Human-readable display name of the piece. |
Source code in src/model/pieces/piece.py
__init__(color, piece_type, vectors=None, attack_vectors=None, can_jump=False, name=None)
¶
Initialize a new chess piece.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
color
|
Any
|
Color identifier (1 for White, -1 for Black). |
required |
piece_type
|
Any
|
Piece identifier or type descriptor. |
required |
vectors
|
Optional[List[Tuple[int, int]]]
|
Optional movement vectors. |
None
|
attack_vectors
|
Optional[List[Tuple[int, int]]]
|
Optional attack vectors (defaults to vectors if None). |
None
|
can_jump
|
bool
|
Whether this piece can jump over other pieces. |
False
|
name
|
Optional[str]
|
Optional display name for the piece. |
None
|
Source code in src/model/pieces/piece.py
canJump()
¶
Check whether the piece can jump over other pieces.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if jumping is enabled, False otherwise. |
getAttackDirections()
¶
Return the attack vectors for this piece.
Returns:
| Type | Description |
|---|---|
Optional[List[Tuple[int, int]]]
|
Optional[List[Tuple[int, int]]]: Attack movement vectors, defaulting to standard vectors. |
Source code in src/model/pieces/piece.py
getColor()
¶
Return the piece's player color code.
Returns:
| Name | Type | Description |
|---|---|---|
Any |
Any
|
Color representation (1 for White, -1 for Black). |
getDirections()
¶
Return the standard movement vectors for this piece.
Returns:
| Type | Description |
|---|---|
Optional[List[Tuple[int, int]]]
|
Optional[List[Tuple[int, int]]]: List of (row_offset, col_offset) tuples, or None. |