Skip to main content

A custom AI Gym environment for the sliding block puzzle game

Project description

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
import puzzle15Gym

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_random = Puzzle15Env(custom_puzzle="2 8 6|7 1 3|-1 5 4")

Making moves

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

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

# Take a step
action = env_3x3.action_space.sample()
observation, reward, done, truncated, info = env_3x3.step(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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

puzzle15gym-1.0.1.tar.gz (17.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

puzzle15gym-1.0.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file puzzle15gym-1.0.1.tar.gz.

File metadata

  • Download URL: puzzle15gym-1.0.1.tar.gz
  • Upload date:
  • Size: 17.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for puzzle15gym-1.0.1.tar.gz
Algorithm Hash digest
SHA256 12c6e9f0699ccbef0b046f857424ef7ebde13f9e2b575ec5b239fa1321613416
MD5 cb57edcec1bd0b0b94a3b77af1b9c47a
BLAKE2b-256 5c12c3a81d75c0594a24c567ff2003a5b84c0394dab7ca08bc9db88c3ce9b6ba

See more details on using hashes here.

File details

Details for the file puzzle15gym-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: puzzle15gym-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for puzzle15gym-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dadeb5f40e981a73131a18cdb30fbb78137f9d3e8c9de0f759779ac3657a5f41
MD5 dfa84cfffbc150b638c60f867d650d16
BLAKE2b-256 8e70ec151dafb7621852a5cfdd69e4acd55f45a7de5e39b2df621acfb979b02f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page