An implementation of Sokoban in Rust

Related tags

Games game rust sokoban
Overview

sokoban-rs

Build Status crates.io License

This is an implementation of Sokoban in the Rust Programming Language.

An example level: Screenshot

Build Instructions

Before building sokoban-rs, you will need to install the developpement libraries for SDL2, preferably with the package manager that comes with your operating system.

Example for Debian/Ubuntu:

sudo apt-get install libsdl2-dev libsdl2-image-dev libsdl2-ttf-dev

Example for Mac OSX

brew install sdl2 sdl2_image sdl2_ttf

You might also like to read the README for these projects:

To build sokoban-rs, type the following commands:

git clone https://github.com/swatteau/sokoban-rs
cd sokoban-rs
cargo build --release

How to Play

This game is released without any level. You can download level collections from http://www.sourcecode.se/sokoban/levels in the SLC (XML) format. For a quick start, try this:

wget http://www.sourcecode.se/sokoban/download/microban.slc
cargo run --release -- microban.slc
  • Use the arrow keys to move the player.
  • Type R to retry the current level.
  • Type N to skip the current level.

Graphics Options

By default, the game will start in 1024x768 windowed mode. You can modify the width and height of the window as well as switch to fullscreen mode.

Example:

cargo run --release -- microban.slc --width=1920 --height=1080 --fullscreen

Credits

  • Planet Cute art by Daniel Cook (Lostgarden.com)
  • Ruji's Handwriting Font by Ruji C. (rujic.net)

License

Copyright 2015-2018 Sébastien Watteau

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Doesn't build on OS X

    Doesn't build on OS X

    I wanted to try this out, but cargo build --release fails. Is there anything special I maybe need to do? Does this maybe not work with clang?

    The error seems to be this one:

    error: linking with `cc` failed: exit code: 1
    

    which leads to this

    ld: library not found for -lSDL2_image
    

    The full output is this:

    $ cargo build --release --verbose
           Fresh bitflags v0.2.1
           Fresh bitflags v0.3.2
           Fresh libc v0.1.10
           Fresh rustc-serialize v0.3.16
           Fresh winapi v0.2.2
           Fresh bitflags v0.1.1
           Fresh winapi-build v0.1.1
           Fresh xml-rs v0.1.26
           Fresh advapi32-sys v0.1.2
           Fresh rand v0.3.10
           Fresh num v0.1.27
           Fresh sdl2-sys v0.6.2
           Fresh sdl2 v0.8.0
       Compiling sokoban-rs v0.1.1 (file:///Users/pascal/Projekte/tools/sokoban-rs)
         Running `rustc src/main.rs --crate-name sokoban_rs --crate-type bin -C opt-level=3 --out-dir /Users/pascal/Projekte/tools/sokoban-rs/target/release --emit=dep-info,link -L dependency=/Users/pascal/Projekte/tools/sokoban-rs/target/release -L dependency=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps --extern bitflags=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libbitflags-c495827ddcd6a202.rlib --extern xml=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libxml-ec337cc3dc06d297.rlib --extern sdl2_image=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2_image-91ae984502e83bb5.rlib --extern sdl2=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2-b3ed89a7752e0295.rlib`
           Fresh sdl2_image v0.2.5 (https://github.com/xsleonard/rust-sdl2_image#33381b39)
    error: linking with `cc` failed: exit code: 1
    note: "cc" "-m64" "-L" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/sokoban_rs.0.o" "-o" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/sokoban_rs" "-Wl,-dead_strip" "-nodefaultlibs" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libxml-ec337cc3dc06d297.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2_image-91ae984502e83bb5.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2-b3ed89a7752e0295.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libbitflags-425420435a0b4460.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libbitflags-c495827ddcd6a202.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libbitflags-dd68b8369bcd8ff0.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2_sys-c2fbfeba65e652ce.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libnum-397f282c1d72fe58.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/librand-aeb0317fb0b04603.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/liblibc-144c435538abd757.rlib" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/librustc_serialize-7ff5bfc027146194.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libstd-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcollections-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/librustc_unicode-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/librand-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liballoc_jemalloc-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/liblibc-35017696.rlib" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib/libcore-35017696.rlib" "-L" "/Users/pascal/Projekte/tools/sokoban-rs/target/release" "-L" "/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps" "-L" "/Users/pascal/.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib" "-L" "/Users/pascal/Projekte/tools/sokoban-rs/.rust/lib/x86_64-apple-darwin" "-L" "/Users/pascal/Projekte/tools/sokoban-rs/lib/x86_64-apple-darwin" "-l" "SDL2_image" "-l" "SDL2" "-l" "SDL2" "-l" "c" "-l" "m" "-l" "System" "-l" "pthread" "-l" "c" "-l" "m" "-Wl,-rpath,@loader_path/../../../../../.multirust/toolchains/nightly/lib/rustlib/x86_64-apple-darwin/lib" "-Wl,-rpath,/usr/local/lib/rustlib/x86_64-apple-darwin/lib" "-l" "compiler-rt"
    note: ld: warning: directory not found for option '-L/Users/pascal/Projekte/tools/sokoban-rs/.rust/lib/x86_64-apple-darwin'
    ld: warning: directory not found for option '-L/Users/pascal/Projekte/tools/sokoban-rs/lib/x86_64-apple-darwin'
    ld: library not found for -lSDL2_image
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    error: aborting due to previous error
    Could not compile `sokoban-rs`.
    
    Caused by:
      Process didn't exit successfully: `rustc src/main.rs --crate-name sokoban_rs --crate-type bin -C opt-level=3 --out-dir /Users/pascal/Projekte/tools/sokoban-rs/target/release --emit=dep-info,link -L dependency=/Users/pascal/Projekte/tools/sokoban-rs/target/release -L dependency=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps --extern bitflags=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libbitflags-c495827ddcd6a202.rlib --extern xml=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libxml-ec337cc3dc06d297.rlib --extern sdl2_image=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2_image-91ae984502e83bb5.rlib --extern sdl2=/Users/pascal/Projekte/tools/sokoban-rs/target/release/deps/libsdl2-b3ed89a7752e0295.rlib` (exit code: 101)
    

    I'm using this rust which I installed with multirust:

    $ rustc -vV
    rustc 1.4.0-nightly (8f1b0aa32 2015-08-21)
    binary: rustc
    commit-hash: 8f1b0aa32552f2e694aa8702ff2cd6d9a0e894f1
    commit-date: 2015-08-21
    host: x86_64-apple-darwin
    release: 1.4.0-nightly
    
    $ clang --version
    Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
    Target: x86_64-apple-darwin14.4.0
    Thread model: posix
    
    $ ld -v
    @(#)PROGRAM:ld  PROJECT:ld64-242.2
    configured to support archs: armv6 armv7 armv7s arm64 i386 x86_64 x86_64h armv6m armv7m armv7em
    LTO support using: LLVM version 3.6.0svn
    
    opened by killercup 3
  • Panics calling unwrap on a None

    Panics calling unwrap on a None

    I run the game as suggested in the README, but as I press any key it crashes with this message:

    thread 'main' panicked at 'called Option::unwrap() on a None value', /checkout/src/libcore/option.rs:335:20

    Follows the backtrace

    stack backtrace: 0: std::sys::imp::backtrace::tracing::imp::unwind_backtrace at /checkout/src/libstd/sys/unix/backtrace/tracing/gcc_s.rs:49 1: std::sys_common::backtrace::_print at /checkout/src/libstd/sys_common/backtrace.rs:69 2: std::panicking::default_hook::{{closure}} at /checkout/src/libstd/sys_common/backtrace.rs:58 at /checkout/src/libstd/panicking.rs:381 3: std::panicking::default_hook at /checkout/src/libstd/panicking.rs:397 4: std::panicking::rust_panic_with_hook at /checkout/src/libstd/panicking.rs:577 5: std::panicking::begin_panic at /checkout/src/libstd/panicking.rs:538 6: std::panicking::begin_panic_fmt at /checkout/src/libstd/panicking.rs:522 7: rust_begin_unwind at /checkout/src/libstd/panicking.rs:498 8: core::panicking::panic_fmt at /checkout/src/libcore/panicking.rs:71 9: core::panicking::panic at /checkout/src/libcore/panicking.rs:51 10: <core::option::Option>::unwrap at /checkout/src/libcore/macros.rs:20 11: sdl2::event::Event::from_ll at /home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-0.19.0/src/sdl2/event.rs:799 12: sdl2::event::wait_event at /home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-0.19.0/src/sdl2/event.rs:1181 13: sdl2::event::::wait_event at /home/gianmarco/.cargo/registry/src/github.com-1ecc6299db9ec823/sdl2-0.19.0/src/sdl2/event.rs:1251 14: sokoban_rs::main at src/main.rs:110 15: __rust_maybe_catch_panic at /checkout/src/libpanic_unwind/lib.rs:99 16: std::rt::lang_start at /checkout/src/libstd/panicking.rs:459 at /checkout/src/libstd/panic.rs:361 at /checkout/src/libstd/rt.rs:59 17: main 18: __libc_start_main 19: _start

    opened by garro95 2
  • Updating sdl2_ttf breaks build

    Updating sdl2_ttf breaks build

    Compiling sokoban-rs v1.0.4 (file:///tmp/sokoban-rs-master)
    src/render.rs:167:46: 167:63 error: unresolved name `sdl2_ttf::blended` [E0425]
    src/render.rs:167         let surface = self.font.render(text, sdl2_ttf::blended(self.bar_text_color)).unwrap();
                                                                   ^~~~~~~~~~~~~~~~~
    src/render.rs:167:46: 167:63 help: run `rustc --explain E0425` to see a detailed explanation
    src/main.rs:135:5: 135:21 error: unresolved name `sdl2_image::quit` [E0425]
    src/main.rs:135     sdl2_image::quit();
                        ^~~~~~~~~~~~~~~~
    src/main.rs:135:5: 135:21 help: run `rustc --explain E0425` to see a detailed explanation
    src/render.rs:56:13: 56:28 error: no associated item named `from_file` found for type `sdl2_ttf::font::Font` in the current scope
    src/render.rs:56             Font::from_file(&ttf, 20).unwrap()
                                 ^~~~~~~~~~~~~~~
    src/render.rs:80:22: 80:36 error: this function takes 3 parameters but 2 parameters were supplied [E0061]
    src/render.rs:80                     .create_and_set(PixelFormatEnum::RGBA8888, fullsize);
                                          ^~~~~~~~~~~~~~
    src/render.rs:80:22: 80:36 help: run `rustc --explain E0061` to see a detailed explanation
    src/render.rs:96:34: 96:50 error: no associated item named `new_unwrap` found for type `sdl2::rect::Rect` in the current scope
    src/render.rs:96         let original_rect = Some(Rect::new_unwrap(0, 0, fullsize.0, fullsize.1));
                                                      ^~~~~~~~~~~~~~~~
    src/render.rs:150:20: 150:36 error: no associated item named `new_unwrap` found for type `sdl2::rect::Rect` in the current scope
    src/render.rs:150         let rect = Rect::new_unwrap(0,
                                         ^~~~~~~~~~~~~~~~
    src/render.rs:167:33: 167:39 error: this function takes 1 parameter but 2 parameters were supplied [E0061]
    src/render.rs:167         let surface = self.font.render(text, sdl2_ttf::blended(self.bar_text_color)).unwrap();
                                                      ^~~~~~
    src/render.rs:167:33: 167:39 help: run `rustc --explain E0061` to see a detailed explanation
    src/render.rs:183:49: 183:65 error: no associated item named `new_unwrap` found for type `sdl2::rect::Rect` in the current scope
    src/render.rs:183         self.renderer.copy(&texture, None, Some(Rect::new_unwrap(x, y, w, h)));
                                                                      ^~~~~~~~~~~~~~~~
    src/render.rs:192:32: 192:48 error: no associated item named `new_unwrap` found for type `sdl2::rect::Rect` in the current scope
    src/render.rs:192         let target_rect = Some(Rect::new_unwrap(x,
                                                     ^~~~~~~~~~~~~~~~
    src/render.rs:216:14: 216:30 error: no associated item named `new_unwrap` found for type `sdl2::rect::Rect` in the current scope
    src/render.rs:216         Some(Rect::new_unwrap(x, y, img_size.0, img_size.1))
                                   ^~~~~~~~~~~~~~~~
    src/render.rs:298:14: 298:30 error: no associated item named `new_unwrap` found for type `sdl2::rect::Rect` in the current scope
    src/render.rs:298         Some(Rect::new_unwrap(x, y, w, h))
                                   ^~~~~~~~~~~~~~~~
    error: aborting due to 9 previous errors
    

    The update is necessary to fix ARM as the current Cargo.toml points to sdl2_ttf and sdl2_image versions that don't compile there.

    I was going to send a PR updating the dependencies but it turned out sokoban didn't compile.

    opened by MagaTailor 2
  • Arm SDL2/GLES high CPU usage (Odroid C1, libMali.so)

    Arm SDL2/GLES high CPU usage (Odroid C1, libMali.so)

    It's probably not specific to sokoban-rs but do please have a look at raw callgrind output:

    https://gist.github.com/petevine/c1ad55dcd1216737f73a

    Thanks!

    opened by MagaTailor 2
  • Cargo dependencies update

    Cargo dependencies update

    Hi,

    Due to the libstd 1.6 ARM/Android breakage that affected SDL2, the crate needed fixing meaning sokoban-rs can't be built without first updating the SDL2 crate. That will require updating the full stack.

    opened by MagaTailor 1
  • Big levels make the game panic

    Big levels make the game panic

    Big levels trigger the following error:

    thread '<main>' panicked at 'Could not get the offscreen texture', src/render.rs:83
    

    We should introduce a secondary, smaller tileset texture and fallback to this when the full-size rendering would exceed a certain limit.

    opened by swatteau 0
  • Thanks, it looks great. Some feedback

    Thanks, it looks great. Some feedback

    I just discovered and installed this. Thanks for the awesome looks. It seems there is very little feedback:

    • did I get the minimum amount of moves? and maybe possibility to retry immediately if I didn't.
    • some way to retry levels that I solved but didn't get minimum amount of moves and levels that I skipped.
    • some visual feedback of the collection, what percentage have I solved optimally.
    • maybe print the keyboard shortcuts.

    When choosing a higher resolution on the cmd line parameters, it just seems to fill the screen with black, the image doesn't actually get bigger. There is no icon shown in gnome alt-tab. I think it's possible for an executable to include that, but I didn't launch it with a .desktop file.

    opened by najamelan 0
Owner
Sébastien Watteau
Sébastien Watteau
Own implementation of Wordle as a CLI app

WordleClone Own implementation of Wordle as a CLI app. Preview Note Running this program in Window's Command Prompt may display unsatisfactory visuals

Kenneth Marinas 1 Feb 18, 2022
Twenty48 - an implementation of the 2048 where users can compete against each other

Twenty48 is an implementation of the 2048 game to demonstrate WebAssembly, Progressive Web Apps and Wasmcloud.

Jonas Hagmar 3 Mar 4, 2022
Angolmois BMS player, Rust edition

Angolmois Rust Edition This is a direct, one-to-one translation of Angolmois to Rust programming language. Angolmois is a BM98-like minimalistic music

Kang Seonghoon 95 Oct 20, 2022
4fun open-source Cave Story reimplementation written in Rust

doukutsu-rs Download latest Nightly builds (Requires being logged in to GitHub) A re-implementation of Cave Story (Doukutsu Monogatari) engine written

null 564 Jan 1, 2023
A roguelike game in Rust

A fantasy deathcrawl in Rust Work in progress. To run, with Rust compiler and Cargo package manager installed: cargo run --release When building on W

Risto Saarelma 347 Nov 21, 2022
Snake implemented in rust.

rsnake - An implementation of classic snake in rust This game was built using the piston_window window wrapper. Download the game If youre using mac-o

Maximilian Schulke 85 Jan 7, 2023
A Doom Renderer written in Rust.

Rust Doom A little Doom 1 & 2 Renderer written in Rust. Mostly written while I was learning the language about 2 years ago, so it might not the best e

Cristi Cobzarenco 2.2k Jan 1, 2023
ASCII terminal hexagonal map roguelike written in Rust

rhex Contributors welcome! Rhex is looking for contributors. See Contributing page for details. Introduction Simple ASCII terminal hexagonal map rogue

Dawid Ciężarkiewicz 137 Dec 2, 2022
A personal etude into rust software (RPG<-it's more fun to debug) development: Tales of the Great White Moose

TGWM (Tales of the Great White Moose) NB: Currently compiles. Should compile and run on both 1.28.0 and 1.31.1 if the Cargo.lock files are deleted. A

null 15 Nov 17, 2021
😠⚔️😈 A minimalistic 2D turn-based tactical game in Rust

Zemeroth is a turn-based hexagonal tactical game written in Rust. Support: patreon.com/ozkriff News: @ozkriff on twitter | ozkriff.games | facebook |

Andrey Lesnikóv 1.3k Jan 5, 2023
⬡ Zone of Control is a hexagonal turn-based strategy game written in Rust. [DISCONTINUED]

Zone of Control The project is discontinued Sorry, friends. ZoC is discontinued. See https://ozkriff.github.io/2017-08-17--devlog.html Downloads Preco

Andrey Lesnikóv 354 Nov 14, 2022
The classic tetris game written in Rust using ncurses

tetris.rs This is the classic tetris game I wrote to have a bit of fun with Rust. Installation and playing cargo install --

null 71 Jul 25, 2022
The video game for Fonts of Power. A tabletop roleplaying game made in Rust with Bevy!

The code and rules for Fonts of Power, a tactical TTRPG / video game about exploring magical places. You can follow its development in our Discord ser

null 25 Dec 23, 2022
A refreshingly simple data-driven game engine built in Rust

What is Bevy? Bevy is a refreshingly simple data-driven game engine built in Rust. It is free and open-source forever! WARNING Bevy is still in the ve

Bevy Engine 21.1k Jan 3, 2023
Data-oriented and data-driven game engine written in Rust

What is Amethyst? Amethyst is a data-driven and data-oriented game engine aiming to be fast and as configurable as possible. Principles These principl

Amethyst Engine 7.9k Dec 31, 2022
Rust library to create a Good Game Easily

ggez What is this? ggez is a Rust library to create a Good Game Easily. The current version is 0.6.0-rc0. This is a RELEASE CANDIDATE version, which m

null 3.6k Jan 4, 2023
Minesweeper game developed with Rust, WebAssembly (Wasm), and Canvas

?? click here to play the game ?? Minesweeper game Revealing all the cells without hitting the mines is the task. Each number in the cell denotes how

Karthik Nedunchezhiyan 23 Dec 28, 2022
A Gameboy emulator written in Rust

An open source Gameboy emulator written in Rust that can use a command line interface as a screen and input device.

Blake Loring 237 Dec 7, 2022
Snake Game in rust for the web

About This template shows how to create a web app using Yew and wasm-pack. ?? Usage ??️ Build When building for the first time, ensure to install depe

PsiAphex 1 Oct 24, 2021