mohsen zamani
2 years ago
4 changed files with 0 additions and 148 deletions
-
5.firebaserc
-
65Auto_solver_README.md
-
62README.md
-
16firebase.json
@ -1,5 +0,0 @@ |
|||||
{ |
|
||||
"projects": { |
|
||||
"default": "flutterpuzzle-eaf89" |
|
||||
} |
|
||||
} |
|
@ -1,65 +0,0 @@ |
|||||
# Auto solver implementation with A-star |
|
||||
|
|
||||
The board is represented as a 1D array initially, which is converted to a 2D matrix(list of list of int). |
|
||||
|
|
||||
Lets understand the implementation with a 3 * 3 slide puzzle. However, this will work for any nXn slide puzzle. |
|
||||
|
|
||||
``` |
|
||||
[1 2 3 4 5 6 7 8 ] |
|
||||
|
|
||||
Let's use the A star algorithm to solve the 8 puzzle problem. |
|
||||
|
|
||||
Let the initial state be |
|
||||
|
|
||||
[] |
|
||||
|
|
||||
Let the goal state be |
|
||||
|
|
||||
[] |
|
||||
|
|
||||
The search tree for the initial state will look like this |
|
||||
|
|
||||
At each step, we move our empty block either left or down. We need to make sure we do not reach the original state through these moves, as they can lead to infinite loops. |
|
||||
|
|
||||
There are two entities we need to keep into mind |
|
||||
|
|
||||
G is the number of steps required to reach the goal state from the initial state. Estimated number of steps from current state to goal state. |
|
||||
|
|
||||
H is Manhattan distance. It is the estimated distance to goal. |
|
||||
|
|
||||
It can be calculated by adding the difference in the row and column for all the blocks of the initial state from the goal state. |
|
||||
|
|
||||
Identify the path with the minimum g+h. |
|
||||
|
|
||||
|
|
||||
These are the variables in `puzzle_solver.dart` : |
|
||||
|
|
||||
* queue - Priority queue |
|
||||
* visited - set |
|
||||
* goal_states - list |
|
||||
* root - object of Node class |
|
||||
* board: board |
|
||||
* previous: null, |
|
||||
* heuristic: manhattan(board, goalStates[currGoal]) |
|
||||
* depth: int |
|
||||
|
|
||||
>Each node can have maximum of 4 children, the graph fill further expand in a similar fashion with each child pointing to the parent using pointer. |
|
||||
|
|
||||
>The g score here, which is the cost of the move will increase by 1 at each depth since each tile sliding to the blank space represents one move and in the end we need to get the optimal moves for the puzzle instance, this basically mean that we have to add 1 to the g score of the parent before storing it in the child nodes. |
|
||||
|
|
||||
>Heuristics returns the number of tiles that are not in their final position |
|
||||
|
|
||||
>Manhattan Distance of a tile is the distance or the number of slides/tiles away it is from it’s goal state.Thus, for a certain state the Manhattan distance will be the sum of the Manhattan distances of all the tiles except the blank tile. |
|
||||
|
|
||||
Functions : |
|
||||
|
|
||||
* rowColGoalStates() - Returns the goal states for the slide puzzle |
|
||||
|
|
||||
queue is initialised with the first node object, the initial board configuration. |
|
||||
|
|
||||
We loop till the queue isnt empty. |
|
||||
|
|
||||
Inside the loop, we pop an element from the top. |
|
||||
|
|
||||
If it possible to reach the goal state from that configuration |
|
||||
|
|
@ -1,62 +0,0 @@ |
|||||
# Flutter Puzzle |
|
||||
|
|
||||
[![Codemagic build status](https://api.codemagic.io/apps/61f7d22dafa5dd12bdc7c1bf/61f7d22dafa5dd12bdc7c1be/status_badge.svg)](https://codemagic.io/apps/61f7d22dafa5dd12bdc7c1bf/61f7d22dafa5dd12bdc7c1be/latest_build) |
|
||||
|
|
||||
> Web App link: https://flutterpuzzle.codemagic.app |
|
||||
|
|
||||
![](screenshots/photo_mode.gif) |
|
||||
|
|
||||
Playing a game or solving a puzzle is always fun when you share with friends. We have created a puzzle that consists of three main modes: |
|
||||
|
|
||||
* **Normal mode:** The classic slide puzzle configuration. |
|
||||
* **Photo mode:** Ability to generate puzzles from any image uploaded. |
|
||||
* **Multiplayer mode:** Play with others in a competitive head-to-head multiplayer mode. |
|
||||
|
|
||||
The puzzle also has an auto solver built-in, it uses the A* algorithm along with some pretty neat tricks to solve the puzzle in the lowest possible moves. |
|
||||
|
|
||||
A full explanation of how the A* algorithm works is [here](https://youtu.be/nwtOWpSKGHc). |
|
||||
|
|
||||
The puzzle uses **Rive** to display an animated Dash beside the puzzle. |
|
||||
|
|
||||
**Riverpod** is used for state management inside the puzzle. The app has pretty challenging state management as there are three modes and the puzzle state is persisted across both the photo mode and the multiplayer mode. |
|
||||
|
|
||||
We also used a color palette generator package that can create an entire color palette from just an image, it is used in photo mode to change the theme of the screen according to the image selected. |
|
||||
|
|
||||
## Screenshots |
|
||||
|
|
||||
**Normal mode:** |
|
||||
|
|
||||
![](screenshots/puzzle_normal.png) |
|
||||
|
|
||||
**Photo mode:** |
|
||||
|
|
||||
![](screenshots/puzzle_photo.png) |
|
||||
|
|
||||
**Multiplayer mode:** |
|
||||
|
|
||||
![](screenshots/puzzle_multiplayer_1.png) |
|
||||
|
|
||||
![](screenshots/puzzle_multiplayer.png) |
|
||||
|
|
||||
|
|
||||
## License |
|
||||
|
|
||||
Copyright (c) 2022 Soumi Bardhan, Souvik Biswas |
|
||||
|
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy |
|
||||
of this software and associated documentation files (the "Software"), to deal |
|
||||
in the Software without restriction, including without limitation the rights |
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
|
||||
copies of the Software, and to permit persons to whom the Software is |
|
||||
furnished to do so, subject to the following conditions: |
|
||||
|
|
||||
The above copyright notice and this permission notice shall be included in all |
|
||||
copies or substantial portions of the Software. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
|
||||
SOFTWARE. |
|
@ -1,16 +0,0 @@ |
|||||
{ |
|
||||
"hosting": { |
|
||||
"public": "build/web", |
|
||||
"ignore": [ |
|
||||
"firebase.json", |
|
||||
"**/.*", |
|
||||
"**/node_modules/**" |
|
||||
], |
|
||||
"rewrites": [ |
|
||||
{ |
|
||||
"source": "**", |
|
||||
"destination": "/index.html" |
|
||||
} |
|
||||
] |
|
||||
} |
|
||||
} |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue