GithubHelp home page GithubHelp logo

rlugojr / snake-star Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sacert/snake-star

0.0 0.0 0.0 68 KB

Simple implementation of an AI in Snake

Home Page: https://sacert.github.io/Snake-Star/

HTML 3.51% JavaScript 91.98% CSS 4.52%

snake-star's Introduction

Snake *

My simple attempt at creating an AI within a game.

Background

After lunch right before the long weekend, like most people, I was too lazy to do any real work. I have been interested in understanding gaming AI for quite some time, mainly after feeling the frustration of the Dark Souls AI, so I decided I'd attempt to get my feet wet in the field by attempting to create a simple pathing AI for the classic game Snake.

Demo

You can try it at: https://sacert.github.io/Snake-Star/

How it looks

Implementation

Going back to what I was taught in university, I thought of using Dijkstra's algorithm to find the shortest path from the head of the snake to the item but have read that A* is very similar to Dijkstra's algorithm but includes a heuristic for better estimating.

Solution: Using A* algorithm

While this did provide me with a snake that did get to the item (apple) the fastest, it would also make a lot of errors such as not working at all if the snake's body was long enough to prevent the head from reaching the item.

Soltuion: Move to a direction furthest from the item to attempt to 'stall' it

This would move the snake's body enough such that there would be a path from head to item although this lead to another difficulty as the snake's head would sometimes move in a direction that would tunnel it to immediate death.

Solution: *Take into factor the number of available spaces within my calculation of determining the next node and choose one that would net the snake the most amount of available movements for stalling

While the AI at this point does work moderately well, it still with make errors such as going for items that will instantly cause it to die or when performing 'stalling', not use all available spaces.

Remarks

While I did think this would be an easy experiment that could be completed within a time frame of roughly 4 hours, something even as simple as creating an AI in snake can be challenging as there are multiple measures to account for. I may spend time when there isn't much work to strengthen the AI but for now, it was a fun little experiment to get a grasp at AI implementation.

snake-star's People

Contributors

sacert avatar

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.