Skip to content

AdnanZahid/SnakeGameiOS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Snake Game iOS

An iOS mobile based Snake Game which relies on neural networks to navigate a grid and collect food items.

Basic components:

  1. Tensorflow
  2. Keras
  3. CoreML
  4. SpriteKit
  5. iOS

How it was built:

A Keras model was generated by training a Snake to navigate through a grid and collect food items.

This way, we generated a CSV file with the following inputs and outputs.

Inputs:

  1. Can snake move left?
  2. Can snake move forward?
  3. Can snake move right?
  4. What is the orthogonal angle between the food and snake head? This needs to be relative to current direction.
  5. A random direction

Output:

  1. On moving closer to food, it was given a score of 1.
  2. On moving away, it was given a score of 0.
  3. On dying it was given a score of -1.

Keras is a high-level framework built on top of Theano and TensorFlow. In our case, Keras was backed by TensorFlow. We built the model using the following layers:

Input layer:

5 neurons based on relu activation function

Hidden layer # 1:

25 neurons based on relu activation function

Hidden layer # 2:

25 neurons based on relu activation function

Output layer:

1 neurons based on linear activation function

The model and training algorithm was written entirely in Python, it was a good project to practice python and get good practice on Keras and Neural Networks in general. Then the model was exported to CoreML using a couple of lines of code.

Then that CoreML model was imported in iOS project and FE of the game was made in SpriteKit (2D game framework provided by Apple).

Screenshot

Inspired by the tutorial:

https://medium.com/@korolvs/today-im-going-to-talk-about-a-small-practical-example-of-using-neural-networks-training-one-to-6b2cbd6efdb3

About

iOS game that uses a Core ML model to play Snake

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages