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 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 is a great library to build interactive 3D content and deliver it to the clients browser.
Development & 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.
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.
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.
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.
Categories: Application Development
Video Url: https://www.youtube.com/embed/0UcFzlQqbA4
Start: Apr, 2016
End: May, 2016