28#include "BrainsFactory.h"
31#include "EVNTrainer.h"
34BrainsFactory* BrainsFactory::mInstance =
nullptr;
37BrainsFactory& BrainsFactory::Instance()
39 if(!mInstance) mInstance =
new(std::nothrow) BrainsFactory;
44void BrainsFactory::Terminate()
46 if(mInstance)
delete mInstance;
51BrainsFactory::BrainsFactory()
58 pNewBrain =
new(std::nothrow) Brain();
59 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_RANDOM, pNewBrain)).second ==
false)
delete pNewBrain;
61 pNewBrain =
new(std::nothrow) BrainPacManHuman();
62 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_HUMAN | PME_OBJECT_PACMAN, pNewBrain)).second ==
false)
delete pNewBrain;
64 pNewBrain =
new(std::nothrow) BrainPacMan();
65 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_FIXED | PME_OBJECT_PACMAN, pNewBrain)).second ==
false)
delete pNewBrain;
67 pNewBrain =
new(std::nothrow) BrainRedGhost();
68 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_FIXED | PME_OBJECT_GHOST_RED, pNewBrain)).second ==
false)
delete pNewBrain;
69 pNewBrain =
new(std::nothrow) BrainEvolvedRedGhost(-1);
70 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_EVOLVED | PME_OBJECT_GHOST_RED, pNewBrain)).second ==
false)
delete pNewBrain;
71 for(i = 0; i < PME_GA_POPULATION; ++i)
73 pNewBrain =
new(std::nothrow) BrainEvolvedRedGhost(i);
74 if(mapBrains.insert(std::make_pair((PME_BRAIN_TYPE_TRAINING0 << i) | PME_OBJECT_GHOST_RED, pNewBrain)).second ==
false)
delete pNewBrain;
77 pNewBrain =
new(std::nothrow) BrainPinkGhost();
78 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_FIXED | PME_OBJECT_GHOST_PINK, pNewBrain)).second ==
false)
delete pNewBrain;
79 pNewBrain =
new(std::nothrow) BrainEvolvedPinkGhost(-1);
80 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_EVOLVED | PME_OBJECT_GHOST_PINK, pNewBrain)).second ==
false)
delete pNewBrain;
81 for(i = 0; i < PME_GA_POPULATION; ++i)
83 pNewBrain =
new(std::nothrow) BrainEvolvedPinkGhost(i);
84 if(mapBrains.insert(std::make_pair((PME_BRAIN_TYPE_TRAINING0 << i) | PME_OBJECT_GHOST_PINK, pNewBrain)).second ==
false)
delete pNewBrain;
87 pNewBrain =
new(std::nothrow) BrainBlueGhost();
88 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_FIXED | PME_OBJECT_GHOST_BLUE, pNewBrain)).second ==
false)
delete pNewBrain;
89 pNewBrain =
new(std::nothrow) BrainEvolvedBlueGhost(-1);
90 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_EVOLVED | PME_OBJECT_GHOST_BLUE, pNewBrain)).second ==
false)
delete pNewBrain;
91 for(i = 0; i < PME_GA_POPULATION; ++i)
93 pNewBrain =
new(std::nothrow) BrainEvolvedBlueGhost(i);
94 if(mapBrains.insert(std::make_pair((PME_BRAIN_TYPE_TRAINING0 << i) | PME_OBJECT_GHOST_BLUE, pNewBrain)).second ==
false)
delete pNewBrain;
97 pNewBrain =
new(std::nothrow) BrainOrangeGhost();
98 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_FIXED | PME_OBJECT_GHOST_ORANGE, pNewBrain)).second ==
false)
delete pNewBrain;
99 pNewBrain =
new(std::nothrow) BrainEvolvedOrangeGhost(-1);
100 if(mapBrains.insert(std::make_pair(PME_BRAIN_TYPE_EVOLVED | PME_OBJECT_GHOST_ORANGE, pNewBrain)).second ==
false)
delete pNewBrain;
101 for(i = 0; i < PME_GA_POPULATION; ++i)
103 pNewBrain =
new(std::nothrow) BrainEvolvedOrangeGhost(i);
104 if(mapBrains.insert(std::make_pair((PME_BRAIN_TYPE_TRAINING0 << i) | PME_OBJECT_GHOST_ORANGE, pNewBrain)).second ==
false)
delete pNewBrain;
107 #ifdef DEBUG_INTERNAL
108 Main::Instance().ILogMgr().get()->msg(LML_NORMAL,
" [BrainFactory] Info: registered '%d' brains.\n", mapBrains.size());
113BrainsFactory::~BrainsFactory()
116 for(
auto itBrain = mapBrains.begin(); itBrain != mapBrains.end(); ++itBrain)
118 delete itBrain->second;
124Sint32 BrainsFactory::think(Actor* pActor, Sint32 iBrainID, Sint32& iTX, Sint32& iTY, GameField* pGF)
126 auto itBrain = mapBrains.find(iBrainID);
127 if(itBrain != mapBrains.end())
129 itBrain->second->think(pActor, iTX, iTY, pGF);
136bool BrainsFactory::validate(Sint32 iBrainID)
138 auto itBrain = mapBrains.find(iBrainID);
139 if(itBrain != mapBrains.end())
return true;
144Sint32 BrainsFactory::getName(Sint32 iBrainID,
string& sN)
146 auto itBrain = mapBrains.find(iBrainID);
147 if(itBrain != mapBrains.end())
149 itBrain->second->getName(sN);
156Sint32 BrainsFactory::getTargetType(Sint32 iBrainID)
158 auto itBrain = mapBrains.find(iBrainID);
159 if(itBrain != mapBrains.end())
161 return itBrain->second->getTargetType();
167Brain* BrainsFactory::getBrain(Sint32 iBrainID)
169 auto itBrain = mapBrains.find(iBrainID);
170 if(itBrain != mapBrains.end())
172 return itBrain->second;