Giter VIP home page Giter VIP logo

puzzle's Introduction

Java Sliding Puzzle Solver

This application is a small command line utility used to solve the 8-puzzle game. This implementation uses the A * Search algorithm to find the goal state. The Manhattan distance is used to calculate the heuristic of the puzzle at each state. This project was written for the senior level Artificial Intelligence class at my university. An example of an initial state and goal state of the 8-puzzle game are shown below.

Initial State:

723
465
1 8

Goal State:

123
456
78

Dependencies

This is a Java project using Maven. The two dependencies you'll need are:

Usage

Being by cloning the repository, or downloading the repository as a zip file.

$ git clone https://github.com/caseyscarborough/puzzle.git && cd puzzle

Once you've retrieved the repository and are in the project's directory, you can package the project using Maven and run it manually using the following commands:

$ mvn package -P cli-dist
$ java -cp target/Puzzle.jar com.caseyscarborough.puzzle.Puzzle

If you are on a UNIX-based system, run script/build to package the application using Maven and script/puzzle to run the application:

$ script/build
$ script/puzzle

Note: This may require you to chmod the scripts make them executable: chmod u+x script/*

The application will then block and allow you to input a sliding puzzle in the following format:

0 1 2
4 5 3
7 6 8

Zeros or blank spaces can be used for the input of the application, meaning all of these inputs are valid:

1 5 2        4 1 2          4 3        0 1 2
4 0 3        5 8          1 7 6        4 5 3
7 6 8        7 3 6        8 2 5        7 6 8

Optional Parameters

You have the option to give two optional parameters. The first is a filename to read from, and the second is a filename to write the output solution to.

Windows:

> java -cp target\Puzzle.jar com.caseyscarborough.puzzle.Puzzle in.txt out.txt

Mac OS X/Linux:

$ script/puzzle in.txt out.txt

Input File Format

The format of the input file should match the same as the input you'd give on the console. This means three lines, with three numbers, each separated by a space. See below:

4 1 2
5 3 6
0 7 8

Sample Puzzles to Test

The following are some sample puzzles to test the application out with.

0 5 2
1 8 3
4 7 6

4 1 2
5 8 3
7 0 6

Note: This one takes a minute!
7 2 3
4 6 5
1 8 0

These are not solvable.
1 2 3
4 5 6
8 7 0

1 5 0
3 2 8
4 6 7

puzzle's People

Contributors

caseyscarborough avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

puzzle's Issues

Not solvable!!!

Hello,
I'm student and i have a question :)
I want to know if your work doesn't solve the puzzle or it just take a long time to solve it so we can say it s not solvable??
it seems your work solve it but it takes a lots of time?? right??

and can u explain to me how can u know if the puzzle is solvable or not??
i didn't understand the idea of the method Puzzle.isSolvable

Thank you

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.