From f3622163c79eea01d6da11730b77df3ddbafd92a Mon Sep 17 00:00:00 2001 From: hicham Date: Tue, 19 Jan 2021 11:46:32 +0100 Subject: [PATCH 1/2] AI.cpp --- src/shared/ai/AI.cpp | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 src/shared/ai/AI.cpp 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 From 1809f83b9ab4b73301ca18091833caad1a6aae34 Mon Sep 17 00:00:00 2001 From: hicham Date: Tue, 19 Jan 2021 12:06:55 +0100 Subject: [PATCH 2/2] RandomAI::selectCharacter --- src/shared/ai/RandomAI.cpp | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/shared/ai/RandomAI.cpp 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