Code Monkey home page Code Monkey logo

snake_hamiltonian_cycle_solver's Introduction

Snake_Hamiltonian_Cycle_Solver

An automated game solver of the popular 1997 game, Snake. It finds a Hamiltonian cycle using Prim's algorithm to provide the snake with a path that prevents it from colliding with a boundary or with itself.

Prim's algorithm

Prim's algorithm is generally used for the purpose of finding a minimum spanning tree for a weighted, undirected graph. However, by assigning the weights randomly we can also use this algorithm to generate random paths. This is used for the purpose of creating a randomized maze. The process involves beginning with a grid of any size.

  1. Choose a random cell to be the starting position.
  2. Keep track of all adjacent cells.
  3. Randomly choose an adjacent cell (lowest edge weight) and create a wall connecting two cells. For a 3x3 grid this can result in a configuration such as

Generating a Hamiltonian cycle

This program avoids exponential time algorithms when generating a hamiltonian cycle by doubling the width and height of the grid and creating a bubble around the randomly generated maze wall which can also be interpreted as continually following across the left side of the maze wall. Using the previously generated maze above we would get

References

https://johnflux.com/2015/05/02/nokia-6110-part-3-algorithms/ https://hurna.io/academy/algorithms/maze_generator/prim_s.html

snake_hamiltonian_cycle_solver's People

Contributors

cheranmahalingam avatar

Stargazers

 avatar  avatar

Watchers

 avatar

snake_hamiltonian_cycle_solver's Issues

pygame?

The whole piece will not run because it lacks a module named pygame.

Here is the error message

ModuleNotFoundError: No module named 'pygame'

Hamiltonian Cycle Gen

So I have been reading your code for quite a while and I have come to a stop. Where you pass the prim alg to process a hamiltonian cycle just doesn't make sense to me. I have come to ask for a more detailed version of what it really does and how in the world it works

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.