Git Product home page Git Product logo

fifteen-puzzle's Introduction

Fifteen Puzzle

A classic puzzle game Fifteen Puzzle with minimalistic design, implemented in Flutter and available on Apple App Store and Google Play.

Rules

The rules are very simple. In a 4-by-4 grid, you need to arrange tiles in order, from 1 to 15 (in first row there must be tiles 1 to 4, in second 5 to 8, in third 9 to 12, and in last 13 to 15), with the bottom right corner being empty.

Puzzle generation

Not every starting composition is solvable, therefore a generating algorithm has to be introduced.

For the starting composition to be solvable, the following must be true.

  • If empty square is on even row from top to bottom, counting from 1 to 4, then the number of inversions must also be even.
  • If empty square is on odd row from top to bottom, then the number of inversions must also be odd.

Here, a pair (a,b) forms anx inversion, if a > b and a comes first in the sequence of numbers, if one is to lay them in a vector instead of 4-by-4 grid. For example, in 1,2,3,6,4,5,7,8,9,10,11,12,13,14,15 we have 2 inversions, since 6 comes before 4 and 5.

Actual algorithm

However, we are not using the points above for generation, because it would easily get complicated and potentially time consuming to generate permutations, count inversions, etc. The simpler and to human more intuitive approach is to take the solved puzzle and scramble it. So, we take a solved 4-by-4 matrix and perform a random walk of 1000 iterations with empty square. The result is the puzzle the player gets to solve. Simple, but clever, ha ๐Ÿ˜œ?

Application

iOS

"iOS Screen"

Android

"Android Screen"

Privacy Policy

Privacy policy is available here.

Contributing and error reporting

If you find an issue in game or have a good idea for a new feature, please file an issue in the issues tab or submit a pull request directly. Just keep in mind, this is a Flutter project, not native mobile development ๐Ÿ˜‰.

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.