Skip to main content

Puzzle15Gym

codecov PyPI version

A custom AI Gym environment for the 15-puzzle game: https://en.wikipedia.org/wiki/15_puzzle.

The blank space is represented by -1.

Library used: GitHub.

Usage

Initiating the env via gym

import gym

env_3x3_random = gym.make('Puzzle3x3Random-v0')
env_3x3_fixed = gym.make('Puzzle3x3Fixed-v0')

env_4x4_random = gym.make('Puzzle4x4Random-v0')
env_4x4_fixed = gym.make('Puzzle4x4Fixed-v0')

env_5x5_random = gym.make('Puzzle5x5Random-v0')
env_5x5_fixed = gym.make('Puzzle5x5Fixed-v0')

Initiating the env directly

from puzzle15Gym import Puzzle15Env

env_random = Puzzle15Env(height=4, width=4)
env_fixed = Puzzle15Env(custom_puzzle="2 8 6|7 1 3|-1 5 4")

Making moves

import gym

env_3x3_random = gym.make('Puzzle3x3Random-v0')

# Reset the environment
observation, info = env_3x3.reset()

# Make a random valid move
import random

valid_actions = info["valid_actions"]
random_action = random.choice(list(valid_actions))
observation, reward, done, truncated, info = env_3x3.step(random_action)

# Render the environment. The only render mode is 'human' which renders visual output.
env_3x3.render()

# Close the environment
env_3x3.close()

Environment Details

  • Action Space: Discrete(4) - 0: up, 1: right, 2: down, 3: left.
  • Observation Space: Box(-1, height*width-1, (height*width), int32). Contains unique values from -1 to (width * height - 1), excluding 0.
  • Reward: 1 if the puzzle is solved, 0 if not, -2 if invalid move.
  • Done: True if the puzzle is solved, False otherwise.

Metadata

Release files for puzzle15Gym 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for puzzle15Gym 1.0.3
File Size Uploaded
puzzle15gym-1.0.3.tar.gz 17.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for puzzle15Gym 1.0.3
File Interpreter ABI Platform
puzzle15gym-1.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 35.0 kB

Release files / puzzle15gym-1.0.3.tar.gz

Download URL puzzle15gym-1.0.3.tar.gz
Size 17.7 kB
Tags Source
SHA-256 checksum
How to use checksums
083300ff3ffa02dda04066cb085ecbc3f81e1716d41b679991f8c5f1f1a1198e
BLAKE2b-256 checksum
How to use checksums
7471a1ef38687ae624990b99dc1398740f8648bd4ec98ff66e0a9b6c180d200a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release files / puzzle15gym-1.0.3-py3-none-any.whl

Download URL puzzle15gym-1.0.3-py3-none-any.whl
Size 17.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9aff823e3c98f3b8f68fc35d9f6ca755c58484545a9a10d78c5a4316d5354d00
BLAKE2b-256 checksum
How to use checksums
9febca9f00ae58ffd0ebd4b2965f6e73b5f4cffa3f20b5d5b687b2ac15409922
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.9

Release history Release notifications | RSS feed

This release

1.0.3 This release

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page