| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "stdafx.h"
- #include "StrategyLoopByAgentId.h"
- #include "Agent.h"
- #include "AgentGroup.h"
- #include <algorithm>
- 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;
- }
|