24 October

AI Three.js Beehive Simulation Featured

Written by 

Project Description

To fulfill the programmatic content of one of the course subjects an algorithm that could replicate real world actions should be created, in this case an application that could apply the concept of Artificial Intelligence.
The simulation should contain "Agents" that would interact with the surrounding environment and these should display intelligent behavior in decision making.

The Idea

The idea was to mimic some of the behavior that a beehive presents, using the bee's as the "Agents".
Every agent should be autonomous in the decision making process regarding his understanding of the environment and his surroundings.
Each agent have the unique purpose of acquiring a checkpoint and return it the hive as quickly as possible while avoiding the obstacles.

Three.js

Three.js is a great library to build interactive 3D content and deliver it to the clients browser.
Offer's out of the box amazing functionalities and it was very easy to find online documentation and examples, also integrates itself very well on "Class Object Oriented" programming in Javascript.

Development & Classes

Application was fully developed in Javascript, there was little code written in HTML, just the basics to get the scenario  up and running.
As you probably know Javascript does not have a fully Object Oriented architecture, all that can do is try to mimic this, nevertheless when it comes to organize applications and code you can without any problem (and you should) build classes.

For this project Ive divided the class architecture in the following way:

Bee.js -  This class holds the agents "mind" and its responsible for the rules and behaviors of each individual "Bee" such as direction that is currently taking, the mode that is currently in (searching for checkpoint or returning to hive), height that is traveling, object collision detection and so on... This is where Ive programmed all the AI behavior displayed.

Hive.js -  The Hive class initializes the hive object in the scenario and returns its position to the Bee's by a method that returns the direction (North, South, etc...) of the hive, also controls the number of checkpoints returned.

Swarm.js -  The Swarm class is responsible for holding all the agents and their random initialization in the simulation.

Obstacles.js -  The Obstacles class as the name suggests, is similar to the Swarm class, but for the objects that are placed randomly in the world.

Flowers.js -  And finally the Flowers class which is also similar to the Obstacles class.

Agent Behaviour

By default the agents present a random behavior throughout the entire world, ive used random functions to direct the agent accordingly to the cardinal points of the map (North, South, East, Weast, etc...), the change of the direction is done via a random Integer that tells that Agent to change the direction in x iterations of the simulation hence taking a new course.

To prevent object colision, the agent ask's the class Obstacles if there are any objects in the location, if they are the agent takes another direction based on the inverse rules of the cardinal points, for instance, if the agent is heading North and finds an object, then it can take 3 options to go around via West or East or going back choosing South.

This process is done until the agent stops colliding into the object and continues his direction either randomly or bee hive oriented.

While moving around, the agent is constantly looking for a flower checkpoint, when it does find it, the agent know that it needs to return to the hive via the fastests route, idealy in a straight vector whenever possible, if it does however colide into an object in its way back, the process of object colision takes place until its free from colide.

Final Notes

The end results are quite satisfactory, the simulation presents patterns and behaviours replicated from the natural enviorment, and it works well while optimizing the system in terms of checkpoint efficiency.

Sources

I'm here making available to free download the source code of the project, feel free to use & modify the code, i simply ask for a referral to this page if you do.

Project Information

Categories: Application Development

Video Url: https://www.youtube.com/embed/0UcFzlQqbA4

Project Timeline

Start: Apr, 2016

End: May, 2016

Downloads

Media

 

Read 11771 times Last modified on Monday, 24 October 2016 18:41
Rate this item
(0 votes)

Leave a comment

Make sure you enter all the required information, indicated by an asterisk (*). HTML code is not allowed.

Latest Posts

Contacts

João Vieira

Skype: jcv.pt

Email: info@joao-vieira.pt

About

This is my personal page, here you will find IT related, projects, discussions and reviews. Feel free to coment and leave your input.