#include "stdafx.h" #include "StrategyLoopByAgentId.h" #include "Agent.h" #include "AgentGroup.h" #include CStrategyLoopByAgentId::CStrategyLoopByAgentId() { } CStrategyLoopByAgentId::~CStrategyLoopByAgentId() { } CAgent * CStrategyLoopByAgentId::_locateAgent(CAgentGroup & AgentGroup) { CAgent* pAgent = NULL; bool t_b_has_jump = false; static UINT agentId = 0; //pAgent = AgentGroup.GetFreeAgentForLoopByAgentId(); std::sort(AgentGroup.GetData(), AgentGroup.GetData() + AgentGroup.GetSize(), [&](CAgent *a, CAgent *b) mutable ->bool { return a->id() < b->id(); }); for (int i = 0; i < AgentGroup.GetCount(); ++i) { pAgent = AgentGroup[i]; if (pAgent->isFree() && pAgent->id() > agentId) { agentId = pAgent->id(); return pAgent; } } for (int i = 0; i < AgentGroup.GetCount(); ++i) { pAgent = AgentGroup[i]; if (pAgent->isFree() && pAgent->id() <= agentId) { agentId = pAgent->id(); return pAgent; } if (pAgent->id() > agentId) break; } return pAgent; }