Git Product home page Git Product logo

sokoban-ruby-solver's Introduction

Sokoban IDA* Solver (Ruby) Build Status Test Coverage Code Climate

Clean and fully tested implementation of Sokoban game logic and IDA* solver in Ruby.

Installation

  • brew install sdl2 libogg libvorbis rust (on MacOS) -> rust for munkres_ru
  • Ruby. See .ruby-version for current version. rbenv is recommended to install it.
  • SDL2. brew install sdl2 on MacOS (for gosu: https://github.com/gosu/gosu/wiki/Getting-Started-on-OS-X)
  • imagemagick. brew install imagemagick on MacOS (for Sokoban image generator)

How It Works

Level internal representation

Standard representation of Sokoban levels is:

     #####                 # -> wall
     #   #                 $ -> box
     #$  #                 . -> goal
   ###  $##                * -> box on a goal
   #  $ $ #                @ -> pusher
 ### # ## #   ######       + -> pusher on a goal
 #   # ## #####  ..#         -> floor
 #    $          .*#
 ##### ### #@##  ..#
     #     #########
     #######

Positions in level start in the upper-left corner with (m=0, n=0). Example: (2, 4) means third rows and fifth cols starting in the upper-left corner ('#' in this level).

Once the files are loaded in our application, the actual representation is extended to dissociate "internal floor" and "external floor":

    #####                 # -> wall
    #sss#                 $ -> box
    #$ss#                 . -> goal
  ###ss$##                * -> box on a goal
  #ss$s$s#                @ -> pusher
###s#s##s#   ######       + -> pusher on a goal
#sss#s##s#####ss..#         -> external floor
#ssss$ssssssssss.*#       s -> internal floor
#####s###s#@##ss..#
    #sssss#########
    #######

But since it's more difficult to read, it's never printed like this in the console.

Play

When reflecting on a Sokoban solver, it's sometimes useful to manually try and solve specific situations. 2 helper methods exist for this purpose.

In both mode, use:

  • Arrow keys to move.
  • 'd' or 'backspace' to cancel the last move.
  • 'esc' to quit.

Visual Game

level = Level.new("    #####          \n"\
                  "    #   #          \n"\
                  "    #$  #          \n"\
                  "  ###  $##         \n"\
                  "  #  $ $ #         \n"\
                  "### # ## #   ######\n"\
                  "#   # ## #####  ..#\n"\
                  "# $  $     @    ..#\n"\
                  "##### ### # ##  ..#\n"\
                  "    #     #########\n"\
                  "    #######        ")

level.play

It will launch a window for you to play the game.

Console Game

Also, see https://sokoban-game.com

sokoban-ruby-solver's People

Contributors

michaelhoste avatar

Stargazers

David Silva avatar

Watchers

Romain Carlier avatar  avatar James Cloos avatar  avatar

Forkers

davidslv

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.