Answers.Body: <p>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.</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-19T03:45:04.197Z
Answers.LastActivityDate: 2016-10-19T03:45:04.197Z
Answers.UserDisplayName: Keno
Answers.Body: <p>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 <a href="https://en.wikipedia.org/wiki/Minimax#In_general_games" rel="nofollow">Minimax</a>.</p>
  
  <p>The ingredients for this are:</p>
  
  <ol>
  <li>A list of all the actions that a snake can immediately perform from its current position.</li>
  <li>A measure of quality (a.k.a. 'fitness') for the resulting world state.</li>
  </ol>
  
  <p>Traditionally specified for <em>two</em> 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.</p>
  
  <p>An extension of the two-player algorithm to n opponents (as seemingly required by the OP) is given in <a href="https://www.diva-portal.org/smash/get/diva2:761634/FULLTEXT01.pdf" rel="nofollow">this paper</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-18T19:27:42.860Z
Answers.LastActivityDate: 2016-10-18T19:27:42.860Z
Answers.UserDisplayName: NietzscheanAI
Answers.Body: <ol>
  <li>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 <a href="https://gamedev.stackexchange.com/questions/3360/when-mapping-the-surface-of-a-sphere-with-tiles-how-might-you-deal-with-polar-d">https://gamedev.stackexchange.com/questions/3360/when-mapping-the-surface-of-a-sphere-with-tiles-how-might-you-deal-with-polar-d</a> and <a href="https://gamedev.stackexchange.com/questions/45167/square-game-map-rendered-as-sphere">https://gamedev.stackexchange.com/questions/45167/square-game-map-rendered-as-sphere</a> for ideas on how to divide your global.</li>
  <li>Once all the cells are connected, you can use an <a href="https://en.wikipedia.org/wiki/A*_search_algorithm" rel="nofollow noreferrer">A-star search algorithm</a> to find the optimal path for an AI "snake".</li>
  <li>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.</li>
  </ol>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-20T11:56:55.070Z
Answers.LastActivityDate: 2016-10-20T11:56:55.070Z
Answers.LastEditDate: 2017-04-13T12:18:55.587Z
Answers.UserDisplayName: Jasper Citi
Answers.Body: <p>This is a pretty tall order. I can't answer your question for you but I can suggest where to start.</p>
  
  <p>You could look into making a neural network for navigation and simple behaviors.</p>
  
  <p>See the following youtube video for navigation reference 
  <a href="https://www.youtube.com/watch?v=0Str0Rdkxxo" rel="nofollow">https://www.youtube.com/watch?v=0Str0Rdkxxo</a></p>
  
  <p>This next video shows that using neural networks, you can have an actor make decisions based on another actor.
  "Tank" battle
  <a href="https://www.youtube.com/watch?v=u2t77mQmJiY" rel="nofollow">https://www.youtube.com/watch?v=u2t77mQmJiY</a></p>
  
  <p>The rest is up to you to figure out. Practice with some simple NN's </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2016-10-18T17:44:36.757Z
Answers.LastActivityDate: 2016-10-18T17:44:36.757Z
Answers.UserDisplayName: Zakk Diaz
Body: <p>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. </p>
  
  <p><a href="https://i.sstatic.net/aQ61J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/aQ61J.png" alt="enter image description here"></a> </p>
  
  <p>The AI snakes must meet the following requirements:  </p>
  
  <ul>
  <li>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.</li>
  <li>The AI snakes must move on a sphere</li>
  </ul>
  
  <p>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.</p>
  
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-18T18:39:36.200Z
Comments.Text: 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.
Comments.UserDisplayName: Tory
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-18T18:43:22.550Z
Comments.Text: Can u send me a link to their open source or documentation because I can't see its open source on the web.
Comments.UserDisplayName: yuval
Comments.ContentLicense: CC BY-SA 3.0
Comments.CreationDate: 2016-10-18T18:47:11.287Z
Comments.Text: [TRON: Game A.I algorithm?](http://gamedev.stackexchange.com/questions/8080/tron-game-a-i-algorithm) - A few of those answers link to sites detailing some strategies and algorithms.
Comments.UserDisplayName: Tory
Tags: <gaming>
Title: How to create an AI snake for a video game?
UserDisplayName: yuval
ThreadText: # How to create an AI snake for a video game?
  
  (Asked by: username_0 on 2016-10-18)
  
  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](https://i.sstatic.net/aQ61J.png)](https://i.sstatic.net/aQ61J.png)
  
  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.
  
  **Tags:** gaming
  
  > **Comments:**
  > **username_1**: 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.  
  > **username_0**: Can u send me a link to their open source or documentation because I can't see its open source on the web.  
  > **username_1**: [TRON: Game A.I algorithm?](http://gamedev.stackexchange.com/questions/8080/tron-game-a-i-algorithm) - A few of those answers link to sites detailing some strategies and algorithms.  
  
  ---
  
  ## 4 answers
  
  ### Answer by username_2 on 2016-10-19. Score: 1
  
  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.
  
  
  ---
  
  ### Answer by username_3 on 2016-10-18. Score: 1
  
  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](https://en.wikipedia.org/wiki/Minimax#In_general_games).
  
  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](https://www.diva-portal.org/smash/get/diva2:761634/FULLTEXT01.pdf).
  
  
  ---
  
  ### Answer by username_4 on 2016-10-20. Score: 1
  
  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](https://en.wikipedia.org/wiki/A*_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.
  
  
  ---
  
  ### Answer by username_5 on 2016-10-18. Score: 0
  
  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
  
  
  ---
  
  