I am creating a snake game in Unity and I would like to implement AI snakes that wander around the globe while avoiding collision with the other snakes on the globe, and if possible I would also like to make the AI snakes purposefully trap other snakes so that the other snakes would collide and die.

enter image description here

The AI snakes must meet the following requirements:

  • They must move in a certain way. A snake is controlled by a user using the arrow keys on a keyboard, therefor I would also like the AI snakes to move using this form of input.
  • The AI snakes must move on a sphere

As I know, creating Artificial Intelligence is not an easy task and I would like to know if there are some open source projects that I can use for accomplishing this task.

  • $\begingroup$ Reminds me a lot of Tron. You might look at the code for a Tron game and see how the automated players are designed for that. Likely for those implementations they are designed heuristically. $\endgroup$
    – Tory
    Commented Oct 18, 2016 at 18:39
  • $\begingroup$ Can u send me a link to their open source or documentation because I can't see its open source on the web. $\endgroup$
    – yuval
    Commented Oct 18, 2016 at 18:43
  • $\begingroup$ TRON: Game A.I algorithm? - A few of those answers link to sites detailing some strategies and algorithms. $\endgroup$
    – Tory
    Commented Oct 18, 2016 at 18:47

4 Answers 4


A relatively simple option which uses AI techniques that are 'traditional' for adversarial games (and which is therefore less of a 'research project' than the use of Machine Learning) is Minimax.

The ingredients for this are:

  1. A list of all the actions that a snake can immediately perform from its current position.
  2. A measure of quality (a.k.a. 'fitness') for the resulting world state.

Traditionally specified for two opponents, the minimax algorithm looks a specified number of moves ahead (alternating between opponents at each turn) and attempts to find the world state that maximizes the quality measure for one opponent whilst minimizing it for the other.

An extension of the two-player algorithm to n opponents (as seemingly required by the OP) is given in this paper.


In general, AI in this type of video games is mostly pathfinding (giving the program a map of possible object positions) and/or an algorithm or series of algorithms ( so it looks random or alive ) tied to the users position ( which is known ), so there is nothing really intelligent in the strict sense, it just looks that way.

In your case I would look into using Latitude and Longitude coordinates (Most 3d engines have some variation ) as the basis for a projected grid on a sphere, your snake will also need to be constrained to the sphere surface and rules/algorithms/maps tweaked to get what you want.

  1. Divide the globe into a "cells". Each cell will have a number of neighbours depending on how you have divided your globe. Have a look at https://gamedev.stackexchange.com/questions/3360/when-mapping-the-surface-of-a-sphere-with-tiles-how-might-you-deal-with-polar-d and https://gamedev.stackexchange.com/questions/45167/square-game-map-rendered-as-sphere for ideas on how to divide your global.
  2. Once all the cells are connected, you can use an A-star search algorithm to find the optimal path for an AI "snake".
  3. Change the heuristic function so that the cells on the opposite side of the opponent are more favourable than the cells on your snake's side. That would cause the AI snake to always try to get to the other side of the opponent with the side-effect of "surrounding" the opponent.

This is a pretty tall order. I can't answer your question for you but I can suggest where to start.

You could look into making a neural network for navigation and simple behaviors.

See the following youtube video for navigation reference https://www.youtube.com/watch?v=0Str0Rdkxxo

This next video shows that using neural networks, you can have an actor make decisions based on another actor. "Tank" battle https://www.youtube.com/watch?v=u2t77mQmJiY

The rest is up to you to figure out. Practice with some simple NN's


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .