2

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.

yuval
  • 121
  • 2
  • 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. – Tory Oct 18 '16 at 18:39
  • Can u send me a link to their open source or documentation because I can't see its open source on the web. – yuval Oct 18 '16 at 18:43
  • [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. – Tory Oct 18 '16 at 18:47

4 Answers4

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.

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.

NietzscheanAI
  • 7,206
  • 22
  • 36
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.

Keno
  • 575
  • 1
  • 3
  • 14
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 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.
Jasper Citi
  • 166
  • 1
  • 5
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

Zakk Diaz
  • 368
  • 2
  • 6