numberlink.levelsΒΆ
Level definitions for the numberlink.env.NumberLinkRGBEnv environment.
This module defines the numberlink.levels.Level dataclass and the numberlink.levels.LEVELS mapping of
built-in level definitions. Each numberlink.levels.Level stores a row oriented grid where uppercase letters
denote endpoint cells and '.' denotes empty cells. Optional bridge coordinates may be supplied to mark bridge cells
used by level construction in numberlink.
Use numberlink.levels.Level to define custom levels or access numberlink.levels.LEVELS for examples.
Module ContentsΒΆ
ClassesΒΆ
Static representation of a NumberLink puzzle board. |
FunctionsΒΆ
Read non-empty, stripped lines from a package resource file. |
|
Attempt to load a JSON solution adjacent to a grid file. |
|
Create a Level from a packaged |
|
Load a level from a text file with an optional adjacent solution. |
|
Load up to |
DataΒΆ
APIΒΆ
- class numberlink.levels.Level[source]ΒΆ
Static representation of a NumberLink puzzle board.
Represent a board as a list of row strings. Uppercase letters denote endpoint cells and
'.'denotes an empty cell. Optionally include a sequence of bridge coordinates to indicate bridge cells. An optional precomputed solution can be attached for O(1) retrieval by the viewer or tools.- Parameters:
grid (list[str]) β Row oriented grid where each string represents a board row.
bridges (collections.abc.Iterable[tuple[int, int]] or None) β Coordinates treated as bridge cells by
numberlink.level_setup.build_level_template()when building an environment instance. May beNonewhen not used.solution (list[list[tuple[int, int]]] or None) β Optional list of paths where each path is a list of
(row, column)coordinate tuples. Path order corresponds to the color order implied by the grid letters.
- bridges: collections.abc.Iterable[Coord] | None = None[source]ΒΆ
- numberlink.levels._read_text_lines(res_file: importlib.resources.abc.Traversable) list[str][source]ΒΆ
Read non-empty, stripped lines from a package resource file.
- numberlink.levels._load_solution_json(res_file: importlib.resources.abc.Traversable) list[list[Coord]] | None[source]ΒΆ
Attempt to load a JSON solution adjacent to a grid file.
Expected JSON format: list of paths, where each path is a list of
[row, col]pairs. ReturnsNonewhen the file doesnβt exist.
- numberlink.levels._level_from_asset(txt_name: str) numberlink.levels.Level[source]ΒΆ
Create a Level from a packaged
assets/levels/*.txtresource.Also attempts to load an optional
.sol.jsonwith the same stem for solution coordinates.
- numberlink.levels.load_level_from_file(txt_path: str | pathlib.Path) numberlink.levels.Level[source]ΒΆ
Load a level from a text file with an optional adjacent solution.
The grid file must contain one row per line. Leading/trailing whitespace and empty lines are ignored. If a solution file is present alongside the grid with suffix
.sol.jsonappended to the grid filename, it is parsed and attached to the returnedLevel.Example:
/path/to/board.txtwith optional/path/to/board.txt.sol.json.
- numberlink.levels._scan_asset_levels(limit: int = 20) dict[str, numberlink.levels.Level][source]ΒΆ
Load up to
limitlevels from packaged assets into a mapping.Level ids are derived from the filename stem with a
file_prefix, for examplefile_5x5_01.
- numberlink.levels.BUILTIN_LEVELS: dict[str, numberlink.levels.Level] = None[source]ΒΆ
- numberlink.levels.LEVELS: dict[str, numberlink.levels.Level] = None[source]ΒΆ