diff --git a/src/shared/ai/AI.cpp b/src/shared/ai/AI.cpp new file mode 100644 index 0000000..df2b35e --- /dev/null +++ b/src/shared/ai/AI.cpp @@ -0,0 +1,6 @@ +#include "AI.h" + +using namespace ai; + +int AI::getPlayerNumber (){ return playerNumber; } +void AI::setPlayerNumber (int newPN){ playerNumber= newPN; } \ No newline at end of file diff --git a/src/shared/ai/RandomAI.cpp b/src/shared/ai/RandomAI.cpp new file mode 100644 index 0000000..d9d1145 --- /dev/null +++ b/src/shared/ai/RandomAI.cpp @@ -0,0 +1,41 @@ +#include "RandomAI.h" +#include +#include +#include +#include + +#include "state.h" +#include "utils.h" + +using namespace ai; +using namespace engine; +using namespace state; +using namespace std; + + +int RandomAI::selectCharacter (state::State& state){ + std::vector> cells = state.getBoard().getCells(); + std::vector posibleIndex; + int i=0; + for(auto cell : cells){ + if (cell->isAccessible()) { + state::AccessibleCell *ac = (state::AccessibleCell *)cell.get(); + int sid = ac->getEntity().getEntityTypeId(); + if (sid == state::EntityTypeId::SOLDIER) { + if ( ac->getPlayerId()==2 ){ + posibleIndex.push_back(i); + } + + } + } + i++; + } + + int randomNumber = rand() % posibleIndex.size(); + cout << "["; + for(auto &index : posibleIndex){ + cout << index << ", "; + } + cout << "]" << endl; + return posibleIndex[randomNumber]; +} \ No newline at end of file