Skip to main content

Crate soukoban

Crate soukoban 

Source
Expand description

§soukoban

docs.rs Test status Code coverage

A library providing implementations of algorithms and data structures related to Sokoban.

§Features

  • Solver
    • Search algorithms: Supports A*, IDA*, GBFS and BFS search.
    • Strategies: Supports quick, push-optimal, and move-optimal strategies.
  • Level
    • Zero-allocation lazy parsing: Parses levels lazily from an in-memory string without memory allocations except for level creation.
    • Lazy stream parsing: Parses levels lazily from a stream.
    • Map reconstruction: Reconstructs the map from the solution.
    • Canonicalization: Removes elements from the map that are not relevant to the solution.
    • RLE support: Enables loading of levels encoded in Run-Length Encoding (RLE) format.
    • Symmetry transformations: Supports rotating and flipping levels.
  • Actions
    • Reversal move handling: Automatically interprets reversal moves as undo actions.
    • Metrics calculation: Computes metrics such as box_lines, box_changes, pushing_sessions, and player_lines.
    • Symmetry transformations: Supports rotating and flipping action sequences mapping.
  • Pathfinding: Finds paths for box/player with support for different strategies.
  • Deadlock detection: Detects static deadlocks and freeze deadlocks.

§Example

use std::str::FromStr as _;
use soukoban::{prelude::*, solver::*};

fn main() {
    // Create a sequence of actions from a LURD string
    let actions = Actions::from_str("R").unwrap();

    // Reconstruct the map from the actions
    let map = Map::from_actions(actions.clone()).unwrap();

    // Print the reconstructed map
    //
    // #####
    // #@$.#
    // #####
    println!("{map}");

    // Search for a solution using A* algorithm
    let solution = Solver::new(map, Strategy::Quick)
        .search(Algorithm::AStar)
        .unwrap();

    // Verify the solution matches the original actions
    assert_eq!(solution, actions);
}

§License

Licensed under either of

at your option.

The level files in the assets directory are licensed solely under their respective licenses, available in the LICENSE file in the directory.

Modules§

action
An action.
actions
A sequence of actions.
deadlock
Utilities for deadlocks detection.
direction
A direction.
error
Error types.
level
A level.
map
A grid-based map.
path_finding
Utilities for path finding.
prelude
Convenience re-export of common structs and functions.
solver
A solver for the Sokoban problem.
tiles
Flags which can represent elements contained in map cells.

Type Aliases§

FxHashMap
Type alias for a hash map that uses the Fx hashing algorithm.
FxHashSet
Type alias for a hash set that uses the Fx hashing algorithm.
Vector2
A stack-allocated, 2-dimensional column vector.