Skip to content

Algorithms

Gjum edited this page Jun 22, 2015 · 1 revision

###Clusters Let's start with clusters, what they are, and how they got implemented.

I won't lie, I had never heard of a cluster before working on this project. Or maybe I heard the word, but I had never thought about their inner workings. I'm not even sure if what I have done can even be considered a cluster. I won't complain though as what I have works and is simple enough.

A cluster here means a single node that includes all the elements around it within a certain distance. The cluster has x and y coordinates as well as a value that should represent the elements that are inside it.

  • Step one, generate a list of everything that needs to be clustered. Each element holds its x and y positions, as well as its size.
  • Step two, loop though that list, and then merge elements that are close together. The proximity of points included will depend on the current blob size.
    • Merging means taking the average of two x and y positions and adding their size to a value variable. Therefore a cluster is only an average of all the position's elements included as well as their size added together to give the cluster it's value.
  • In the case of food clusters, you can then pick the best cluster to go to based on how much value it has. There is actually a little catch as you can't simply base your choice on the value of a cluster alone, but on the distance as well. Keeping that in mind, a cluster loses it's value the further away it is from your blob.
Clone this wiki locally