Giter VIP home page Giter VIP logo

gametreesolver-n-puzzle-game-artificial-inteligence's Introduction

Game Tree Solver: N-puzzle game (Artificial Inteligence)

Code to solve the N-puzzle game (best known as the 8 puzzle game) using a min priority queue and the A* search algorithm. This problem is a classic problem in artificial intelligence

Use any board in the specified fortmat and the program will solve it (if it has a solution) and show you the steps get the solution:

Example:

Getting Started

The repository also contains the implementetions of a min and max priority queues with useful comments if you want to know how these algorithms work. The solver.py can work using either: the included minPQ.py or using the min priority queue from the python library heapq. Read the comments inside the files for further information

You can create your own boards using either: the included random generator in the solver.py file

(a snippet of the code inside solver.py)

// code away!
n = 3   # size of the board
a = list(random.sample(range(n*n),n*n))  
blocks = [[a[n*i+j] for j in range(n)] for i in range(n) ]

where n is the size of the board. If you choose this option, change the value of n or you can create your own files in .txt formst and save them in the source_data folder. To solve those board you can use the following part of the code (also included in solver.py):

(a snippet of the code inside solver.py)

data_folder = Path("source_data/")
file_to_open = data_folder / "puzzle05.txt"
f = open(file_to_open)
n = int(f.readline())
blocks = [[ int(el) for el in line.split()] for line in f ]

To know how to build your own boards in the right format, read the comments inside solver.py. Uncomment any one of above lines of code depending in how you want to supply the boards


Installation

  • All the code and test cases required to get started, are already included in this repo

FAQ

  • will it be useful to look inside this code or it is of that kind of unreadable and ugly code?
    • Yes!!! It will be helpful to look inside, I try to write understandable code to make it accessible. Inside there are useful comments explaining how the code works and it has some cool "plain text art" to illustrate some key concepts. If you want to learn how to do similar things (solve path finding or do optimization) you should give it a try.

Support

Reach out to me at one of the following places!

  • Coming soon...

License

License

gametreesolver-n-puzzle-game-artificial-inteligence's People

Contributors

edxz7 avatar

Stargazers

 avatar  avatar

Forkers

sethips

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.