NumberLink puzzle environment for Gymnasium
Project description
NumberLink Environment for Gymnasium
A Gymnasium environment for the NumberLink puzzle game.
Gameplay Rules
NumberLink connects matching endpoints with non overlapping paths on a grid.
NumberLink boards follow these invariants:
- Every pair of endpoints must be connected by a single path. Endpoints are enumerated in
numberlink.level_setup.LevelTemplateand copied into the environment state. - Paths cannot branch or reuse grid cells. The environment enforces this through the action mask returned by
numberlink.env.NumberLinkRGBEnv.resetandnumberlink.env.NumberLinkRGBEnv.step. - Unless the chosen variant disables the requirement, every cell must belong to a path. Toggle this rule with
numberlink.config.VariantConfig.must_fill. - Bridge cells yield independent vertical and horizontal lanes governed by
numberlink.config.VariantConfig.bridges_enabled. - Diagonal moves are allowed only when
numberlink.config.VariantConfig.allow_diagonalis set. Cell switching is controlled bynumberlink.config.VariantConfig.cell_switching_mode.
Quick links
- Quick start: Quick Start
- Google Colab: Open in Colab
- Installation guide: Installation - documentation site
- CLI reference: CLI - documentation site
- Python usage (API snippets): API reference - documentation site
- Citing this project: Cite this project
- Contact: Contact
Demo
Quick start
The NumberLink documentation covers every workflow in detail. The highlights below show the recommended Gymnasium >= 1.0 usage patterns. You can also try it out in the Google Colab example.
Install from PyPI
Using pip
pip install numberlink
Install with uv
uv pip install numberlink
See the installation guide for Pixi, Conda, and source build instructions.
Create a single environment
import gymnasium as gym
# Gymnasium discovers NumberLinkRGB-v0 from the package entry points
env = gym.make("NumberLinkRGB-v0", render_mode="rgb_array")
observation, info = env.reset(seed=42)
action_mask = info["action_mask"]
terminated = False
truncated = False
while not (terminated or truncated):
action = env.action_space.sample(mask=action_mask)
observation, reward, terminated, truncated, info = env.step(action)
action_mask = info["action_mask"]
env.close()
Configuration objects such as GeneratorConfig, VariantConfig, and RenderConfig customize generation, gameplay rules, and rendering. Examples live in the usage guide and the level setup module.
Run vectorized environments
import gymnasium as gym
from numberlink import GeneratorConfig
vec_env = gym.make_vec(
"NumberLinkRGB-v0",
num_envs=4,
render_mode="rgb_array",
generator=GeneratorConfig(width=6, height=6, colors=4),
)
observations, infos = vec_env.reset(seed=0)
actions = [vec_env.single_action_space.sample(mask=mask) for mask in infos["action_mask"]]
observations, rewards, terminated, truncated, infos = vec_env.step(actions)
vec_env.close()
Gymnasium auto resets terminated slots when the vector environment is configured with the default autoreset mode. See the vector API section of the docs for batched workflows.
Human render mode
import gymnasium as gym
import numberlink
from numberlink.viewer import NumberLinkViewer
numberlink.register_numberlink_v0()
env = gym.make("NumberLinkRGB-v0", render_mode="human")
viewer = NumberLinkViewer(env)
viewer.loop()
The pygame viewer mirrors the CLI command shown in examples/run_human.py and is documented at viewer API.
Auto-registration
Recommended usage is to install the package (for example via PyPI), and Gymnasium then discovers the environments via
the package's entry-points and you can call gymnasium.make(...) / gymnasium.make_vec(...) directly. If you need to
register the env id in-process (for development or interactive use), call:
import numberlink
numberlink.register_numberlink_v0()
See the docs for details on packaging entry-points and the registration helper: https://misaghsoltani.github.io/NumberLink/usage.html and https://misaghsoltani.github.io/NumberLink/apidocs/index.html.
License
MIT License - see LICENSE.
Cite this work
If you use NumberLink in your research, please cite:
@misc{numberlinkenv2025soltani,
author = {Soltani, Misagh},
title = {NumberLink Puzzle},
url = {https://misaghsoltani.github.io/NumberLink},
year = {2025}
}
Contact
If you have any questions or issues, please contact Misagh Soltani (misaghsoltani@gmail.com)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file numberlink-0.1.0.tar.gz.
File metadata
- Download URL: numberlink-0.1.0.tar.gz
- Upload date:
- Size: 90.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c52a1dc8ba68c0b852e3d0c7c1aa3949d5fe0c230ddc1996b458383a7be0c705
|
|
| MD5 |
7013c7fc9e642f6987b142bcb37b0625
|
|
| BLAKE2b-256 |
5983fec800775cb27928f703cd53ae519a8c88dac229c7dfe74028bc242a01b3
|
Provenance
The following attestation bundles were made for numberlink-0.1.0.tar.gz:
Publisher:
publish_to_pypi.yml on misaghsoltani/NumberLink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numberlink-0.1.0.tar.gz -
Subject digest:
c52a1dc8ba68c0b852e3d0c7c1aa3949d5fe0c230ddc1996b458383a7be0c705 - Sigstore transparency entry: 629505963
- Sigstore integration time:
-
Permalink:
misaghsoltani/NumberLink@2179a3c00271c24ca5e896c9a5567daee86a680d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/misaghsoltani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@2179a3c00271c24ca5e896c9a5567daee86a680d -
Trigger Event:
push
-
Statement type:
File details
Details for the file numberlink-0.1.0-py3-none-any.whl.
File metadata
- Download URL: numberlink-0.1.0-py3-none-any.whl
- Upload date:
- Size: 105.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6701be08edce0a14a572d311b5f60077fffc0b26fd1dcb7139e0e4011f540204
|
|
| MD5 |
f58fd31ebc1d3d6e5081bd5880cc17f1
|
|
| BLAKE2b-256 |
3c25c5a28b35cbe7732a8f8522fcfd67656f52c6da0dd0b4f245bf0fe45d843a
|
Provenance
The following attestation bundles were made for numberlink-0.1.0-py3-none-any.whl:
Publisher:
publish_to_pypi.yml on misaghsoltani/NumberLink
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
numberlink-0.1.0-py3-none-any.whl -
Subject digest:
6701be08edce0a14a572d311b5f60077fffc0b26fd1dcb7139e0e4011f540204 - Sigstore transparency entry: 629505967
- Sigstore integration time:
-
Permalink:
misaghsoltani/NumberLink@2179a3c00271c24ca5e896c9a5567daee86a680d -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/misaghsoltani
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish_to_pypi.yml@2179a3c00271c24ca5e896c9a5567daee86a680d -
Trigger Event:
push
-
Statement type: