// Run the main algorithm performing the operations // required of the "Seperation" behaviour. private Vector2 computeSeperation() { ReturnVector vecFunc = seperationVector; Finalization finalizeFunc = seperationFinalize; return(runAlgorithm(vecFunc, finalizeFunc)); }
// Run the main algorithm performing the operations // required of the "Alignment" behaviour. private Vector2 computeAlignment() { ReturnVector vecFunc = alignmentVector; Finalization finalizeFunc = alignmentFinalize; return(runAlgorithm(vecFunc, finalizeFunc)); }
// Main algorithmic 'formula' of alignment, cohesion and seperation. // The passed functions handle the minute differences. private Vector2 runAlgorithm(ReturnVector vecFunc, Finalization finalizeFunc) { Vector2 velocity = Vector2.zero; uint neighbourCount = 0; // Ugh... Some super-annoying bugs can occur with the agent list when the frog eats a fly or the game is restarted. // This check as well as "staleAgents" below means that we should avoid any null reference crap. EnsureFlocksOK(); Hashtable agents = (Hashtable)flocks[this.tag]; List <GameObject> staleAgents = new List <GameObject>(); foreach (object o in agents.Keys) { GameObject agent = (GameObject)o; if (agent == null) { staleAgents.Add(agent); continue; } if (agent == gameObject) { continue; } // Find neighbours of our agent to include in the calculation. if (Vector2.Distance(agent.transform.position, transform.position) < neighbourDist) { //Debug.Log("Found neighbour"); velocity += vecFunc(agent); neighbourCount += 1; } } foreach (GameObject staleAgent in staleAgents) { agents.Remove(staleAgent); } if (neighbourCount == 0) { return(velocity); } return(finalizeFunc(velocity, neighbourCount)); }
/// <summary> Assert will first pass the facts to the parameters. Once the /// parameters are set, it should call execute to get the result. /// </summary> public override void assertLeft(Index linx, Rete engine, WorkingMemory mem) { Map leftmem = (Map)mem.getBetaLeftMemory(this); if (!leftmem.containsKey(linx)) { Parameters = linx.Facts; ReturnVector rv = func.executeFunction(engine, params_Renamed); if (!rv.firstReturnValue().BooleanValue) { BetaMemory bmem = new BetaMemoryImpl(linx); leftmem.put(bmem.Index, bmem); } // only propogate if left memories count is zero if (leftmem.size() == 0) { propogateAssert(linx, engine, mem); } } }