Moving from the check-in of only animating one agent to having multiple agents that then should interact was a big hurdle for me, especially considering I only ended up giving myself Sunday and Monday to implement it. Saturday got lost to the weekend and I ended up only having two days, unfortunately. After spending most of Sunday wrapping my brain around how to redesign my code for multiple agents, I tried my hand at implementing BOIDs.
It was a struggle to adapt my program to plan for multiple agents, each of which would have their own path to follow. I ran through a few different ideas, starting with adding Start and Goal Node*
to each of my Agent objects. I had previously incorporated the Start and Goal directly into my PRM graph and therefore left my Agent class as only a slightly different child of the WorldObject class, but with a vector<Node*> path
. However, I decided that my PRM needed to just be the Nodes that I randomly placed in my World and that each of my Agents should use these connected Nodes to find their path from their self-contained Start and Goal Nodes.
After figuring this detail out, it took me a long time to organize my thoughts as to how to have multiple Start and Goal Nodes and paths that didn't interfere with each other. At first, I thought that I would need to deep copy the Nodes from my PRM into the path within each Agent. Eventually, I realized that having all the Start and Goal Nodes pushed onto my PRM didn't matter since one Agent's Start and Goal Nodes wouldn't help another Agent reach their Goal.
Once I got multiple agents running (although, without any interactions between each other), I moved onto figuring out BOIDs. First, I sat myself down and worked out by hand what equations I wanted to use for my Separation, Alignment, and Cohesion forces. After working out some math by myself, I had to figure out how to adapt my code. This once again was a little bit of a chore since it seemed as though my project wasn't set up well for the features that I wanted to add. I decided on a Flock class that would be a lead flock. Like in The Lion King, each Flock would have leaders and followers. The leaders would be exactly like the independent Agents I figured out earlier, each with their own self-contained, calculated path. The followers, however, would operate solely under the BOIDs model, driven to follow the leaders as well as each other.
My first attempt at BOIDs was strange and unsuccessful (I don't have a video) and I'm still not sure why. After looking up pseudocode examples that were only ever so slightly different than my own, and spending too much time tweaking parameters, I finally had a reasonable BOIDs. The followers followed behind the leader (I still have yet to see what happens with multiple Agents, but I left the capability there just in case) and formed clumps with each other.
Video 1: Starts with using UCS to determine the paths of 2 Agents. Runs again with weighted A*, also with 2 Agents, and shows noticeable speed up in comparison.
Video 2: 20x20 Agent Mode with two obstacles planned around using A* weight of 2.
Video 3: 20x20 Flock Mode with 10 followers and 1 leader, using A* weight of 2.