UntilVictoryFight Class Reference

#include <UntilVictoryFight.h>

Inheritance diagram for UntilVictoryFight:

Inheritance graph
[legend]
Collaboration diagram for UntilVictoryFight:

Collaboration graph
[legend]

Public Member Functions

 UntilVictoryFight ()
 Constructor.
virtual ~UntilVictoryFight ()
 Empty Destructor.
virtual unsigned int resolve (Cell *c)
 Make all the fights needed in a Cell.

Detailed Description

< A Fight strategy : the bigger win

Definition at line 35 of file UntilVictoryFight.h.


Member Function Documentation

unsigned int UntilVictoryFight::resolve ( Cell c  )  [virtual]

Make all the fights needed in a Cell.

Parameters:
c the cell in which the fights had to take place
Returns:
the amount of food produced by the deads

Implements Fight.

Definition at line 41 of file UntilVictoryFight.cpp.

References Worshiper::getColony(), Worshiper::getFood(), Cell::getPeople(), Worshiper::getSize(), Cell::removeWorshiper(), and Random::value().

00041                                                {
00042   std::list<Worshiper*>* worshipers = NULL;
00043   std::list<Worshiper*>::iterator it, end;
00044   Worshiper *bigger = NULL;
00045   unsigned int size_max = 0, food = 0;
00046   bool restart = false;
00047 
00048   // on récupère les worshipers présents sur la case
00049   worshipers = c->getPeople();
00050   if(worshipers != NULL) {
00051     end = worshipers->end();
00052     // on recherche le plus gros d'entre eux
00053     for(it = worshipers->begin(); it != end; ++it) {
00054       if((*it)->getSize() > size_max) {
00055         bigger = *it;
00056         size_max = bigger->getSize();
00057       }
00058     }
00059     // et maintenant il élimine tous les worshipers des autres colonies
00060     if(bigger != NULL) {
00061       end = worshipers->end();
00062       for(it = worshipers->begin(); it != end;) {
00063         // s'agit-il d'un ennemis ?
00064         if(*it != bigger && (*it)->getColony() != bigger->getColony()) {
00065           // Armes égales ? Que Dieu décide de l'issu de ce combat !...
00066           if(((*it)->getSize() == size_max) && (Random::value() % 2)) {
00067             // oups, on vient de se faire déssouder,
00068             food += bigger->getFood();
00069             c->removeWorshiper(bigger);
00070             delete(bigger);
00071             // un nouveau champion vient de naître
00072             bigger = *it;
00073             // et on n'a plus qu'a tout recommencer dans
00074             // la joie et la bonne humeur
00075             restart = true;
00076           } else {
00077             // ...ou pas (désolé mon petit, mais je crois que tu va souffrir)
00078             food += (*it)->getFood();
00079             c->removeWorshiper(*it);
00080             delete (*it);
00081             --it;
00082           }
00083         }
00084         // si on recommence, il ne faut pas incrémenter l'itérateur,
00085         // on se replace plutôt en début de liste.
00086         if(! restart) {
00087           ++it;
00088         } else {
00089           restart = false;
00090           it = worshipers->begin();
00091         }
00092       }
00093     }
00094   }
00095 
00096   return food;
00097 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Sat Feb 2 22:23:18 2008 for Teapot Colony Wars by  doxygen 1.5.4