Giter Club home page Giter Club logo

rush-hour-solver's Introduction

rush-hour-solver

A rush hour solver in Haskell. In collaboration with @sanantoniochili

The programme rush_hour.hs is an implementation in Haskell of a solver for the classic puzzle game rush hour. There are two main solvers implemented by the functions solve and solve_astar. The function solve implements a simple Bridth First Search, while solve_astar uses a heuristic described here.

The input of the solve functions is an initial state of the rush hour grid. Although a grid state is encoded internally differently, there are provided the functions readState and writeState to convert a simple string in a valid grid state. An example of such a valid state-string is given bellow.

"...a\n==.a\n....\n....\n"  

which describes the following state:

...a  
==.a  
....  
....  

The blocking cars are represented with the same character (e.g. 'a'), the red car, is represented by the character '=' and the empty places are represented by '.'. Calling the function solve (readState "...a\n==.a\n....\n....\n") in GHCi prompt, will return a list of moves in order to the red car, be unblocked. For a more user friendly list of subsequent string-states to be printed, you may use the function printSolution, see the examples bellow.

> state = readState "...a\n==.a\n....\n....\n"
> printSolution state (solve state)

...a
==.a
....
....

....
==..
...a
...a

....
..==
...a
...a

> state = readState "..abbb\n..a.c.\n..==c.\n....d.\n....d.\n....d.\n"
> printSolution state (solve_astar state)

..abbb
..a.c.
..==c.
....d.
....d.
....d.

..abbb
..a.c.
==..c.
....d.
....d.
....d.

...bbb
....c.
==..c.
....d.
..a.d.
..a.d.

.bbb..
....c.
==..c.
....d.
..a.d.
..a.d.

.bbbc.
....c.
==....
....d.
..a.d.
..a.d.

.bbbc.
....c.
....==
....d.
..a.d.
..a.d.

Notes

The file rush_hour.pdf contains a detailed description of the assignment's requirements (in Greek), while in README.pdf we describe in detail the implementation (in Greek).

Issues

If a sting-state is given to solve (or solve_astar), where there is no solution, the function will not terminate.

rush-hour-solver's People

Contributors

merkouris148 avatar

Watchers

 avatar

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.