00001
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "Warrior.h"
00026
00027 #include <list>
00028 #include <vector>
00029 #include <map>
00030
00031 #include "Random.h"
00032 #include "MoveCommand.h"
00033 #include "WorshiperInfo.h"
00034 #include "VisualContext.h"
00035 #include "MoveIterator.h"
00036
00038 #define WARRIOR_DANGER 2
00039
00040 using namespace std;
00041
00042 Warrior::Warrior() : HeuristicBehaviour() {
00043
00044 }
00045
00046 Warrior::~Warrior() {
00047
00048 }
00049
00050 void Warrior::think() {
00051
00052 _pheros->clear();
00053
00054 _action = MOVECMD_NOMOVE;
00055
00056 VisualContext * visu = getVisualContext();
00057 MoveIterator it_move, it2_move, end_move;
00058 list<WorshiperInfo> winfos;
00059 list<WorshiperInfo>::iterator it_winfos, end_winfos;
00060 vector<unsigned int> pheros;
00061 bool found;
00062
00063
00064 found = false;
00065 end_move = visu->endMove();
00066 for(it_move = visu->beginMove(); !found && it_move != end_move; ++it_move){
00067 if(*it_move != MOVECMD_NOMOVE && visu->legal(it_move) && visu->reachable(it_move)){
00068 winfos = visu->getWorshipers(it_move);
00069
00070 if(!winfos.empty()){
00071
00072 end_winfos = winfos.end();
00073
00074
00075 for(it_winfos = winfos.begin(); !found && it_winfos != end_winfos; ++it_winfos){
00076 found = it_winfos->isEnnemy();
00077 }
00078 --it_winfos;
00079
00080
00081
00082 if(found){
00083 _action = *it_move;
00084 putPheromone(WARRIOR_DANGER);
00085 }
00086 }
00087 }
00088 }
00089
00090
00091 if(!found){
00092 found = false;
00093 for(it_move = visu->beginMove(); !found && it_move != end_move; ++it_move){
00094 if(*it_move != MOVECMD_NOMOVE && visu->legal(it_move) && visu->reachable(it_move)){
00095 it2_move = it_move;
00096 pheros = visu->getPheromones(it_move);
00097 found = (pheros[WARRIOR_DANGER] > 0);
00098 }
00099 }
00100
00101
00102 if(found){
00103 _action = *it2_move;
00104 } else {
00105 _action = randomMove();
00106 }
00107
00108 }
00109 }