games.single_player.flow_free.state¶

State model for Flow Free game.

This module defines the game state for Flow Free, tracking the board, flows, and game progress.

Classes¶

Cell

A cell on the Flow Free board.

Flow

A flow in Flow Free, consisting of two endpoints and a path of pipes.

FlowEndpoint

An endpoint (colored dot) in Flow Free.

FlowFreeState

State for the Flow Free game.

Module Contents¶

class games.single_player.flow_free.state.Cell(/, **data)¶

Bases: pydantic.BaseModel

A cell on the Flow Free board.

Parameters:

data (Any)

position¶

Position of the cell.

flow_id¶

ID of the flow occupying this cell, if any.

is_endpoint¶

Whether this cell contains an endpoint.

pipe_direction¶

Direction of the pipe in this cell, if any.

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.

class games.single_player.flow_free.state.Flow(/, **data)¶

Bases: pydantic.BaseModel

A flow in Flow Free, consisting of two endpoints and a path of pipes.

Parameters:

data (Any)

id¶

Unique identifier for the flow.

color¶

Color of the flow.

start¶

Starting endpoint.

end¶

Ending endpoint.

path¶

List of positions forming the path between endpoints.

completed¶

Whether the flow is complete (endpoints connected).

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.

class games.single_player.flow_free.state.FlowEndpoint(/, **data)¶

Bases: pydantic.BaseModel

An endpoint (colored dot) in Flow Free.

Parameters:

data (Any)

position¶

Position of the endpoint on the board.

is_start¶

Whether this is the start endpoint (otherwise it’s the end).

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.

class games.single_player.flow_free.state.FlowFreeState(/, **data)¶

Bases: haive.games.single_player.base.SinglePlayerGameState

State for the Flow Free game.

Parameters:

data (Any)

rows¶

Number of rows in the grid.

cols¶

Number of columns in the grid.

grid¶

2D grid of cells.

flows¶

Dictionary of flows by ID.

current_flow_id¶

ID of the currently selected flow.

puzzle_id¶

Identifier for the current puzzle.

hints_used¶

Number of hints used.

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.

get_adjacent_positions(position)¶

Get all valid adjacent positions.

Parameters:

position (haive.games.single_player.flow_free.models.Position) – Position to get adjacent positions for.

Returns:

List of adjacent positions.

Return type:

list[haive.games.single_player.flow_free.models.Position]

get_cell(position)¶

Get the cell at the specified position.

Parameters:

position (haive.games.single_player.flow_free.models.Position) – Position to get the cell for.

Returns:

The cell at the position, or None if out of bounds.

Return type:

Cell | None

is_cell_empty(position)¶

Check if a cell is empty.

Parameters:

position (haive.games.single_player.flow_free.models.Position) – Position to check.

Returns:

True if the cell is empty, False otherwise.

Return type:

bool

is_cell_endpoint(position)¶

Check if a cell contains an endpoint.

Parameters:

position (haive.games.single_player.flow_free.models.Position) – Position to check.

Returns:

True if the cell contains an endpoint, False otherwise.

Return type:

bool

to_display_string()¶

Generate a string representation of the board for display.

Returns:

A formatted string representation of the board.

Return type:

str

property board_fill_percentage: float¶

Calculate the percentage of the board that is filled.

Return type:

float

property completion_percentage: float¶

Calculate the percentage of flows completed.

Return type:

float

property filled_cells: int¶

Calculate the number of filled cells on the board.

Return type:

int

property is_solved: bool¶

Check if the puzzle is solved.

The puzzle is solved when all flows are completed and all cells are filled.

Return type:

bool

property total_cells: int¶

Calculate the total number of cells on the board.

Return type:

int