MCPcopy Index your code
hub / github.com/dangarfield/sokoban-solver

github.com/dangarfield/sokoban-solver @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
122 symbols 253 edges 17 files 15 documented · 12%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🎮 Sokoban Solver & Game

A modern, responsive web-based Sokoban puzzle game with an intelligent solver, level editor, and solution visualizer. Play classic push-the-box puzzles or let the AI solve them for you!

Live Demo

Sokoban Solver Preview

✨ Features

🎯 Game & Solver

  • Intelligent AI Solver - Advanced A* algorithm with optimized performance
  • Real-time Progress - Watch the solver work with live progress updates
  • Solution Playback - Step through solutions move by move
  • Multiple Algorithms - Choose from BFS, DFS, UCS, or A* search methods

🎨 Level Editor

  • Visual Editor - Click cells to cycle through floor, wall, block, target, and player
  • Responsive Grid - Automatically scales to fit your screen
  • Custom Levels - Create and save your own puzzles
  • Import/Export - Share levels via URL with deep-linking support

🎮 Gameplay

  • Smooth Controls - Play with WASD, arrow keys, or on-screen buttons
  • Voice Control - Use speech recognition for hands-free play
  • Mobile Friendly - Fully responsive design works on all devices
  • Auto-progression - Automatically advance to next level when solved

💾 Data Management

  • Local Storage - All progress saved in your browser
  • Level Sharing - Generate shareable URLs for custom levels
  • Reset Option - Clear all data and start fresh
  • Cached Solutions - Previously solved puzzles load instantly

🚀 Quick Start

Online (Recommended)

Simply visit the live application - no installation required!

Local Development

# Clone the repository
git clone https://github.com/dangarfield/sokoban-solver.git
cd sokoban-solver

# Serve locally (any web server works)
npx serve .
# or
python -m http.server 8000
# or
php -S localhost:8000

# Open http://localhost:8000 in your browser

🎮 How to Play

Basic Controls

  • Movement: WASD keys or arrow keys
  • Reset Level: Escape or Space
  • Voice Commands: Say "up", "down", "left", "right", or "restart"

Level Editor

  1. Click any cell to cycle through types:
  2. Floor (empty space)
  3. Wall (obstacle)
  4. Block (pushable box)
  5. Target (goal position)
  6. Player (starting position)
  7. Target & Block together
  8. Target & Player together

  9. Save your level using the save button

  10. Share your creation with the export button

Using the Solver

  1. Click "Solve" to start the AI solver
  2. Watch progress as it explores possible moves
  3. Navigate solution with Previous/Next buttons
  4. Solutions are cached for instant replay

🧠 Solver Algorithm

The application uses Festival, a high-performance Sokoban solver that combines optimal search strategies with advanced pruning techniques.

Festival Algorithm Overview

Festival is a state-of-the-art solver originally developed in C++ by Yaron Shoham. This implementation is a Rust port compiled to WebAssembly for browser execution.

Key Features: - Pattern Database Heuristics - Pre-computed lookup tables for accurate distance estimates - Advanced Deadlock Detection - Identifies unsolvable positions early (freeze deadlock, bipartite matching) - Macro Moves - Optimizes sequences of moves into single operations - Transposition Tables - Avoids re-exploring identical board states - Lower Bound Pruning - Eliminates branches that cannot lead to optimal solutions

Performance Optimizations

  • Rust + WebAssembly - Near-native performance in the browser (10-100x faster than JavaScript)
  • Non-blocking UI - Solver runs in a Web Worker without freezing the interface
  • Real-time Progress - Live updates on explored states and search progress
  • Memory Efficient - Optimized state representation and hash tables
  • Optimal Solutions - Finds shortest push solutions for most puzzles

🎨 Level Format

Levels use the standard XSB (Extended Sokoban) text format:

Level: My Custom Level
########
#  .   #
# $  @ #
#      #
########

Symbols (XSB Standard): - # = Wall - = Floor (empty space) - $ = Box (crate to push) - . = Goal (target position) - @ = Player starting position - * = Box on goal - + = Player on goal

🔧 Configuration

Adding Levels

Edit grids/Base-Levels.txt to include new puzzles using XSB format:

Level: Easy Puzzle
####
#.@#
#$ #
####

Level: Medium Challenge
#######
#.  @ #
# $$  #
#  .  #
#######

🤝 Contributing

This project builds upon excellent work from: - KnightofLuna/sokoban-solver - Original web interface - Festival Solver - High-performance C++ solver by Yaron Shoham

Technology Stack

  • Frontend: Vanilla JavaScript, Bootstrap 5
  • Solver: Rust compiled to WebAssembly
  • Algorithm: Festival solver (pattern databases, advanced pruning)
  • Performance: Web Workers for non-blocking UI

Extension points exported contracts — how you extend this code

InitOutput (Interface)
(no doc)
festival-rust/pkg/festival_rust.d.ts

Core symbols most depended-on inside this repo

is_wall
called by 31
festival-rust/src/board.rs
add_pos
called by 29
festival-rust/src/util.rs
set
called by 23
festival-rust/src/distance.rs
is_goal
called by 16
festival-rust/src/board.rs
executeManualMove
called by 12
main.js
loadLevel
called by 9
main.js
addToExternrefTable0
called by 6
festival-rust/pkg/festival_rust.js
get
called by 6
festival-rust/src/distance.rs

Shape

Function 59
Method 43
Class 18
Enum 1
Interface 1

Languages

TypeScript56%
Rust44%

Modules by API surface

main.js24 symbols
festival-rust/pkg/festival_rust.js20 symbols
festival-rust/pkg-node/festival_rust.js15 symbols
festival-rust/src/board.rs14 symbols
festival-rust/src/search.rs13 symbols
festival-rust/src/distance.rs7 symbols
festival-rust/src/deadlock.rs7 symbols
festival-rust/src/lib.rs5 symbols
festival-rust/src/pattern_db.rs3 symbols
festival-rust/src/heuristic.rs3 symbols
festival-rust/pkg/festival_rust.d.ts3 symbols
solver-festival-rust.js2 symbols

For agents

$ claude mcp add sokoban-solver \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page