-
Notifications
You must be signed in to change notification settings - Fork 0
/
AntColony.cpp
53 lines (46 loc) · 921 Bytes
/
AntColony.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include "StdAfx.h"
#include "AntColony.h"
#include "Ant.h"
#include "SketcherEngine.h"
#include "AntColonyConfiguration.h"
#include "Display.h"
AntColony::AntColony(void)
: m_iRemainedAnts(0)
{
}
AntColony::~AntColony(void)
{
}
void AntColony::DispatchAnt(SketcherEngine* pSketcher, AntColonyConfiguration* pConfig)
{
if(m_iRemainedAnts <= 0)
{
return;
}
int iAntsPerExecution=pConfig->GetAntsPerExecution();
int iAntsPerRefresh=pConfig->GetAntsPerRefresh();
for(int i=0; i<iAntsPerExecution; i++)
{
Ant ant;
ant.Start(pConfig, pSketcher);
m_iRemainedAnts --;
m_iDeadAnts++;
if(m_iDeadAnts % iAntsPerRefresh == 0)
{
gDisplay.InvalidateView(FALSE);
}
if(m_iRemainedAnts <=0)
{
break;
}
}
}
void AntColony::Reset(AntColonyConfiguration* pConfig)
{
m_iRemainedAnts=pConfig->GetColonySize();
m_iDeadAnts=0;
}
bool AntColony::IsNull(void) const
{
return m_iRemainedAnts <=0 ;
}