games.core.game.core_position¶
Position models for the game framework.
This module defines the base Position class and its specific implementations for different coordinate systems used in games.
Classes¶
Position on a grid-based board with row and column coordinates. |
|
Position on a hexagonal grid using cube coordinates. |
|
Position using floating point coordinates in a 2D space. |
|
Base class for all position types in games. |
Module Contents¶
- class games.core.game.core_position.GridPosition(/, **data)¶
Bases:
Position
Position on a grid-based board with row and column coordinates.
Used in games like Chess, Checkers, Scrabble, etc. where the board is organized as a rectangular grid of cells.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- chebyshev_distance(other)¶
Calculate the Chebyshev distance to another grid position.
This is the maximum of the horizontal and vertical distances, which corresponds to the number of moves a king in chess would need.
- Parameters:
other (GridPosition)
- Return type:
- manhattan_distance(other)¶
Calculate the Manhattan distance to another grid position.
- Parameters:
other (GridPosition)
- Return type:
- neighbors()¶
Get all adjacent grid positions (orthogonal).
- Returns:
Dictionary mapping direction names to positions.
- Return type:
- neighbors_with_diagonals()¶
Get all adjacent grid positions including diagonals.
- Returns:
Dictionary mapping direction names to positions.
- Return type:
- offset(row_offset, col_offset)¶
Create a new position that is offset from this one.
- Parameters:
- Return type:
- classmethod validate_coordinates(v)¶
Ensure coordinates are valid.
- class games.core.game.core_position.HexPosition(/, **data)¶
Bases:
Position
Position on a hexagonal grid using cube coordinates.
Used in games like Catan, hex-based war games, etc.
This uses cube coordinates (q, r, s) where q + r + s = 0.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- distance(other)¶
Calculate the distance to another hex position.
- Parameters:
other (HexPosition)
- Return type:
- classmethod from_axial(q, r)¶
Create a hex position from axial coordinates (q, r).
- Parameters:
- Return type:
- neighbors()¶
Get all adjacent hex positions.
- Returns:
Dictionary mapping direction names to positions.
- Return type:
- classmethod validate_cube_coords(v, values)¶
Ensure cube coordinates are valid (q + r + s = 0).
- class games.core.game.core_position.PointPosition(/, **data)¶
Bases:
Position
Position using floating point coordinates in a 2D space.
Used in games with continuous coordinates like territory maps or physics-based games.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- distance_to(other)¶
Calculate the Euclidean distance to another point position.
- Parameters:
other (PointPosition)
- Return type:
- offset(x_offset, y_offset)¶
Create a new position that is offset from this one.
- Parameters:
- Return type:
- class games.core.game.core_position.Position(/, **data)¶
Bases:
pydantic.BaseModel
Base class for all position types in games.
A Position represents a location in a game. Different games use different coordinate systems, so this base class is extended for specific needs.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)