All Projects → HectorPulido → Evolutionary Neural Networks On Unity For Bots

HectorPulido / Evolutionary Neural Networks On Unity For Bots

Licence: mit
Neural networks + Genetic algorithm on unity

Projects that are alternatives of or similar to Evolutionary Neural Networks On Unity For Bots

Regoap
Generic C# GOAP (Goal Oriented Action Planning) library with Unity3d examples
Stars: ✭ 600 (+1478.95%)
Mutual labels:  ai, unity, gamedev
Consolation
In-game debug console for Unity.
Stars: ✭ 489 (+1186.84%)
Mutual labels:  unity, gamedev
Enet Csharp
Reliable UDP networking library
Stars: ✭ 464 (+1121.05%)
Mutual labels:  unity, gamedev
Entitas Csharp
Entitas is a super fast Entity Component System (ECS) Framework specifically made for C# and Unity
Stars: ✭ 5,393 (+14092.11%)
Mutual labels:  unity, gamedev
Enhancer
A collection of utilities to enhance the Unity Editor
Stars: ✭ 394 (+936.84%)
Mutual labels:  unity, gamedev
Holoshield
Highly customizable sci-fi shield / force field shader for Unity3D. Allows you to set edge power & color, inner texture scrolling, waviness, scale pulsation and procedural intensity noise. Implements tessellation for low-poly base meshes.
Stars: ✭ 401 (+955.26%)
Mutual labels:  unity, gamedev
Anything about game
A wonderful list of Game Development resources.
Stars: ✭ 541 (+1323.68%)
Mutual labels:  unity, gamedev
Spheredissolve
Customizable procedural spherical dissolve shader for Unity3D, for all your customizable procedural spherical dissolve needs!
Stars: ✭ 311 (+718.42%)
Mutual labels:  unity, gamedev
Gameproject3
游戏服务器框架,网络层分别用SocketAPI、Boost Asio、Libuv三种方式实现, 框架内使用共享内存,无锁队列,对象池,内存池来提高服务器性能。还包含一个不断完善的Unity 3D客户端,客户端含大量完整资源,坐骑,宠物,伙伴,装备, 这些均己实现上阵和穿戴, 并可进入副本战斗,多人玩法也己实现, 持续开发中。
Stars: ✭ 655 (+1623.68%)
Mutual labels:  unity, gamedev
Radialprogressbar
Customizable radial progress bar shader for Unity3D. Allows you to set arc range, minimum and maximum colors, textures, radius, and a few more things. Create HP Bars, Speedometers, rank progress, etc!
Stars: ✭ 714 (+1778.95%)
Mutual labels:  unity, gamedev
Construct
JavaScript Digital Organisms simulator
Stars: ✭ 17 (-55.26%)
Mutual labels:  ai, genetic-algorithm
Unity2d Components
A constantly evolving array of Unity C# components for 2D games, including classes for pixel art cameras, events & messaging, saving & loading game data, collision handlers, object pools, and more.
Stars: ✭ 375 (+886.84%)
Mutual labels:  unity, gamedev
Game Networking Resources
A Curated List of Game Network Programming Resources
Stars: ✭ 4,208 (+10973.68%)
Mutual labels:  unity, gamedev
Verticaldissolve
Procedural vertical dissolve shader. Highly customizable. Tweak edge color, noisiness & waviness, rim light, emission scrolling and more.
Stars: ✭ 434 (+1042.11%)
Mutual labels:  unity, gamedev
Facemoji
😆 A voice chatbot that can imitate your expression. OpenCV+Dlib+Live2D+Moments Recorder+Turing Robot+Iflytek IAT+Iflytek TTS
Stars: ✭ 320 (+742.11%)
Mutual labels:  ai, unity
Texturepanner
This repository hosts a shader for Unity3D whose main goal is to facilitate the creation of neon-like signs, conveyor belts and basically whatever based on scrolling textures
Stars: ✭ 528 (+1289.47%)
Mutual labels:  unity, gamedev
Valvesockets Csharp
Managed C# abstraction of GameNetworkingSockets library by Valve Software
Stars: ✭ 273 (+618.42%)
Mutual labels:  unity, gamedev
Noahgameframe
A fast, scalable, distributed game server engine/framework for C++, include the actor library, network library, can be used as a real time multiplayer game engine ( MMO RPG/MOBA ), which support C#/Lua script/ Unity3d, Cocos2dx and plan to support Unreal.
Stars: ✭ 3,258 (+8473.68%)
Mutual labels:  unity, gamedev
Beaverandfairies
Stars: ✭ 14 (-63.16%)
Mutual labels:  unity, gamedev
Voxelengine unity
Voxel engine made in C# for Unity
Stars: ✭ 25 (-34.21%)
Mutual labels:  unity, gamedev

Evolutionary Neural Networks on Unity For bots

This is a simple asset that train a neural networks using genetic algorithm in unity to make a bot that can play a game or just interact with the envoriment

HOW IT WORKS

Flappy bird bot

First of anything I will explain the concept of Genetic algorithm: This is a algorithm based on the process of natural selection that works crossovering certains individuals and mutate them with the goal of get a more ideal individuals for a work.

Now the neural network is just a matematical function that can imitate or aproximate to any other matematical function, is the universal approximator. One of this function can be the "Being the most enjoyable final boss" or "Being the most human like chatbot" or "Being the most difficult enemy", so usually the neural network is training using the backpropagation algorithm. But this is a pretty complex algorithm to do, and it does not works when you don't really know the function that you want

Here the Genetic algorithm can help us, just crossover a lot of neural networks and choose the most adapted one

How it works

WHY (MOTIVATION)

I wanted to sell this asset on the store, but Unity ML attacked and I couldn't, so I release it, It's a pretty good and simple experiment, to learn neural networks without backpropagation.
So this was made for my youtube, and twitch channels
Banner
Youtube channel
https://www.youtube.com/c/HectorAndresPulidoPalmar
Twitch Channel
https://www.twitch.tv/hector_pulido_

TO DO

  • More examples
  • Cleaner interface to set the fitness

HOW TO USE

Open it on unity 2018 or greater (sorry about that >-< ), is also recomended to set the scripting runtime version in .Net 4.X, you can make your own envoriment and set the fitness function, but I recomend, to look at the examples.

To create a Envoriment...

You need two things a mendel machine (a trainer if you like the concept), to use it you need to iherit from the class mendel machine and set up, things like the startpoints or the behaviour when the generation is over.

using EvolutionaryPerceptron.MendelMachine;

public class ExampleMendelMachine : MendelMachine {

	int index = 0; //Just one way to change the generation
	//Init all variables
	protected override void Start()
	{
		individualsPerGeneration = somenumber; //You can set an individuals per generation here
		base.Start(); 
		StartCoroutine(InstantiateBotCoroutine());
	}	
	//When a bot die
	public override void NeuralBotDestroyed(Brain neuralBot)
	{
		//Consolidate the fitness
        base.NeuralBotDestroyed(neuralBot);

		//Doo some cool stuff, read the examples
		Destroy(neuralBot.gameObject); //Don't forget to destroy the gameObject
		
		index--;
		if (index <= 0)
		{
			Save(); //don't forget to save when you change the generation
			population = Mendelization();
			generation++;
			StartCoroutine(InstantiateBotCoroutine());
		}
	}
	//You can instantiate one, two, what you want
	IEnumerator InstantiateBotCoroutine()
	{
		//Instantiate bots
		index = individualsPerGeneration;
		for	(int i = 0 ; i < individualsPerGeneration ; i++)
		{
			var b = InstantiateBot(population[i], lifeTime, someTransform, i); // A way to instantiate
		}
	}
}

And you also need a interpreter of the neural bot class this class will act like a Senses and Actuators from the body (the individual), I recomend that the sensors where raycast (o raycast2D) or any lineal information, this class also can change the fitness of the neuralbot.

public class NeuralExample : BotHandler
{
	MyControllerClass cs;
	//Init all variables
	protected override void Start()
	{
		base.Start();
		cs = GetComponent<MyControllerClass>();
	}	
	void Update()
	{
		var i = new double[1, 5] { { n1, n2, n3, n4, n5 } }; // Sensor info
		var output = nb.SetInput(i); //Feed forward
		
		cs.speed = output[0, 0]; // Linear something

            	if (output[0, 1] > 0.5) // Trigger something
            	{
                	cs.jumpRequest = true;
            	}
		nb.AddFitness(Time.deltaTime); // You can reward the lifetime
	}

	private void OnTriggerEnter2D(Collider2D collision)
	{
		//Example of destroy
		if (collision.CompareTag("Obstacle"))
		{
			nb.Destroy();
		}
	}

}

When you finish to train...

Now you can select the bot you want to save, and press the save button, that will generate a .nn file, that file is compatible with IMITATION LEARNING, just desactivate the Learning Phase boolean

EXAMPLES

In this moments there are 4 examples

Self driving car

Self driving car

An automatic Car in unity, it can be trained on just 10 generations, the sensors are Raycast and the actuator is the Unity Standard Asset Vehicle Car

Fitness function

The fitnes function is, how many checkpoints it touch and the Die function is the collision with the tag "Obstacle"

Flappy bird bots

Flappy Bot
This is a flappy bird game bot made with this library, the sensors are 3 raycast, the position, and the center of the obstacles

Dinosaur clone bots

Dinosaur
This is a google chrome clone, it have 7 raycast as sensor aditional to the 7 raycast of the last frame, and 2 buttons as outputs also the fitness function is the lifetime

Fitness function

The fitness function is the time, and the Die function is the collision with the tag "Obstacle"
Assets from

Asteroids like game

Asteroids like game
This is an implementation of the algorithm for the Asteroid game; The sensors are a lot of raycast that detect asteroids, and the die function is when ship collide with an asteroid, and there are 3 output, one for shoot, one for turn, other for accelerate

Fitness function

Lifetime without shoot is a positive reward
Shooting time is a negative reward

The project is not in this here, it's in other repository

https://github.com/HectorPulido/Asteroids-like-game
Assets Licence: MIT

Survival bot

Survival Bot
This is an implementation of the algorithm in the Survival shooter project from Unity Tec. The sensors are a lot of raycast that detect shootables, and enemies, and the die function is when the life gets 0

Fitness function

A useful shoot give 2 points
A fail shoot give -5 points
When the bot move a lot give 1 point
When health is lost give -1 points

The project is not in this here, it's in other repository

https://github.com/HectorPulido/Evolutionary-Neural-Bots-On-Survival-Shooter
Assets Licence: Apache 2.0

PONG Bot

Pong Bot
This is an implementation for the pong game, the sensors are the position and velocity of the ball, the the position and the velocity of the enemy racket and the position of the racket (All the position must be locals)

Fitness function

Pro point add one of fitness point
Contra point remove one of fitness point

This program uses

  1. Simple Linear Algebra for C#

OTHER WORKS

IMITATION LEARNING IN UNITY

This is an open source project that uses neural networks and backpropagation in C#, and train it via stochastic gradient descend using the human behaviour as base
https://github.com/HectorPulido/Imitation-learning-in-unity

More Genetic algorithms on Unity

Those are three Genetics Algorithm using unity, The First one is a simple algorithm that Looks for the minimun of a function, The Second one is a solution for the Travelling Salesman Problem, The Third one is a Automata machine
https://github.com/HectorPulido/Three-Genetics-Algorithm-Using-Unity

Vectorized Multilayer Neural Network from scratch

This is a simple MultiLayer perceptron made with Simple Linear Algebra for C# , is a neural network based on This Algorithm but generalized. This neural network can calcule logic doors like Xor Xnor And Or via Stochastic gradient descent backpropagation with Sigmoid as Activation function, but can be used to more complex problems.
https://github.com/HectorPulido/Vectorized-multilayer-neural-network

Where can i learn more

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].