Giter Site home page Giter Site logo

redwn / prolog-akari Goto Github PK

View Code? Open in Web Editor NEW
6.0 1.0 0.0 252 KB

A solver to a game called "akari" (https://krazydad.com/play/akari/) using SWI-Prolog.

Prolog 82.12% Gnuplot 0.52% JavaScript 7.06% GLSL 0.11% C++ 9.43% Meson 0.47% Python 0.28%
ai cpp js prolog puzzle-solver lights-out-game

prolog-akari's Introduction

Prolog-Akari -- Hawks Team's Version

Running The Game

TODO

Conventions

Predicates that end with __ are considered private and should not be exposed as public APIs.

Unit Testing

Here's a guide that is actually readable on unit testing in prolog: http://pbrown.me/blog/swi_prolog_unit_testing_env/

Summary:

  1. Load the project's file using SWI-Prolog's CLI command swipl project.pl
  2. Type load_test_files([make(all)]).
  3. Type run_tests. to actually run tests
  4. Whenever you want to run tests again, type make.

In the utils folder, you can find an example map that you can work on.

Maps

There's a map parser in the utils folder that can do the following:

  1. Fetch an Akari map from https://krazydad.com/play/akari/, parse it, and write it to kb.pl.
  2. Parse a string map from utils/map.txt and write it to kb.pl.

Its current implementation does the first thing, but you can fiddle around a bit with the code in utils/map-parser.js to read a map from a text file. (The function readMapFromFile exists, you just have to invoke it).

Example of a string map

This is a string representation of an 8 x 8 grid.

..1............2.#...1.3#....#.....2.#...0.2##.1....#.###.#...2.1.....1....#2.2...1.0............#..

  • Numbers represent walls with numbers.
  • . represent normal cells.
  • # represent normal walls.

How generating maps works

The parser first fetches the whole HTML string of the webpage, and then applies a regular expression against it so it can extract the string representation of the map. The string of the map exists in the HTML source code, you just have to find it.

If you're curious, you can inspect the source code of Akari's website using your browser's devtools.

Invoking the parser

First, make sure that you have Node installed on your machine.

  1. Copy the URL of the map that you want.

  2. Run the map parser and pass it the URL of the map like this: node utils/map-parser.js "https://krazydad.com/play/akari/?kind=8x8&volumeNumber=2&bookNumber=8&puzzleNumber=16"
    Note that the URL has to be double quoted

  3. You will find the appropriate predicates written to a file called kb.pl in the root directory of the project.

Knowledge base

  • wall_num(X, Y, GoalNumberOfLights): Means that cell X, Y is a wall that has a number, GoalNumberOfLights. This number represents the number of lights that should be present around the cell. So wall_num(2, 3, 4) should have 4 light cells around it.
  • wall(X, Y): Means that cell X, Y is a normal wall.
  • size(Rows, Columns): Size of the game's grid. Note that the grid should be a square.
  • lit(cell(X, Y)): Means that cell X, Y is lit by a light.
  • light(cell(X, Y)): Means that cell X, Y is a light source.

Graphically Represented Results

You can use our provided C++ project which in turn runs a SWI-Prolog instance within it, that relies on "project.pl" file, to see the puzzle before and after -if the algorithm could solve- solving.

Building

Make sure you have the following dependencies:

  • SFML development libraries
  • glbinding development libraries
  • SWI-Prolog development library With these installed you can build using the provided Meson script.

Running

Run the application with the path to "project.pl" being the second command line argument. Press the space button and the algorithm will attempt to solve the puzzle. In case the algortithm failed to solve the puzzle, it will basically freeze the app until you close it.

Snapshots

snapshot-1 snapshot-2 snapshot-3

P.S : All the provided textures are public domain.

Solution Algorithm

TODO: @redwn please elaborate on the algorithm here.

TODO

  • Adjust variable names
  • Adjust whitespace
  • Solve project using very advanced techniques
  • Use modules to hide private implementations
  • Write explanatory comments for complicated predicates
  • Write unit tests

prolog-akari's People

Contributors

hasanmothaffar avatar red1c3 avatar redwn avatar tarook0 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  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.