From 672468a7389c128a26d16d18db6d8fb8a221a14e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20W=2E=20Urba=C5=84czyk?= Date: Thu, 1 Mar 2012 16:32:14 +0000 Subject: [PATCH] Deleted GeniusAI. --- AI/GeniusAI/AIPriorities.cpp | 251 ------ AI/GeniusAI/AIPriorities.h | 36 - AI/GeniusAI/BattleHelper.cpp | 186 ----- AI/GeniusAI/BattleHelper.h | 49 -- AI/GeniusAI/BattleLogic.cpp | 781 ------------------ AI/GeniusAI/BattleLogic.h | 131 ---- AI/GeniusAI/CGeniusAI.cpp | 1396 --------------------------------- AI/GeniusAI/CGeniusAI.h | 215 ----- AI/GeniusAI/Common.h | 11 - AI/GeniusAI/DLLMain.cpp | 38 - AI/GeniusAI/ExpertSystem.cpp | 143 ---- AI/GeniusAI/ExpertSystem.h | 215 ----- AI/GeniusAI/GeneralAI.cpp | 22 - AI/GeniusAI/GeneralAI.h | 18 - AI/GeniusAI/Makefile.am | 24 - AI/GeniusAI/Makefile.in | 675 ---------------- AI/GeniusAI/StdInc.cpp | 2 - AI/GeniusAI/StdInc.h | 7 - AI/GeniusAI/genius.vcxproj | 244 ------ AI/GeniusAI/neuralNetwork.cpp | 417 ---------- AI/GeniusAI/neuralNetwork.h | 61 -- 21 files changed, 4922 deletions(-) delete mode 100644 AI/GeniusAI/AIPriorities.cpp delete mode 100644 AI/GeniusAI/AIPriorities.h delete mode 100644 AI/GeniusAI/BattleHelper.cpp delete mode 100644 AI/GeniusAI/BattleHelper.h delete mode 100644 AI/GeniusAI/BattleLogic.cpp delete mode 100644 AI/GeniusAI/BattleLogic.h delete mode 100644 AI/GeniusAI/CGeniusAI.cpp delete mode 100644 AI/GeniusAI/CGeniusAI.h delete mode 100644 AI/GeniusAI/Common.h delete mode 100644 AI/GeniusAI/DLLMain.cpp delete mode 100644 AI/GeniusAI/ExpertSystem.cpp delete mode 100644 AI/GeniusAI/ExpertSystem.h delete mode 100644 AI/GeniusAI/GeneralAI.cpp delete mode 100644 AI/GeniusAI/GeneralAI.h delete mode 100644 AI/GeniusAI/Makefile.am delete mode 100644 AI/GeniusAI/Makefile.in delete mode 100644 AI/GeniusAI/StdInc.cpp delete mode 100644 AI/GeniusAI/StdInc.h delete mode 100644 AI/GeniusAI/genius.vcxproj delete mode 100644 AI/GeniusAI/neuralNetwork.cpp delete mode 100644 AI/GeniusAI/neuralNetwork.h diff --git a/AI/GeniusAI/AIPriorities.cpp b/AI/GeniusAI/AIPriorities.cpp deleted file mode 100644 index 11b1a0382..000000000 --- a/AI/GeniusAI/AIPriorities.cpp +++ /dev/null @@ -1,251 +0,0 @@ -#include "StdInc.h" -#include "AIPriorities.h" - -// TODO: No using namespace!! -using namespace geniusai; - -Network::Network() -{} -Network::Network(vector whichFeatures)// random network - : whichFeatures(whichFeatures), - net(whichFeatures.size(), - whichFeatures.size() * 0.601 + 2, - whichFeatures.size() * 0.251 + 2, - 1) -{ -} - -Network::Network(istream & input) -{ - // vector whichFeatures; - int feature; - string line; - getline(input,line); - stringstream lineIn(line); - while(lineIn>>feature) - whichFeatures.push_back(feature); - - getline(input, line);//get R - net = neuralNetwork(whichFeatures.size(), - whichFeatures.size() * 0.601 + 2, - whichFeatures.size() * 0.251 + 2, - 1); -} - - -double Network::feedForward(const vector & stateFeatures) -{ - // TODO: Should comment/rewrite it... - return (rand() % 1000) / 800.0; - double * input = new double[whichFeatures.size()]; - for (int i = 0; i < whichFeatures.size(); i++) - input[i] = stateFeatures[whichFeatures[i]]; - - double ans = net.feedForwardPattern(input)[0]; - - delete input; - return ans; -} - -Priorities::Priorities(const string & filename) //read brain from file -:numSpecialFeatures(8) -{ - ifstream infile(filename.c_str()); - - // object_num [list of features] - // brain data or "R" for random brain - objectNetworks.resize(255); - buildingNetworks.resize(9); - - char type; - int object_num; - int town_num; - int building_num; - while(infile>>type) - { - switch(type) - { - case 'o'://map object - infile >> object_num; - objectNetworks[object_num].push_back(Network(infile)); - break; - case 't'://town building - infile >> town_num >> building_num; - buildingNetworks[town_num][building_num]=Network(infile); - - break; - } - } -} - -void Priorities::fillFeatures(const CGeniusAI::HypotheticalGameState & hgs) -{ - stateFeatures.clear(); - stateFeatures.resize(50); - for(int i = 0; i < stateFeatures.size(); i++) - stateFeatures[i]=0; - for(int i = 0; i < hgs.resourceAmounts.size();i++) //features 0-7 are resources - stateFeatures[i]=hgs.resourceAmounts[i]; - - //TODO: //features 8-15 are incomes - - specialFeaturesStart = 16; //features 16-23 are special features (filled in by get functions before ANN) - - stateFeatures[24] = hgs.AI->m_cb->getDate(); - stateFeatures[25] = 1; - - -} - -double Priorities::getCost(vector &resourceCosts,const CGHeroInstance * moved,int distOutOfTheWay) -{ - if(!resourceCosts.size())return -1; - //TODO: replace with ann - double cost = resourceCosts[0]/4.0+resourceCosts[1]/2.0+resourceCosts[2]/4.0+resourceCosts[3]/2.0+resourceCosts[4]/2.0+resourceCosts[5]/2.0+resourceCosts[6]/3000.0; - - if(moved) //TODO: multiply by importance of hero - cost+=distOutOfTheWay/10000.0; - return cost; -} - -double Priorities::getValue(const CGeniusAI::AIObjective & obj) -{ //resource - - vector resourceAmounts(8,0); - int amount; - - if(obj.type==CGeniusAI::AIObjective::finishTurn) //TODO: replace with value of visiting that object divided by days till completed - return .0001; //small nonzero - double a; - if(obj.type==CGeniusAI::AIObjective::attack) - return 100; - if(dynamic_cast(&obj)) - { - const CGeniusAI::HeroObjective* hobj = dynamic_cast(&obj); - stateFeatures[16] = hobj->whoCanAchieve.front()->h->getTotalStrength(); - if(dynamic_cast(hobj->object)) - stateFeatures[17] = dynamic_cast(hobj->object)->getArmyStrength(); - switch(hobj->object->ID) - { - case 5: //artifact //TODO: return value of each artifact - return 0; - case 79://resources on the ground - switch(hobj->object->subID) - { - case 6: - amount = 800; - break; - case 0: case 2: - amount = 9.5; //will be rounded, sad - break; - default: - amount = 4; - break; - } - resourceAmounts[hobj->object->subID]=amount; - return getCost(resourceAmounts,NULL,0); - break; - case 55://mystical garden - resourceAmounts[6]=500; - a=getCost(resourceAmounts,NULL,0); - resourceAmounts[6]=0; - resourceAmounts[5]=5; - return (a+getCost(resourceAmounts,NULL,0))*.5; - case 109: - resourceAmounts[6]=1000; - return getCost(resourceAmounts,NULL,0); - case 12://campfire - resourceAmounts[6]=500; - for(int i = 0; i < 6;i++) - resourceAmounts[i]=1; - return getCost(resourceAmounts,NULL,0); - case 112://windmill - for(int i = 1; i < 6;i++)//no wood - resourceAmounts[i]=1; - return getCost(resourceAmounts,NULL,0); - break; - case 49://magic well - //TODO: add features for hero's spell points - break; - case 34: //hero - if(dynamic_cast(hobj->object)->getOwner()==obj.AI->m_cb->getMyColor())//friendly hero - { - - stateFeatures[17] = dynamic_cast(hobj->object)->getTotalStrength(); - return objectNetworks[34][0].feedForward(stateFeatures); - } - else - { - stateFeatures[17] = dynamic_cast(hobj->object)->getTotalStrength(); - return objectNetworks[34][1].feedForward(stateFeatures); - } - - break; - case 98: - if(dynamic_cast(hobj->object)->getOwner()==obj.AI->m_cb->getMyColor())//friendly town - { - stateFeatures[17] = dynamic_cast(hobj->object)->getArmyStrength(); - return 0; // objectNetworks[98][0].feedForward(stateFeatures); - } - else - { - stateFeatures[17] = dynamic_cast(hobj->object)->getArmyStrength(); - return 0; //objectNetworks[98][1].feedForward(stateFeatures); - } - - break; - case 88: - //TODO: average value of unknown level 1 spell, or value of known spell - case 89: - //TODO: average value of unknown level 2 spell, or value of known spell - case 90: - //TODO: average value of unknown level 3 spell, or value of known spell - return 0; - break; - case 215://quest guard - return 0; - case 53: //various mines - return 0; //out of range crash - //objectNetworks[53][hobj->object->subID].feedForward(stateFeatures); - case 113://TODO: replace with value of skill for the hero - return 0; - case 103: case 58://TODO: replace with value of seeing x number of new tiles - return 0; - default: - if (objectNetworks[hobj->object->ID].size()) - return objectNetworks[hobj->object->ID][0].feedForward(stateFeatures); - tlog6 << "don't know the value of "; - switch(obj.type) - { - case CGeniusAI::AIObjective::visit: - tlog6 << "visiting " << hobj->object->ID; - break; - tlog6 << "attacking " << hobj->object->ID; - break; - case CGeniusAI::AIObjective::finishTurn: - obj.print(); - break; - } - tlog6 << endl; - } - } - else //town objective - { - if(obj.type == CGeniusAI::AIObjective::buildBuilding) - { - const CGeniusAI::TownObjective* tnObj = dynamic_cast(&obj); - if(buildingNetworks[tnObj->whichTown->t->subID].find(tnObj->which)!=buildingNetworks[tnObj->whichTown->t->subID].end()) - return buildingNetworks[tnObj->whichTown->t->subID][tnObj->which].feedForward(stateFeatures); - else - { - tlog6 << "don't know the value of "; - obj.print(); - tlog6 << endl; - } - - } - } - - - return 0; -} \ No newline at end of file diff --git a/AI/GeniusAI/AIPriorities.h b/AI/GeniusAI/AIPriorities.h deleted file mode 100644 index 08ca5319c..000000000 --- a/AI/GeniusAI/AIPriorities.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once - -#include "CGeniusAI.h" -#include "neuralNetwork.h" - -namespace geniusai { - -class Network -{ -public: - Network(); - Network(vector whichFeatures);// random network - Network(istream & input); - vector whichFeatures; - double feedForward(const vector & stateFeatures); - neuralNetwork net; //a network with whichFeatures.size() inputs, and 1 output -}; - - -class Priorities -{ -public: - Priorities(const string & filename); //read brain from file - - - vector stateFeatures; - int specialFeaturesStart; - int numSpecialFeatures; - void fillFeatures(const CGeniusAI::HypotheticalGameState & AI); - double getValue(const CGeniusAI::AIObjective & obj); - double getCost(vector &resourceCosts,const CGHeroInstance * moved,int distOutOfTheWay); - vector > objectNetworks; - vector > buildingNetworks; -}; - -} \ No newline at end of file diff --git a/AI/GeniusAI/BattleHelper.cpp b/AI/GeniusAI/BattleHelper.cpp deleted file mode 100644 index 32fcece6e..000000000 --- a/AI/GeniusAI/BattleHelper.cpp +++ /dev/null @@ -1,186 +0,0 @@ -#include "StdInc.h" -#include "BattleHelper.h" - -using namespace geniusai::BattleAI; -using namespace std; - - -CBattleHelper::CBattleHelper(): - InfiniteDistance(0xffff), - BattlefieldWidth(GameConstants::BFIELD_WIDTH-2), - BattlefieldHeight(GameConstants::BFIELD_HEIGHT), - m_voteForMaxDamage(10), - m_voteForMinDamage(10), - m_voteForMaxSpeed(10), - m_voteForDistance(10), - m_voteForDistanceFromShooters(20), - m_voteForHitPoints(10) -{ - // loads votes - std::fstream f; - f.open("AI\\CBattleHelper.txt", std::ios::in); - if (f) - { - //char c_line[512]; - std::string line; - while (std::getline(f, line, '\n')) - { - //f.getline(c_line, sizeof(c_line), '\n'); - //std::string line(c_line); - //std::getline(f, line); - std::vector parts; - boost::algorithm::split(parts, line, boost::algorithm::is_any_of("=")); - if (parts.size() >= 2) - { - boost::algorithm::trim(parts[0]); - boost::algorithm::trim(parts[1]); - if (parts[0].compare("m_voteForDistance") == 0) - { - try - { - m_voteForDistance = boost::lexical_cast(parts[1]); - } - catch (boost::bad_lexical_cast &) - {} - } - else if (parts[0].compare("m_voteForDistanceFromShooters") == 0) - { - try - { - m_voteForDistanceFromShooters = boost::lexical_cast(parts[1]); - } - catch (boost::bad_lexical_cast &) - {} - } - else if (parts[0].compare("m_voteForHitPoints") == 0) - { - try - { - m_voteForHitPoints = boost::lexical_cast(parts[1]); - } - catch (boost::bad_lexical_cast &) - {} - } - else if (parts[0].compare("m_voteForMaxDamage") == 0) - { - try - { - m_voteForMaxDamage = boost::lexical_cast(parts[1]); - } - catch (boost::bad_lexical_cast &) - {} - } - else if (parts[0].compare("m_voteForMaxSpeed") == 0) - { - try - { - m_voteForMaxSpeed = boost::lexical_cast(parts[1]); - } - catch (boost::bad_lexical_cast &) - {} - } - else if (parts[0].compare("m_voteForMinDamage") == 0) - { - try - { - m_voteForMinDamage = boost::lexical_cast(parts[1]); - } - catch (boost::bad_lexical_cast &) - {} - } - } - } - f.close(); - } -} - -CBattleHelper::~CBattleHelper() -{} - - -int CBattleHelper::GetBattleFieldPosition(int x, int y) -{ - return x + GameConstants::BFIELD_WIDTH * (y - 1); -} - -int CBattleHelper::DecodeXPosition(int battleFieldPosition) -{ - int x = battleFieldPosition%GameConstants::BFIELD_WIDTH; - assert( x > 0 && x < GameConstants::BFIELD_WIDTH-1 ); - return x; -} - -int CBattleHelper::DecodeYPosition(int battleFieldPosition) -{ - - int y=battleFieldPosition/GameConstants::BFIELD_WIDTH +1; - assert( y > 0 && y <= GameConstants::BFIELD_HEIGHT); - return y; -} - -int CBattleHelper::StepRight(int pos){ - return pos+1; -} - -int CBattleHelper::StepLeft(int pos){ - return pos-1; -} - -int CBattleHelper::StepUpleft(int pos){ - if((pos/GameConstants::BFIELD_WIDTH)%2==0){ - return pos-GameConstants::BFIELD_WIDTH; - }else{ - return pos-GameConstants::BFIELD_WIDTH-1; - } -} - -int CBattleHelper::StepUpright(int pos){ - if((pos/GameConstants::BFIELD_WIDTH)%2==0){ - return pos-GameConstants::BFIELD_WIDTH+1; - }else{ - return pos-GameConstants::BFIELD_WIDTH; - } -} - -int CBattleHelper::StepDownleft(int pos){ - if((pos/GameConstants::BFIELD_WIDTH)%2==0){ - return pos+GameConstants::BFIELD_WIDTH; - }else{ - return pos+GameConstants::BFIELD_WIDTH-1; - } -} - -int CBattleHelper::StepDownright(int pos){ - if((pos/GameConstants::BFIELD_WIDTH)%2==0){ - return pos+GameConstants::BFIELD_WIDTH+1; - }else{ - return pos+GameConstants::BFIELD_WIDTH; - } -} - -int CBattleHelper::GetShortestDistance(int pointA, int pointB) -{ - int x1 = DecodeXPosition(pointA); - int y1 = DecodeYPosition(pointA); - int x2 = DecodeXPosition(pointB); - int y2 = DecodeYPosition(pointB); - int dx = abs(x1 - x2); - int dy = abs(y1 - y2); - if( dy%2==1 ){ - if( y1%2==1 ){ - if( x2<=x1 ){dx++;} - }else{ - if( x2>=x1 ){dx++;} - } - } - max(dy,dx+dy/2); - - return 0; -} - -int CBattleHelper::GetDistanceWithObstacles(int pointA, int pointB) -{ - - // TODO - implement this! - return GetShortestDistance(pointA, pointB); -} diff --git a/AI/GeniusAI/BattleHelper.h b/AI/GeniusAI/BattleHelper.h deleted file mode 100644 index 592983959..000000000 --- a/AI/GeniusAI/BattleHelper.h +++ /dev/null @@ -1,49 +0,0 @@ -#pragma once - -#include "Common.h" - -namespace geniusai { namespace BattleAI { - - class CBattleHelper -{ -public: - CBattleHelper(); - ~CBattleHelper(); - - int GetBattleFieldPosition(int x, int y); - int DecodeXPosition(int battleFieldPosition); - int DecodeYPosition(int battleFieldPosition); - - int StepDownright(int pos); - int StepUpright(int pos); - int StepDownleft(int pos); - int StepUpleft(int pos); - int StepRight(int pos); - int StepLeft(int pos); - - int GetShortestDistance(int pointA, int pointB); - int GetDistanceWithObstacles(int pointA, int pointB); - - int GetVoteForMaxDamage() const { return m_voteForMaxDamage; } - int GetVoteForMinDamage() const { return m_voteForMinDamage; } - int GetVoteForMaxSpeed() const { return m_voteForMaxSpeed; } - int GetVoteForDistance() const { return m_voteForDistance; } - int GetVoteForDistanceFromShooters() const { return m_voteForDistanceFromShooters; } - int GetVoteForHitPoints() const { return m_voteForHitPoints; } - - const int InfiniteDistance; - const int BattlefieldWidth; - const int BattlefieldHeight; -private: - int m_voteForMaxDamage; - int m_voteForMinDamage; - int m_voteForMaxSpeed; - int m_voteForDistance; - int m_voteForDistanceFromShooters; - int m_voteForHitPoints; - - CBattleHelper(const CBattleHelper &); - CBattleHelper &operator=(const CBattleHelper &); -}; - -}} \ No newline at end of file diff --git a/AI/GeniusAI/BattleLogic.cpp b/AI/GeniusAI/BattleLogic.cpp deleted file mode 100644 index d2fc9f2d5..000000000 --- a/AI/GeniusAI/BattleLogic.cpp +++ /dev/null @@ -1,781 +0,0 @@ -#include "StdInc.h" -#include "BattleLogic.h" - -#include "../../lib/BattleState.h" -#include -#include -#include - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN //excludes rarely used stuff from windows headers - delete this line if something is missing -#include -HANDLE handleIn; -HANDLE handleOut; -#endif - -using namespace geniusai::BattleAI; -using namespace boost::lambda; -using namespace std; - -#if _MSC_VER >= 1600 -#define bind boost::lambda::bind -#endif - -/* -ui8 side; //who made this action: false - left, true - right player - ui32 stackNumber;//stack ID, -1 left hero, -2 right hero, - ui8 actionType; // - 0 = Cancel BattleAction - 1 = Hero cast a spell - 2 = Walk - 3 = Defend - 4 = Retreat from the battle - 5 = Surrender - 6 = Walk and Attack - 7 = Shoot - 8 = Wait - 9 = Catapult - 10 = Monster casts a spell (i.e. Faerie Dragons) - ui16 destinationTile; - si32 additionalInfo; // e.g. spell number if type is 1 || 10; tile to attack if type is 6 -*/ -/** - * Implementation of CBattleLogic class. - */ -CBattleLogic::CBattleLogic(CCallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) : - m_iCurrentTurn(-2), - m_bIsAttacker(!side), - m_cb(cb), - m_army1(army1), - m_army2(army2), - m_tile(tile), - m_hero1(hero1), - m_hero2(hero2), - m_side(side) -{ - const int max_enemy_creatures = 12; - m_statMaxDamage.reserve(max_enemy_creatures); - m_statMinDamage.reserve(max_enemy_creatures); - - m_statMaxSpeed.reserve(max_enemy_creatures); - m_statDistance.reserve(max_enemy_creatures); - m_statDistanceFromShooters.reserve(max_enemy_creatures); - m_statHitPoints.reserve(max_enemy_creatures); -} - -CBattleLogic::~CBattleLogic() -{} - -void CBattleLogic::SetCurrentTurn(int turn) -{ - m_iCurrentTurn = turn; -} - -void CBattleLogic::MakeStatistics(int currentCreatureId) -{ - typedef std::vector vector_stacks; - vector_stacks allStacks = m_cb->battleGetStacks(); - const CStack *currentStack = m_cb->battleGetStackByID(currentCreatureId); - if(currentStack->position < 0) //turret - { - return; - } - /* - // find all creatures belong to the enemy - std::for_each(allStacks.begin(), allStacks.end(), - if_(bind(&CStack::attackerOwned, bind(&map_stacks::value_type::second, _1)) == m_bIsAttacker) - [ - var(enemy)[ret(bind(&map_stacks::value_type::first, _1))] = - ret(bind(&map_stacks::value_type::second, _1)) - ] - ); - // fill other containers - // max damage - std::for_each(enemy.begin(), enemy.end(), - var(m_statMaxDamage)[ret(bind(&map_stacks::value_type::first, _1))] = - ret(bind(&CCreature::damageMax, bind(&CStack::creature, - bind(&map_stacks::value_type::second, _1)))) - ); - // min damage - std::for_each(enemy.begin(), enemy.end(), - var(m_statMinDamage)[ret(bind(&map_stacks::value_type::first, _1))] = - ret(bind(&CCreature::damageMax, bind(&CStack::creature, - bind(&map_stacks::value_type::second, _1)))) - ); - */ - m_statMaxDamage.clear(); - m_statMinDamage.clear(); - m_statHitPoints.clear(); - m_statMaxSpeed.clear(); - m_statDistanceFromShooters.clear(); - m_statDistance.clear(); - m_statDistance.clear(); - - m_statCasualties.clear(); - - int totalEnemyDamage = 0; - int totalEnemyHitPoints = 0; - - int totalDamage = 0; - int totalHitPoints = 0; - - BOOST_FOREACH(const CStack *st, allStacks) - { - const int stackHP = st->valOfBonuses(Bonus::STACK_HEALTH); - - if ((st->attackerOwned != 0) != m_bIsAttacker) - { - int id = st->ID; - if (st->count < 1) - { - continue; - } - // make stats - int hitPoints = st->count * stackHP - (stackHP - st->firstHPleft); - - m_statMaxDamage.push_back(std::pair(id, st->getMaxDamage() * st->count)); - m_statMinDamage.push_back(std::pair(id, st->getMinDamage() * st->count)); - m_statHitPoints.push_back(std::pair(id, hitPoints)); - m_statMaxSpeed.push_back(std::pair(id, stackHP)); - - totalEnemyDamage += (st->getCreature()->damageMax + st->getCreature()->damageMin) * st->count / 2; - totalEnemyHitPoints += hitPoints; - - // calculate casualties - SCreatureCasualties cs; - // hp * amount - damage * ( (att - def)>=0 ) - // hit poionts - assert(hitPoints >= 0 && "CGeniusAI - creature cannot have hit points less than zero"); - - //CGHeroInstance *attackerHero = (m_side)? m_hero1 : m_hero2; - //CGHeroInstance *defendingHero = (m_side)? m_hero2 : m_hero1; - - int attackDefenseBonus = currentStack->Attack() - st->Defense(); - double damageFactor = 1.0; - if(attackDefenseBonus < 0) //decreasing dmg - { - if(0.02 * (-attackDefenseBonus) > 0.3) - { - damageFactor += -0.3; - } - else - { - damageFactor += 0.02 * attackDefenseBonus; - } - } - else //increasing dmg - { - if(0.05 * attackDefenseBonus > 4.0) - { - damageFactor += 4.0; - } - else - { - damageFactor += 0.05 * attackDefenseBonus; - } - } - - cs.damage_max = (int)(currentStack->getMaxDamage() * currentStack->count * damageFactor); - if (cs.damage_max > hitPoints) - { - cs.damage_max = hitPoints; - } - - cs.damage_min = (int)(currentStack->getMinDamage() * currentStack->count * damageFactor); - if (cs.damage_min > hitPoints) - { - cs.damage_min = hitPoints; - } - - cs.amount_max = cs.damage_max / stackHP; - cs.amount_min = cs.damage_min / stackHP; - - cs.leftHitPoints_for_max = (hitPoints - cs.damage_max) % stackHP; - cs.leftHitPoint_for_min = (hitPoints - cs.damage_min) % stackHP; - - m_statCasualties.push_back(std::pair(id, cs)); - - if (st->getCreature()->isShooting() && st->shots > 0) - { - m_statDistanceFromShooters.push_back(std::pair(id, m_battleHelper.GetShortestDistance(currentStack->position, st->position))); - } - - if (currentStack->hasBonusOfType(Bonus::FLYING) || (currentStack->getCreature()->isShooting() && currentStack->shots > 0)) - { - m_statDistance.push_back(std::pair(id, m_battleHelper.GetShortestDistance(currentStack->position, st->position))); - } - else - { - m_statDistance.push_back(std::pair(id, m_battleHelper.GetDistanceWithObstacles(currentStack->position, st->position))); - } - } - else - { - if (st->count < 1) - { - continue; - } - int hitPoints = st->count * stackHP - (stackHP - st->firstHPleft); - - totalDamage += (st->getMaxDamage() + st->getMinDamage()) * st->count / 2; - totalHitPoints += hitPoints; - } - } - if (totalDamage / static_cast(totalEnemyDamage) < 0.5 && - totalHitPoints / static_cast(totalEnemyHitPoints) < 0.5) - { - m_bEnemyDominates = true; - DbgBox("** EnemyDominates!"); - } - else - { - m_bEnemyDominates = false; - } - - //boost compile hack - typedef int const std::pair::* IntPtr; - typedef int const SCreatureCasualties::* CreaPtr; - typedef SCreatureCasualties const std::pair::* CreaPairPtr; - - // sort max damage - std::sort(m_statMaxDamage.begin(), m_statMaxDamage.end(), - bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); - // sort min damage - std::sort(m_statMinDamage.begin(), m_statMinDamage.end(), - bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); - // sort max speed - std::sort(m_statMaxSpeed.begin(), m_statMaxSpeed.end(), - bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); - // sort distance - std::sort(m_statDistance.begin(), m_statDistance.end(), - bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) < bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); - // sort distance from shooters - std::sort(m_statDistanceFromShooters.begin(), m_statDistanceFromShooters.end(), - bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) < bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); - // sort hit points - std::sort(m_statHitPoints.begin(), m_statHitPoints.end(), - bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_1) > bind((IntPtr)&creature_stat::value_type::second, boost::lambda::_2)); - // sort casualties - std::sort(m_statCasualties.begin(), m_statCasualties.end(), - bind((CreaPtr)&creature_stat_casualties::value_type::second_type::damage_max, - bind((CreaPairPtr)&creature_stat_casualties::value_type::second, boost::lambda::_1)) - > - bind((CreaPtr)&creature_stat_casualties::value_type::second_type::damage_max, - bind((CreaPairPtr)&creature_stat_casualties::value_type::second, boost::lambda::_2))); -} - -BattleAction CBattleLogic::MakeDecision(int stackID) -{ - const CStack *currentStack = m_cb->battleGetStackByID(stackID); - if(currentStack->position < 0 || currentStack->getCreature()->idNumber == 147) //turret or first aid kit - { - return BattleAction::makeDefend(currentStack); - } - MakeStatistics(stackID); - - list creatures; - int additionalInfo = 0; //? - - if (m_bEnemyDominates) - { - creatures = PerformBerserkAttack(stackID, additionalInfo); - } - else - { - creatures = PerformDefaultAction(stackID, additionalInfo); - } - - /*std::string message("Creature will be attacked - "); - message += boost::lexical_cast(creature_to_attack); - DbgBox(message.c_str());*/ - - - if (additionalInfo == -1 || creatures.empty()) - { - // defend - return BattleAction::makeDefend(currentStack); - } - else if (additionalInfo == -2) - { - return BattleAction::makeWait(currentStack); - } - - list::iterator it, eit; - eit = creatures.end(); - for (it = creatures.begin(); it != eit; ++it) - { - BattleAction ba = MakeAttack(stackID, *it); - if (ba.actionType != action_walk_and_attack) - { - continue; - } - else - { -#if defined PRINT_DEBUG - PrintBattleAction(ba); -#endif - return ba; - } - } - BattleAction ba = MakeAttack(stackID, *creatures.begin()); - return ba; -} - - - -std::vector CBattleLogic::GetAvailableHexesForAttacker(const CStack *defender, const CStack *attacker) -{ - int x = m_battleHelper.DecodeXPosition(defender->position); - int y = m_battleHelper.DecodeYPosition(defender->position); - bool defenderIsDW = defender->doubleWide(); - bool attackerIsDW = attacker->doubleWide(); - // TOTO: should be std::vector but for debug purpose std::pair is used - typedef std::pair hexPoint; - std::list candidates; - std::vector fields; - if (defenderIsDW) - { - if (defender->attackerOwned) - { - // from left side - if (!(y % 2)) - { - // up - candidates.push_back(hexPoint(x - 2, y - 1)); - candidates.push_back(hexPoint(x - 1, y - 1)); - candidates.push_back(hexPoint(x, y - 1)); - // down - candidates.push_back(hexPoint(x - 2, y + 1)); - candidates.push_back(hexPoint(x - 1, y + 1)); - candidates.push_back(hexPoint(x, y + 1)); - } - else - { - // up - candidates.push_back(hexPoint(x - 1, y - 1)); - candidates.push_back(hexPoint(x, y - 1)); - candidates.push_back(hexPoint(x + 1, y - 1)); - // down - candidates.push_back(hexPoint(x - 1, y + 1)); - candidates.push_back(hexPoint(x, y + 1)); - candidates.push_back(hexPoint(x + 1, y + 1)); - - } - candidates.push_back(hexPoint(x - 2, y)); - candidates.push_back(hexPoint(x + 1, y)); - - } - else - { - // from right - if (!(y % 2)) - { - // up - candidates.push_back(hexPoint(x - 1, y - 1)); - candidates.push_back(hexPoint(x, y - 1)); - candidates.push_back(hexPoint(x + 1, y - 1)); - // down - candidates.push_back(hexPoint(x - 1, y + 1)); - candidates.push_back(hexPoint(x, y + 1)); - candidates.push_back(hexPoint(x + 1, y + 1)); - } - else - { - // up - candidates.push_back(hexPoint(x, y - 1)); - candidates.push_back(hexPoint(x + 1, y - 1)); - candidates.push_back(hexPoint(x + 2, y - 1)); - // down - candidates.push_back(hexPoint(x, y + 1)); - candidates.push_back(hexPoint(x + 1, y + 1)); - candidates.push_back(hexPoint(x + 2, y + 1)); - } - candidates.push_back(hexPoint(x - 1, y)); - candidates.push_back(hexPoint(x + 2, y)); - } - } - else - { - if (!(y % 2)) // even line - { - // up - candidates.push_back(hexPoint(x - 1, y - 1)); - candidates.push_back(hexPoint(x, y - 1)); - // down - candidates.push_back(hexPoint(x - 1, y + 1)); - candidates.push_back(hexPoint(x, y + 1)); - } - else // odd line - { - // up - candidates.push_back(hexPoint(x, y - 1)); - candidates.push_back(hexPoint(x + 1, y - 1)); - // down - candidates.push_back(hexPoint(x, y + 1)); - candidates.push_back(hexPoint(x + 1, y + 1)); - } - - candidates.push_back(hexPoint(x + 1, y)); - candidates.push_back(hexPoint(x - 1, y)); - } - - // remove fields which are out of bounds or obstacles - for (std::list::iterator it = candidates.begin(); it != candidates.end(); ++it) - { - if (it->first < 1 || it->first > m_battleHelper.BattlefieldWidth || - it->second < 1 || it->second > m_battleHelper.BattlefieldHeight) - { - // field is out of bounds - //it = candidates.erase(it); - continue; - } - - int new_pos = m_battleHelper.GetBattleFieldPosition(it->first, it->second); - const CStack *st = m_cb->battleGetStackByPos(new_pos); - - if (st == NULL || st->count < 1) - { - if (attackerIsDW) - { - int tail_pos = -1; - if (attacker->attackerOwned) // left side - { - int tail_pos_x = it->first - 1; - if (tail_pos_x < 1) - { - continue; - } - tail_pos = m_battleHelper.GetBattleFieldPosition(it->first, it->second); - } - else // right side - { - int tail_pos_x = it->first + 1; - if (tail_pos_x > m_battleHelper.BattlefieldWidth) - { - continue; - } - tail_pos = m_battleHelper.GetBattleFieldPosition(it->first, it->second); - } - assert(tail_pos >= 0 && "Error during calculation position of double wide creature"); - //CStack *tailStack = m_cb->battleGetStackByPos(tail_pos); - if (st != NULL && st->count >= 1) - { - continue; - } - } - - fields.push_back(new_pos); - - } - else if (attacker) - { - if (attacker->ID == st->ID) - { - fields.push_back(new_pos); - } - } - // - //++it; - } - return fields; -} - -BattleAction CBattleLogic::MakeAttack(int attackerID, int destinationID) -{ - const CStack *attackerStack = m_cb->battleGetStackByID(attackerID), - *destinationStack = m_cb->battleGetStackByID(destinationID); - assert(attackerStack && destinationStack); - - //don't attack ourselves - if(destinationStack->attackerOwned == !m_side) - { - return BattleAction::makeDefend(attackerStack); - } - - if (m_cb->battleCanShoot(attackerStack, destinationStack->position)) // shoot - { - return BattleAction::makeShotAttack(attackerStack, destinationStack); - } - else - { - // go or go&attack - int dest_tile = -1; - std::vector av_tiles = GetAvailableHexesForAttacker(m_cb->battleGetStackByID(destinationID), m_cb->battleGetStackByID(attackerID)); - if (av_tiles.size() < 1) - { - return BattleAction::makeDefend(attackerStack); - } - - // get the best tile - now the nearest - - int prev_distance = m_battleHelper.InfiniteDistance; - int currentPos = m_cb->battleGetPos(attackerID); - - for (std::vector::iterator it = av_tiles.begin(); it != av_tiles.end(); ++it) - { - int dist = m_battleHelper.GetDistanceWithObstacles(*it, m_cb->battleGetPos(attackerID)); - if (dist < prev_distance) - { - prev_distance = dist; - dest_tile = *it; - } - if (*it == currentPos) - { - dest_tile = currentPos; - break; - } - } - - std::vector fields = m_cb->battleGetAvailableHexes(m_cb->battleGetStackByID(attackerID), false); - - if(fields.size() == 0) - { - return BattleAction::makeDefend(attackerStack); - } - - BattleAction ba; - ba.side = m_side; - //ba.actionType = 6; // go and attack - ba.stackNumber = attackerID; - ba.destinationTile = static_cast(dest_tile); - //simplified checking for possibility of attack (previous was too simplified) - int destStackPos = m_cb->battleGetPos(destinationID); - if(BattleHex::mutualPosition(dest_tile, destStackPos) != -1) - ba.additionalInfo = destStackPos; - else if(BattleHex::mutualPosition(dest_tile, destStackPos+1) != -1) - ba.additionalInfo = destStackPos+1; - else if(BattleHex::mutualPosition(dest_tile, destStackPos-1) != -1) - ba.additionalInfo = destStackPos-1; - else - return BattleAction::makeDefend(attackerStack); - - int nearest_dist = m_battleHelper.InfiniteDistance; - int nearest_pos = -1; - - // if double wide calculate tail - int tail_pos = -1; - if (attackerStack->doubleWide()) - { - int x_pos = m_battleHelper.DecodeXPosition(attackerStack->position); - int y_pos = m_battleHelper.DecodeYPosition(attackerStack->position); - if (attackerStack->attackerOwned) - { - x_pos -= 1; - } - else - { - x_pos += 1; - } - // if creature can perform attack without movement - do it! - tail_pos = m_battleHelper.GetBattleFieldPosition(x_pos, y_pos); - if (dest_tile == tail_pos) - { - ba.additionalInfo = dest_tile; - ba.actionType = action_walk_and_attack; -#if defined PRINT_DEBUG - PrintBattleAction(ba); -#endif - assert(m_cb->battleGetStackByPos(ba.additionalInfo, false)); //if action is action_walk_and_attack additional info must point on enemy stack - assert(m_cb->battleGetStackByPos(ba.additionalInfo, false) != attackerStack); //don't attack ourselve - return ba; - } - } - - for (std::vector::const_iterator it = fields.begin(); it != fields.end(); ++it) - { - if (*it == dest_tile) - { - // attack! - ba.actionType = action_walk_and_attack; -#if defined PRINT_DEBUG - PrintBattleAction(ba); -#endif - assert(m_cb->battleGetStackByPos(ba.additionalInfo)); //if action is action_walk_and_attack additional info must point on enemy stack - assert(m_cb->battleGetStackByPos(ba.additionalInfo) != attackerStack); //don't attack ourselve - return ba; - } - int d = m_battleHelper.GetDistanceWithObstacles(dest_tile, *it); - if (d < nearest_dist) - { - nearest_dist = d; - nearest_pos = *it; - } - } - string message; - message = "Attacker position X="; - message += boost::lexical_cast(m_battleHelper.DecodeXPosition(nearest_pos)) + ", Y="; - message += boost::lexical_cast(m_battleHelper.DecodeYPosition(nearest_pos)); - DbgBox(message.c_str()); - - ba.actionType = action_walk; - ba.destinationTile = (ui16)nearest_pos; - ba.additionalInfo = -1; -#if defined PRINT_DEBUG - PrintBattleAction(ba); -#endif - - return ba; - } -} -/** - * The main idea is to perform maximum casualties. - */ -list CBattleLogic::PerformBerserkAttack(int stackID, int &additionalInfo) -{ - const CStack * c = m_cb->battleGetStackByID(stackID); - // attack to make biggest damage - list creatures; - - if (!m_statCasualties.empty()) - { - //creature_to_attack = m_statCasualties.begin()->first; - creature_stat_casualties::iterator it = m_statCasualties.begin(); - for (; it != m_statCasualties.end(); ++it) - { - if (it->second.amount_min <= 0) - { - creatures.push_back(it->first); - continue; - } - for (creature_stat::const_iterator it2 = m_statDistance.begin(); it2 != m_statDistance.end(); ++it2) - { - if (it2->first == it->first && it2->second - 1 <= c->getCreature()->valOfBonuses(Bonus::STACKS_SPEED)) - { - creatures.push_front(it->first); - } - } - } - creatures.push_back(m_statCasualties.begin()->first); - } - return creatures; -} - -list CBattleLogic::PerformDefaultAction(int stackID, int &additionalInfo) -{ - // first approach based on the statistics and weights - // if this solution was fine we would develop this idea - // - std::map votes; - - for (creature_stat::iterator it = m_statMaxDamage.begin(); it != m_statMaxDamage.end(); ++it) - { - votes[it->first] = 0; - } - - votes[m_statMaxDamage.begin()->first] += m_battleHelper.GetVoteForMaxDamage(); - votes[m_statMinDamage.begin()->first] += m_battleHelper.GetVoteForMinDamage(); - if (m_statDistanceFromShooters.size()) - { - votes[m_statDistanceFromShooters.begin()->first] += m_battleHelper.GetVoteForDistanceFromShooters(); - } - votes[m_statDistance.begin()->first] += m_battleHelper.GetVoteForDistance(); - votes[m_statHitPoints.begin()->first] += m_battleHelper.GetVoteForHitPoints(); - votes[m_statMaxSpeed.begin()->first] += m_battleHelper.GetVoteForMaxSpeed(); - - - // get creature to attack - - int max_vote = 0; - - list creatures; - - for (std::map::iterator it = votes.begin(); it != votes.end(); ++it) - { - if (bool(m_cb->battleGetStackByID(it->first)->attackerOwned) == m_side //it's hostile stack - && it->second > max_vote) - { - max_vote = it->second; - creatures.push_front(it->first); - } - } - additionalInfo = 0; // list contains creatures which shoud be attacked - - return creatures; -} - -void CBattleLogic::PrintBattleAction(const BattleAction &action) // for debug purpose -{ - std::string message("Battle action \n"); - message += "\taction type - "; - switch (action.actionType) - { - case 0: - message += "Cancel BattleAction\n"; - break; - case 1: - message += "Hero cast a spell\n"; - break; - case 2: - message += "Walk\n"; - break; - case 3: - message += "Defend\n"; - break; - case 4: - message += "Retreat from the battle\n"; - break; - case 5: - message += "Surrender\n"; - break; - case 6: - message += "Walk and Attack\n"; - break; - case 7: - message += "Shoot\n"; - break; - case 8: - message += "Wait\n"; - break; - case 9: - message += "Catapult\n"; - break; - case 10: - message += "Monster casts a spell\n"; - break; - } - message += "\tDestination tile: X = "; - message += boost::lexical_cast(m_battleHelper.DecodeXPosition(action.destinationTile)); - message += ", Y = " + boost::lexical_cast(m_battleHelper.DecodeYPosition(action.destinationTile)); - message += "\nAdditional info: "; - if (action.actionType == 6)// || action.actionType == 7) - { - message += "stack - " + boost::lexical_cast(m_battleHelper.DecodeXPosition(action.additionalInfo)); - message += ", " + boost::lexical_cast(m_battleHelper.DecodeYPosition(action.additionalInfo)); - message += ", creature - "; - const CStack *c = m_cb->battleGetStackByPos(action.additionalInfo); - if (c && c->getCreature()) - { - message += c->getCreature()->nameRef; - } - else - { - message += "NULL"; - } - } - else - { - message += boost::lexical_cast(action.additionalInfo); - } - -#ifdef _WIN32 - HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); - - CONSOLE_SCREEN_BUFFER_INFO csbi; - GetConsoleScreenBufferInfo(hConsole, &csbi); - SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN | FOREGROUND_INTENSITY); - -#else - std::string color; - color = "\x1b[1;40;32m"; - std::cout << color; -#endif - - std::cout << message.c_str() << std::endl; - -#ifdef _WIN32 - SetConsoleTextAttribute(hConsole, csbi.wAttributes); -#else - color = "\x1b[0m"; - std::cout << color; -#endif -} diff --git a/AI/GeniusAI/BattleLogic.h b/AI/GeniusAI/BattleLogic.h deleted file mode 100644 index e9c0130ac..000000000 --- a/AI/GeniusAI/BattleLogic.h +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include "Common.h" -#include "BattleHelper.h" - -#pragma warning (disable: 4100 4251 4245 4018 4081) - -#include "../../CCallback.h" -#include "../../lib/CCreatureHandler.h" -#include "../../lib/CObjectHandler.h" -#pragma warning (default: 4100 4251 4245 4018 4081) - -#pragma warning (disable: 4100) - -using namespace std; - -namespace geniusai { namespace BattleAI { - -/** - * Class is responsible for making decision during the battle. - */ -class CBattleLogic -{ -private: - enum EMainStrategyType - { - strategy_super_aggresive, - strategy_aggresive, - strategy_neutral, - strategy_defensive, - strategy_super_defensive, - strategy_berserk_attack /** cause max damage, usually when creatures fight against overwhelming army*/ - }; - enum ECreatureRoleInBattle - { - creature_role_shooter, - creature_role_defenser, - creature_role_fast_attacker, - creature_role_attacker - }; - enum EActionType - { - action_cancel = 0, // Cancel BattleAction - action_cast_spell = 1, // Hero cast a spell - action_walk = 2, // Walk - action_defend = 3, // Defend - action_retreat = 4, // Retreat from the battle - action_surrender = 5, // Surrender - action_walk_and_attack = 6, // Walk and Attack - action_shoot = 7, // Shoot - action_wait = 8, // Wait - action_catapult = 9, // Catapult - action_monster_casts_spell = 10 // Monster casts a spell (i.e. Faerie Dragons) - }; - struct SCreatureCasualties - { - int amount_max; // amount of creatures that will be dead - int amount_min; - int damage_max; // number of hit points that creature will lost - int damage_min; - int leftHitPoints_for_max; // number of hit points that will remain (for last unity) - int leftHitPoint_for_min; // scenario - }; -public: - CBattleLogic(CCallback *cb, const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); - ~CBattleLogic(); - - void SetCurrentTurn(int turn); - /** - * Get the final decision. - */ - BattleAction MakeDecision(int stackID); -private: - CBattleHelper m_battleHelper; - //BattleInfo m_battleInfo; - int m_iCurrentTurn; - bool m_bIsAttacker; - CCallback *m_cb; - const CCreatureSet *m_army1; - const CCreatureSet *m_army2; - int3 m_tile; - const CGHeroInstance *m_hero1; - const CGHeroInstance *m_hero2; - bool m_side; - - // statistics - typedef std::vector > creature_stat; // first - creature id, second - value - creature_stat m_statMaxDamage; - creature_stat m_statMinDamage; - // - creature_stat m_statMaxSpeed; - creature_stat m_statDistance; - creature_stat m_statDistanceFromShooters; - creature_stat m_statHitPoints; - - typedef std::vector > creature_stat_casualties; - creature_stat_casualties m_statCasualties; - - bool m_bEnemyDominates; - /** - * Before decision we have to make some calculation and simulation. - */ - void MakeStatistics(int currentCreatureId); - /** - * Helper function. It's used for performing an attack action. - */ - std::vector GetAvailableHexesForAttacker(const CStack *defender, const CStack *attacker = NULL); - /** - * Make an attack action if it's possible. - * If it's not possible then function returns defend action. - */ - BattleAction MakeAttack(int attackerID, int destinationID); - /** - * Berserk mode - do maximum casualties. - * Return vector wiht IDs of creatures to attack, - * additional info: -2 means wait, -1 - defend, 0 - make attack - */ - list PerformBerserkAttack(int stackID, int &additionalInfo); - /** - * Normal mode - equilibrium between casualties and yields. - * Return vector wiht IDs of creatures to attack, - * additional info: -2 means wait, -1 - defend, 0 - make attack - */ - list PerformDefaultAction(int stackID, int &additionalInfo); - /** - * Only for debug purpose. - */ - void PrintBattleAction(const BattleAction &action); -}; - -}} \ No newline at end of file diff --git a/AI/GeniusAI/CGeniusAI.cpp b/AI/GeniusAI/CGeniusAI.cpp deleted file mode 100644 index 41b5f26b9..000000000 --- a/AI/GeniusAI/CGeniusAI.cpp +++ /dev/null @@ -1,1396 +0,0 @@ -#include "StdInc.h" -#include "CGeniusAI.h" - -#include "../../lib/BattleState.h" -#include "../../lib/CBuildingHandler.h" -#include "../../lib/CHeroHandler.h" -#include "../../lib/VCMI_Lib.h" -#include "../../lib/NetPacks.h" -#include "AIPriorities.h" -#include "../../lib/CGameState.h" -#include "../../lib/GameConstants.h" - -using std::endl; -using geniusai::CGeniusAI; -class LibClasses; - -#if defined (_MSC_VER) && (_MSC_VER >= 1020) || (__MINGW32__) -// Excludes rarely used stuff from windows headers - delete this line if -// something is missing. -#define WIN32_LEAN_AND_MEAN -#include -#endif - -void DbgBox(const char* msg, bool messageBox) -{ -#if defined PRINT_DEBUG -#if defined _DEBUG -//# if 0 -# if defined (_MSC_VER) && (_MSC_VER >= 1020) - if (messageBox) - { - MessageBoxA(NULL, msg, "Debug message", MB_OK | MB_ICONASTERISK); - } -# endif - tlog6 << msg << std::endl; -#endif -#endif -} - - -// TODO: Rewrite those i-s, o-s to something meaningful. -bool CGeniusAI::AIObjectContainer::operator<(const AIObjectContainer& b) const -{ - if (o->pos != b.o->pos) - return o->pos < b.o->pos; - else - return o->id < b.o->id; -} - -CGeniusAI::HypotheticalGameState::HeroModel::HeroModel( - const CGHeroInstance* h) - : finished(false), h(h) -{ - pos = h->getPosition(false); - remainingMovement = h->movement; -} - -CGeniusAI::HypotheticalGameState::TownModel::TownModel( - const CGTownInstance* t) - : t(t) -{ - hasBuilt = static_cast(t->builded); - creaturesToRecruit = t->creatures; - //creaturesInGarrison = t->getArmy(); -} - -CGeniusAI::HypotheticalGameState::HypotheticalGameState(CGeniusAI& ai) - : knownVisitableObjects(ai.knownVisitableObjects) -{ - AI = &ai; - std::vector heroes = ai.m_cb->getHeroesInfo(); - for (std::vector::iterator i = heroes.begin(); - i != heroes.end(); - i++) - heroModels.push_back(HeroModel(*i)); - - std::vector towns = ai.m_cb->getTownsInfo(); - for (std::vector ::iterator i = towns.begin(); - i != towns.end(); - i++) { - if ( (*i)->tempOwner == ai.m_cb->getMyColor() ) - townModels.push_back(TownModel(*i)); - } - - if (ai.m_cb->howManyTowns() != 0) { - AvailableHeroesToBuy = - ai.m_cb->getAvailableHeroes(ai.m_cb->getTownBySerial(0)); - } - - for (int i = 0; i < 8; i++) - resourceAmounts.push_back(ai.m_cb->getResourceAmount(i)); -} - - -void CGeniusAI::HypotheticalGameState::update(CGeniusAI& ai) -{ - AI = &ai; - knownVisitableObjects = ai.knownVisitableObjects; - std::vector oldModels = heroModels; - heroModels.clear(); - - std::vector heroes = ai.m_cb->getHeroesInfo(); - for (std::vector::iterator i = heroes.begin(); i != heroes.end(); i++) - heroModels.push_back(HeroModel(*i)); - - int j; - for (int i = 0; i < oldModels.size(); ++i) - { - for (j = 0; j < heroModels.size(); ++j) - { - if (oldModels[i].h->subID == heroModels[j].h->subID) - { - heroModels[j].finished = oldModels[i].finished; - heroModels[j].previouslyVisited_pos = oldModels[i].previouslyVisited_pos; - } - } - } - - townModels.clear(); - std::vector towns = ai.m_cb->getTownsInfo(); - for (std::vector::iterator i = towns.begin(); i != towns.end(); i++) - { - if ( (*i)->tempOwner == ai.m_cb->getMyColor() ) - townModels.push_back(TownModel(*i)); - } - - if (ai.m_cb->howManyTowns()) - { - AvailableHeroesToBuy = ai.m_cb->getAvailableHeroes(ai.m_cb->getTownBySerial(0)); - } - - resourceAmounts.clear(); - for (int i = 0; i < 8; i++) - resourceAmounts.push_back(ai.m_cb->getResourceAmount(i)); -} - -CGeniusAI::HeroObjective::HeroObjective(const HypotheticalGameState &hgs, - Type t, - const CGObjectInstance* object, - HypotheticalGameState::HeroModel* h, - CGeniusAI* ai) - : hgs(hgs), object(object) -{ - AI = ai; - pos = object->pos; - type = t; - whoCanAchieve.push_back(h); - _value = -1; -} - - -double CGeniusAI::HeroObjective::getValue() const -{ - if (_value >= 0) - return _value - _cost; - - // TODO: each object should have an associated cost to visit IE - // (tree of knowledge 1000 gold/10 gems) - vector resourceCosts; - for (int i = 0; i < 8; i++) - resourceCosts.push_back(0); - - if (object->ID == 47) // School of magic - resourceCosts[6] += 1000; - - // TODO: Add some meaningful (and not exploitable) number here. - double bestCost = 9e9f; - HypotheticalGameState::HeroModel* bestHero = NULL; - if (type != AIObjective::finishTurn) - { - for (int i = 0; i < whoCanAchieve.size(); i++) - { - int distOutOfTheWay = 0; - CPath path3; - //from hero to object - if (AI->m_cb->getPath(whoCanAchieve[i]->pos, - pos, - whoCanAchieve[i]->h, - path3)) { - distOutOfTheWay+=path3.nodes[0].dist; - } - - // from object to goal - if (AI->m_cb->getPath(pos, - whoCanAchieve[i]->interestingPos, - whoCanAchieve[i]->h, - path3)) { - distOutOfTheWay += path3.nodes[0].dist; - // from hero directly to goal - if (AI->m_cb->getPath(whoCanAchieve[i]->pos, - whoCanAchieve[i]->interestingPos, - whoCanAchieve[i]->h, - path3)) - distOutOfTheWay-=path3.nodes[0].dist; - } - - double cost = AI->m_priorities->getCost(resourceCosts, - whoCanAchieve[i]->h, - distOutOfTheWay); - if (cost < bestCost) - { - bestCost = cost; - bestHero = whoCanAchieve[i]; - } - } // for (int i = 0; i < whoCanAchieve.size(); i++) - } - else // if (type != AIObjective::finishTurn) - bestCost = 0; - - if (bestHero) - { - whoCanAchieve.clear(); - whoCanAchieve.push_back(bestHero); - } - - _value = AI->m_priorities->getValue(*this); - _cost = bestCost; - return _value - _cost; -} - - -bool CGeniusAI::HeroObjective::operator<(const HeroObjective& other) const -{ - if (type != other.type) - return type < other.type; - else if (pos != other.pos) - return pos < other.pos; - else if (object->id != other.object->id) - return object->id < other.object->id; - else if ((dynamic_cast(object) != NULL) && - (whoCanAchieve.front()->h->id != other.whoCanAchieve.front()->h->id)) - return whoCanAchieve.front()->h->id < other.whoCanAchieve.front()->h->id; - else - return false; -} - - -void CGeniusAI::HeroObjective::print() const -{ - switch (type) - { - case visit: - tlog6 << "visit " << object->hoverName - << " at (" <pos.x << ","<< object->pos.y << ")" ; - break; - case attack: - tlog6 << "attack " << object->hoverName; - break; - case finishTurn: - tlog6 << "finish turn"; - // TODO: Add a default, just in case. - } - if (whoCanAchieve.size() == 1) - tlog6 << " with " << whoCanAchieve.front()->h->hoverName; -} - - -CGeniusAI::TownObjective::TownObjective( - const HypotheticalGameState& hgs, - Type t, - HypotheticalGameState::TownModel* tn, - int Which, - CGeniusAI * ai) - : hgs(hgs), whichTown(tn), which(Which) -{ - AI = ai; - type = t; - _value = -1; -} - -double CGeniusAI::TownObjective::getValue() const -{ - if (_value >= 0) - return _value - _cost; - - // TODO: Include a constant stating the meaning of 8 (number of resources). - vector resourceCosts(8,0); - CBuilding* b = NULL; - CCreature* creature = NULL; - double cost = 0; // TODO: Needed? - int ID = 0; - int newID = 0; - int howMany = 0; - ui32 creatures_max = 0; - - switch (type) - { - case recruitHero: - resourceCosts[6] = 2500; // TODO: Define somehow the meaning of gold etc. - break; - - case buildBuilding: - b = VLC->buildh->buildings[whichTown->t->subID][which]; - for (int i = 0; b && ( i < b->resources.size() ); ++i) - resourceCosts[i] = b->resources[i]; - break; - - case recruitCreatures: - // Buy upgraded if possible. - ID = whichTown->creaturesToRecruit[which].second.back(); - creature = VLC->creh->creatures[ID]; - howMany = whichTown->creaturesToRecruit[which].first; - creatures_max = 0; // Max creatures you can recruit of this type. - - for (int i = 0; i < creature->cost.size(); i++) - { - if (creature->cost[i] != 0) - creatures_max = hgs.resourceAmounts[i]/creature->cost[i]; - else - creatures_max = INT_MAX; // TODO: Will have to rewrite it. - // TODO: Buy the best units (the least I can buy)? - vstd::amin(howMany, creatures_max); - } - // The cost of recruiting the stack of creatures. - for (int i = 0; creature && (i < creature->cost.size() ); ++i) - resourceCosts[i] = creature->cost[i]*howMany; - break; - - case upgradeCreatures: - UpgradeInfo ui; - AI->m_cb->getUpgradeInfo(whichTown->t,which, ui); - ID = whichTown->t->getCreature(which)->idNumber; - howMany = whichTown->t->getStackCount(which); - - newID = ui.newID.back(); - int upgrade_serial = ui.newID.size() - 1; -// for (std::set< std::pair >::iterator j = ui.cost[upgrade_serial].begin(); j != ui.cost[upgrade_serial].end(); j++) -// resourceCosts[j->first] = j->second*howMany; - break; - } - - _cost = AI->m_priorities->getCost(resourceCosts, NULL, 0); - _value = AI->m_priorities->getValue(*this); - return _value - _cost; -} - - -bool CGeniusAI::TownObjective::operator<(const TownObjective &other) const -{ - if (type != other.type) - return type < other.type; - else if (which != other.which) - return which < other.which; - else if (whichTown->t->id != other.whichTown->t->id) - return whichTown->t->id < other.whichTown->t->id; - else - return false; -} - - -void CGeniusAI::TownObjective::print() const -{ - HypotheticalGameState::HeroModel hm; - CBuilding* b = NULL; - const CCreature* creature = NULL; - int ID = 0; - int howMany = 0; - int newID = 0; // TODO: Needed? - int hSlot = 0; // TODO: Needed? - ui32 creatures_max; - - switch (type) - { - case recruitHero: - tlog6 << "recruit hero."; - break; - - case buildBuilding: - b = VLC->buildh->buildings[whichTown->t->subID][which]; - tlog6 << "build " << b->Name() << " cost = "; - if (b->resources.size()) - { - if (b->resources[0]) - tlog6 << b->resources[0] << " wood. "; - if (b->resources[1]) - tlog6 << b->resources[1] << " mercury. "; - if (b->resources[2]) - tlog6 << b->resources[2] << " ore. "; - if (b->resources[3]) - tlog6 << b->resources[3] << " sulfur. "; - if (b->resources[4]) - tlog6 << b->resources[4] << " crystal. "; - if (b->resources[5]) - tlog6 << b->resources[5] << " gems. "; - if (b->resources[6]) - tlog6 << b->resources[6] << " gold. "; - } - break; - - case recruitCreatures: - // Buy upgraded if possible. - ID = whichTown->creaturesToRecruit[which].second.back(); - creature = VLC->creh->creatures[ID]; - howMany = whichTown->creaturesToRecruit[which].first; - creatures_max = 0; - - for (int i = 0; i < creature->cost.size(); i++) - { - if (creature->cost[i]) - creatures_max = hgs.resourceAmounts[i]/creature->cost[i]; - else - creatures_max = INT_MAX; - vstd::amin(howMany, creatures_max); - } - tlog6 << "recruit " << howMany << " " << creature->namePl - << " (Total AI Strength " << creature->AIValue*howMany - << "). cost = "; - - if (creature->cost.size()) - { - if (creature->cost[0]) - tlog6 << creature->cost[0]*howMany << " wood. "; - if (creature->cost[1]) - tlog6 << creature->cost[1]*howMany << " mercury. "; - if (creature->cost[2]) - tlog6 << creature->cost[2]*howMany << " ore. "; - if (creature->cost[3]) - tlog6 << creature->cost[3]*howMany << " sulfur. "; - if (creature->cost[4]) - tlog6 << creature->cost[4]*howMany << " cristal. "; - if (creature->cost[5]) - tlog6 << creature->cost[5]*howMany << " gems. "; - if (creature->cost[6]) - tlog6 << creature->cost[6]*howMany << " gold. "; - } - break; // case recruitCreatures. - - case upgradeCreatures: - UpgradeInfo ui; - AI->m_cb->getUpgradeInfo (whichTown->t, which, ui); - ID = whichTown->t->getCreature(which)->idNumber; - tlog6 << "upgrade " << VLC->creh->creatures[ID]->namePl; - //ui.cost - break; - } // switch(type) -} - - -CGeniusAI::CGeniusAI() : m_generalAI(), m_state(NO_BATTLE) -{ - m_priorities = new Priorities("AI/GeniusAI.brain"); -} - - -CGeniusAI::~CGeniusAI() -{ - delete m_priorities; -} - - -void CGeniusAI::init(CCallback *CB) -{ - m_cb = CB; - m_generalAI.init(CB); - - human = false; - playerID = m_cb->getMyColor(); - std::string info = std::string("GeniusAI initialized for player ") - + boost::lexical_cast(playerID); - m_battleLogic = NULL; - DbgBox(info.c_str()); -} - - -void CGeniusAI::reportResources() -{ - tlog6 << "Day " << m_cb->getDate() << ": "; - tlog6 << "AI Player " <getMyColor()<< " with " - << m_cb->howManyHeroes(true) << " heroes. " << endl; - tlog6 << m_cb->getResourceAmount(0) << " wood. "; - tlog6 << m_cb->getResourceAmount(1) << " mercury. "; - tlog6 << m_cb->getResourceAmount(2) << " ore. "; - tlog6 << m_cb->getResourceAmount(3) << " sulfur. "; - tlog6 << m_cb->getResourceAmount(4) << " crystal. "; - tlog6 << m_cb->getResourceAmount(5) << " gems. "; - tlog6 << m_cb->getResourceAmount(6) << " gold."; - tlog6 << endl; -} - - -void CGeniusAI::addHeroObjectives(CGeniusAI::HypotheticalGameState::HeroModel& h, - CGeniusAI::HypotheticalGameState& hgs) -{ - int3 hpos = h.pos; - int3 destination; - int3 interestingPos; - CPath path; - int movement = h.remainingMovement; - int maxInteresting = 0; - AIObjective::Type tp = AIObjective::visit; - - if (h.finished) - return; - - for (std::set::const_iterator i = hgs.knownVisitableObjects.begin(); i != hgs.knownVisitableObjects.end(); i++) - { - tp = AIObjective::visit; - if (h.previouslyVisited_pos == i->o->getSightCenter()) - continue; - - //TODO: what would the hero actually visit if he went to that spot - // maybe the hero wants to visit a seemingly unguarded enemy town, - // but there is a hero on top of it. - // if(i->o->) - if (i->o->ID != GameConstants::HEROI_TYPE) - {// Unless you are trying to visit a hero. - bool heroThere = false; - for(int j = 0; j < hgs.heroModels.size(); j++) - { - if (hgs.heroModels[j].pos == i->o->getSightCenter()) - heroThere = true; - } - if (heroThere) // It won't work if there is already someone visiting that spot. - continue; - } - if (i->o->ID == GameConstants::HEROI_TYPE && // Visiting friendly heroes not yet supported. - i->o->getOwner() == m_cb->getMyColor()) - continue; - if (i->o->id == h.h->id) // Don't visit yourself (should be caught by above). - continue; - // Don't visit a mine if you own, there's almost no - // point(maybe to leave guards or because the hero's trapped). - if (i->o->ID == 53 && i->o->getOwner() == m_cb->getMyColor()) - continue; - - if (i->o->getOwner() != m_cb->getMyColor()) - { - // TODO: I feel like the AI shouldn't have access to this information. - // We must get an approximation based on few, many, ... zounds etc. - int enemyStrength = 0; - - // TODO: should be virtual maybe, army strength should be - // comparable across objects. - // TODO: Rewrite all those damn i->o. For someone reading it the first - // time it's completely inconprehensible. - // TODO: NO MAGIC NUMBERS !!! - if (dynamic_cast (i->o)) - enemyStrength = (dynamic_cast (i->o))->getArmyStrength(); - if (dynamic_cast (i->o)) enemyStrength = (dynamic_cast (i->o))->getTotalStrength(); - // TODO: Make constants of those 1.2 & 2.5. - if (dynamic_cast (i->o)) - enemyStrength = static_cast((dynamic_cast (i->o))->getArmyStrength() * 1.2); - double heroStrength = h.h->getTotalStrength(); - // TODO: ballence these numbers using objective cost formula. - // TODO: it would be nice to do a battle simulation. - if (enemyStrength * 2.5 > heroStrength) - continue; - - if (enemyStrength > 0) - tp = AIObjective::attack; - } - - //don't visit things that have already been visited this week. - if ((dynamic_cast (i->o)) && - (dynamic_cast (i->o)->visited)) - continue; - - //don't visit things that you have already visited OPH - if ((dynamic_cast (i->o)) && - vstd::contains(dynamic_cast (i->o)->visitors, - h.h->id)) - continue; - - // TODO: Some descriptions of those included so someone can undestand them. - if (i->o->ID == 88 || i->o->ID == 89 || i->o->ID == 90) - { - //TODO: if no spell book continue - //TODO: if the shrine's spell is identified, and the hero already has it, continue - } - - destination = i->o->getSightCenter(); - - // Don't try to take a path from the underworld to the top or vice versa. - // TODO: Will have to make some calculations so that the AI can enter the - // underground. - if (hpos.z == destination.z) - { - //TODO: fix get path so that it doesn't return a path unless z's are - // the same, or path goes through sub gate. - if (m_cb->getPath(hpos, destination, h.h, path)) - { - path.convert(0); - if (path.nodes[0].dist < movement) - { - // TODO: So easy to understand... - HeroObjective ho(hgs, tp, i->o, &h, this); - std::set::iterator found = currentHeroObjectives.find(ho); - if (found == currentHeroObjectives.end()) - currentHeroObjectives.insert(ho); - else - { - // TODO: Try to rewrite if possible... - // A cast to a pointer, from a reference, to a pointer - // of an iterator. - HeroObjective* objective = (HeroObjective*)&(*found); - objective->whoCanAchieve.push_back(&h); - } - } - - // Find the most interesting object that is eventually reachable, - // and set that position to the ultimate goal position. - // TODO: replace random numbers with some sort of ranking system. - int hi = rand(); - if (hi > maxInteresting) - { - maxInteresting = hi; - interestingPos = destination; - } - } // if (m_cb->getPath(hpos, destination, h.h, path)) - } // if (hpos.z == destination.z) - } // for (std::set::const_iterator - // i = knownVisitableObjects.begin(); - - h.interestingPos = interestingPos; - // there ought to be a path - // if(h.remainingMovement>0&&m_cb->getPath(hpos,interestingPos,h.h,path)) - currentHeroObjectives.insert(HeroObjective(hgs, - HeroObjective::finishTurn, - h.h, - &h, - this)); -} - - -void CGeniusAI::HeroObjective::fulfill(CGeniusAI& cg, HypotheticalGameState& hgs) -{ - cg.m_cb->waitTillRealize = true; - HypotheticalGameState::HeroModel* h = NULL; - int3 hpos; - int3 destination; - int3 bestPos; - int3 currentPos; - int3 checkPos; - CPath path; - CPath path2; - int howGood = 0; - - switch (type) - { - case finishTurn: - h = whoCanAchieve.front(); - h->finished=true; - hpos = h->pos; - destination = h->interestingPos; - - if (!cg.m_cb->getPath(hpos, destination, h->h, path)) - { - tlog6 << "AI error: invalid destination" << endl; - return; - } - destination = h->pos; - // Find closest coord that we can get to. - for (int i = path.nodes.size() - 2; i >= 0; i--) - { - // TODO: getPath what?? - if ((cg.m_cb->getPath(hpos, path.nodes[i].coord, h->h, path2)) && (path2.nodes[0].dist <= h->remainingMovement)) - destination = path.nodes[i].coord; - } - - if (destination == h->interestingPos) - break; - - // ! START ! // - // Find close pos with the most neighboring empty squares. We don't want to - // get in the way. - bestPos = destination; - howGood = 0; - // TODO: Add a meaning to 3. - for (int x = -3; x <= 3; x++) - { - for (int y = -3; y <= 3; y++) - { - currentPos = destination + int3(x,y,0); - // There better not be anything there. - if (cg.m_cb->getVisitableObjs(currentPos).size() != 0) - continue; - if ((cg.m_cb->getPath(hpos, currentPos, h->h, path) == false) || - // It better be reachable from the hero - // TODO: remainingMovement > 0... - (path.nodes[0].dist>h->remainingMovement)) - continue; - - int count = 0; - int yy; - for (int xx = -1; xx <= 1; ++xx) - { - for (yy = -1; yy <= 1; ++yy) - { - checkPos = currentPos + int3(xx, yy, 0); - if (cg.m_cb->getPath(currentPos, checkPos, h->h, path) != false) - ++count; - } - } - if (count > howGood) - { - howGood = count; - bestPos = currentPos; - } - } - } - - destination = bestPos; - // ! END ! // - cg.m_cb->getPath(hpos, destination, h->h, path); - path.convert(0); - break; - - case visit: - case attack: - h = whoCanAchieve.front(); //lowest cost hero - h->previouslyVisited_pos = object->getSightCenter(); - hpos = h->pos; - destination = object->getSightCenter(); - break; - } // switch(type) - - if ((type == visit || type == finishTurn || type == attack) && (cg.m_cb->getPath (hpos, destination, h->h, path))) - path.convert(0); - - if (cg.m_state.get() != NO_BATTLE) - cg.m_state.waitUntil (NO_BATTLE); // Wait for battle end - - // Wait over, battle over too. hero might be killed. check. - for (int i = path.nodes.size() - 2; (i >= 0) && (cg.m_cb->getHeroSerial(h->h) >= 0); --i) - { - if (!cg.m_cb->moveHero(h->h,path.nodes[i].coord)); - { - tlog3 << "cannot move hero to " << path.nodes[i].coord << endl; - break; - } - - if (cg.m_state.get() != NO_BATTLE) - cg.m_state.waitUntil(NO_BATTLE); // Wait for battle end - } - - h->remainingMovement -= path.nodes[0].dist; - if (object->blockVisit) - h->pos = path.nodes[1].coord; - else - h->pos = destination; - - std::set::iterator - i = hgs.knownVisitableObjects.find(AIObjectContainer(object)); - if (i != hgs.knownVisitableObjects.end()) - hgs.knownVisitableObjects.erase(i); - - const CGTownInstance* town = dynamic_cast (object); - if (town && object->getOwner() == cg.m_cb->getMyColor()) - { - //upgrade hero's units - tlog6 << "visiting town" << endl; - for (TSlots::const_iterator i = h->h->Slots().begin(); i != h->h->Slots().end(); i++) - { // For each hero slot. - UpgradeInfo ui; - cg.m_cb->getUpgradeInfo(h->h,i->first, ui); - - bool canUpgrade = false; - if (ui.newID.size() != 0) - { // Does this stack need upgrading? - canUpgrade = true; - std::set >::iterator j; - for (int ii = 0; ii < ui.cost.size(); ii++) // Can afford the upgrade? - { -// for (j = ui.cost[ii].begin(); j != ui.cost[ii].end(); j++) -// if (hgs.resourceAmounts[j->first] < j->second * i->second->count) -// canUpgrade = false; - } - } - if (canUpgrade) - { - cg.m_cb->upgradeCreature(h->h, i->first, ui.newID.back()); - tlog6 << "upgrading hero's " - << i->second->type->namePl - << endl; - } - } - - // Give town's units to hero. - int weakestCreatureStack; - int weakestCreatureAIValue = 99999; // we will lower it in the process - - for (TSlots::const_iterator i = town->Slots().begin(); i != town->Slots().end(); i++) - { - if (i->second->type->AIValue < weakestCreatureAIValue) - { - weakestCreatureAIValue = i->second->type->AIValue; - weakestCreatureStack = i->first; - } - } - for (TSlots::const_iterator i = town->Slots().begin(); i != town->Slots().end(); i++)\ - { // For each town slot. - int hSlot = h->h->getSlotFor(i->second->type->idNumber); - - if (hSlot == -1) - continue; - tlog6 << "giving hero " << i->second->type->namePl << endl; - if (!h->h->slotEmpty(hSlot)) - { - // Can't take garrisonHero's last unit. - if ( (i->first == weakestCreatureStack) && (town->garrisonHero != NULL) ) - cg.m_cb->splitStack(town, h->h, i->first, hSlot, i->second->count - 1); - else - // TODO: the comment says that this code is not safe for the AI. - cg.m_cb->mergeStacks(town, h->h, i->first, hSlot); - } - else - cg.m_cb->swapCreatures(town, h->h, i->first, hSlot); - } // for (std::map< si32, std::pair >::const_iterator ... - } // if (town && object->getOwner == cg.m_cb->getMyColor()) -} - - -void CGeniusAI::addTownObjectives (HypotheticalGameState::TownModel& t, HypotheticalGameState& hgs) -{ - //recruitHero - //buildBuilding - //recruitCreatures - //upgradeCreatures - - // Recruit hero. - if ( (hgs.heroModels.size() < 3) && (hgs.resourceAmounts[6] >= 2500) ) - { - bool heroAtTown = false; - for (int i = 0; i < hgs.heroModels.size(); i++) - { - if (hgs.heroModels[i].pos == t.t->getSightCenter()) - heroAtTown = true; - } - // No visiting hero and built tavern. - if (!heroAtTown && vstd::contains(t.t->builtBuildings, 5)) - { - for (int i = 0; i < hgs.AvailableHeroesToBuy.size(); i++) - { - if ( (hgs.AvailableHeroesToBuy[i] != NULL) && (t.t->subID == hgs.AvailableHeroesToBuy[i]->type->heroType / 2) ) - { - TownObjective to(hgs,AIObjective::recruitHero, &t, 0, this); - currentTownObjectives.insert(to); - } - } - } - } - - // Build a building. - if (!t.hasBuilt) - { - // m_cb->getCBuildingsByID(t.t); - bmap > thisTownsBuildings = VLC->buildh->buildings[t.t->subID]; - for (bmap >::iterator i = thisTownsBuildings.begin(); i != thisTownsBuildings.end(); i++) - { - if (m_cb->canBuildStructure(t.t, i->first) == 7) - { - TownObjective to(hgs, AIObjective::buildBuilding, &t, i->first ,this); - currentTownObjectives.insert(to); - } - } - } - - // Recruit creatures. - for (int i = 0; i < t.creaturesToRecruit.size(); i++) - { - if (t.creaturesToRecruit[i].first == 0 || t.creaturesToRecruit[i].second.empty()) - continue; - - int ID = t.creaturesToRecruit[i].second.back(); - // m_cb->getCCreatureByID(ID); - const CCreature *creature = VLC->creh->creatures[ID]; - bool canAfford = true; - for (int ii = 0; ii < creature->cost.size(); ii++) - { - if (creature->cost[ii] > hgs.resourceAmounts[ii]) - canAfford = false; // Can we afford at least one creature? - } - if (!canAfford) - continue; - - //tlog6 << "town has " << t.t->creatures[i]->first << " "<< creature->namePl << " (AI Strength " << creature->AIValue << ")." << endl; - TownObjective to(hgs, AIObjective::recruitCreatures, &t, i, this); - currentTownObjectives.insert(to); - } - - // Upgrade creatures. - for (TSlots::const_iterator i = t.t->Slots().begin(); i != t.t->Slots().end(); i++) - { - UpgradeInfo ui; - m_cb->getUpgradeInfo(t.t, i->first, ui); - if (ui.newID.size()) - { - bool canAfford = true; - - int upgrade_serial = ui.newID.size() - 1; -// for (std::set< std::pair >::iterator j = ui.cost[upgrade_serial].begin(); j != ui.cost[upgrade_serial].end(); j++) -// { -// if (hgs.resourceAmounts[j->first] < j->second * i->second->count) -// canAfford = false; -// } - if (canAfford) - { - TownObjective to(hgs,AIObjective::upgradeCreatures,&t,i->first,this); - currentTownObjectives.insert(to); - } - } // if (ui.netID.size() != 0) - } // for (std::map< si32, std::pair ... -} - - -void CGeniusAI::TownObjective::fulfill(CGeniusAI& cg, - HypotheticalGameState& hgs) -{ - cg.m_cb->waitTillRealize = true; - CBuilding * b; - const CCreature *creature; - HypotheticalGameState::HeroModel hm; - int ID, howMany, newID, hSlot; - - switch (type) - { - case recruitHero: - cg.m_cb->recruitHero(whichTown->t, hgs.AvailableHeroesToBuy[which]); - hm = HypotheticalGameState::HeroModel(hgs.AvailableHeroesToBuy[which]); - hm.pos = whichTown->t->getSightCenter(); - hm.remainingMovement = hm.h->maxMovePoints(true); - hgs.heroModels.push_back(hm); - hgs.resourceAmounts[6] -= 2500; - break; - - case buildBuilding: - b = VLC->buildh->buildings[whichTown->t->subID][which]; - if (cg.m_cb->canBuildStructure(whichTown->t,which) == 7) - { - tlog6 << "built " << b->Name() << "." << endl; - if (!cg.m_cb->buildBuilding(whichTown->t, which)) - tlog6 << "really tried to build unbuildable building" << endl; - - for (int i = 0; b && i < b->resources.size(); i++) // use only when certain building was found - hgs.resourceAmounts[i] -= b->resources[i]; - } else - tlog6 << "trying to build a structure we cannot build" << endl; - whichTown->hasBuilt=true; - break; - - case recruitCreatures: - // Buy upgraded if possible. - ID = whichTown->creaturesToRecruit[which].second.back(); - creature = VLC->creh->creatures[ID]; - howMany = whichTown->creaturesToRecruit[which].first; - for (int i = 0; i < creature->cost.size(); i++) - vstd::amin(howMany, creature->cost[i] ? hgs.resourceAmounts[i]/creature->cost[i] : INT_MAX); - if (howMany == 0) - { - tlog6 << "tried to recruit without enough money."; - tlog6 << "recruiting " << howMany << " " - << creature->namePl << " (Total AI Strength " - << creature->AIValue*howMany << ")." << endl; - cg.m_cb->recruitCreatures(whichTown->t, ID, howMany); - } - break; - - case upgradeCreatures: - UpgradeInfo ui; - cg.m_cb->getUpgradeInfo(whichTown->t, which, ui); - ID = whichTown->t->getCreature(which)->idNumber; - newID = ui.newID.back(); - // TODO: reduce resources in hgs - cg.m_cb->upgradeCreature(whichTown->t, which, newID); - tlog6 << "upgrading " << VLC->creh->creatures[ID]->namePl << endl; - break; - } -} - - -void CGeniusAI::fillObjectiveQueue(HypotheticalGameState & hgs) -{ - objectiveQueue.clear(); - currentHeroObjectives.clear(); - currentTownObjectives.clear(); - - for (std::vector ::iterator i = hgs.heroModels.begin(); i != hgs.heroModels.end(); i++) - addHeroObjectives(*i, hgs); - - for (std::vector ::iterator i = hgs.townModels.begin(); i != hgs.townModels.end(); i++) - addTownObjectives(*i, hgs); - - for (std::set::iterator i = currentHeroObjectives.begin(); i != currentHeroObjectives.end(); i++) - // TODO: Recheck and try to write simpler expression. - objectiveQueue.push_back(AIObjectivePtrCont((CGeniusAI::HeroObjective*)&(*i))); - - for (std::set::iterator i = currentTownObjectives.begin(); i != currentTownObjectives.end(); i++) - objectiveQueue.push_back(AIObjectivePtrCont((CGeniusAI::TownObjective*)&(*i))); -} - - -CGeniusAI::AIObjective * CGeniusAI::getBestObjective() -{ - trueGameState.update(*this); - fillObjectiveQueue(trueGameState); - -// TODO: Write this part. -// if(objectiveQueue.size()) -// return max_element(objectiveQueue.begin(),objectiveQueue.end())->obj; - m_priorities->fillFeatures(trueGameState); - if (objectiveQueue.empty()) - return NULL; -// sort(objectiveQueue.begin(),objectiveQueue.end()); -// reverse(objectiveQueue.begin(),objectiveQueue.end()); - int num = 1; -// for(std::vector ::iterator i = objectiveQueue.begin(); i < objectiveQueue.end();i++) -// { -// if(!dynamic_cast(i->obj)) - // continue; -// tlog6 << num++ << ": "; -// i->obj->print(); -// tlog6 << " value: " << i->obj->getValue(); -// tlog6 << endl; -// } -// int choice = 0; -// tlog6 << "which would you do? (enter 0 for none): "; -// cin >> choice; - tlog6 << "doing best of " << objectiveQueue.size() << ": "; - CGeniusAI::AIObjective* best = max_element(objectiveQueue.begin(), objectiveQueue.end())->obj; - best->print(); - tlog6 << " value = " << best->getValue() << endl; - - if (objectiveQueue.size()) - return best; - return objectiveQueue.front().obj; -} - - -void CGeniusAI::yourTurn() -{ - static boost::mutex mutex; - boost::mutex::scoped_lock lock(mutex); - m_cb->waitTillRealize = false; - static int seed = rand(); - srand(seed); - - if (VLC->IS_AI_ENABLED) - { - m_cb->waitTillRealize = true; - // if (m_cb->getDate() == 1) - //{ - // startFirstTurn(); - // - // m_cb->endTurn(); - // return; - // } - //////////////TODO: replace with updates. Also add suspected objects list.///////// - knownVisitableObjects.clear(); - int3 pos = m_cb->getMapSize(); - int y, z; //don't reallocate them unnecessarily - for (int x = 0; x < pos.x; ++x) - { - for (y = 0; y < pos.y; ++y) - { - for (z = 0; z < pos.z; ++z) - tileRevealed(int3(x,y,z)); - } - } - /////////////////////////////////////////////////////////////////////////////////// - - reportResources(); - - trueGameState = HypotheticalGameState(*this); - AIObjective * objective = getBestObjective(); - if (objective) //single so far, TODO: restore while - objective->fulfill(*this,trueGameState); - seed = rand(); - } - m_cb->endTurn(); - m_cb->waitTillRealize = false; -} - - -void CGeniusAI::startFirstTurn() -{ - HypotheticalGameState hgs(*this); - - const CGTownInstance * town = m_cb->getTownBySerial(0); - const CGHeroInstance * heroInst = m_cb->getHeroBySerial(0); - - TownObjective(hgs, AIObjective::recruitHero, &hgs.townModels.front(), 0, this).fulfill(*this, hgs); - - m_cb->swapGarrisonHero(town); - hgs.update(*this); - for (ui32 i = 0; i < hgs.townModels.front().creaturesToRecruit.size(); ++i) - { - if (hgs.townModels.front().creaturesToRecruit[i].first == 0) - continue; - int ID = hgs.townModels.front().creaturesToRecruit[i].second.back(); - const CCreature *creature = VLC->creh->creatures[ID]; - - bool canAfford = true; - for (ui32 ii = 0; ii < creature->cost.size(); ii++) - { - if (creature->cost[ii] > hgs.resourceAmounts[ii]) - canAfford = false; // Can we afford at least one creature? - } - if (!canAfford) - continue; - - TownObjective(hgs,AIObjective::recruitCreatures,&hgs.townModels.front(),i,this).fulfill(*this,hgs); - } - hgs.update(*this); - - HypotheticalGameState::HeroModel* hero; - for (int i = 0; i < hgs.heroModels.size(); i++) - { - if (hgs.heroModels[i].h->id == heroInst->id) - HeroObjective(hgs, AIObjective::visit, town, hero = &hgs.heroModels[i], this).fulfill(*this,hgs); - } - hgs.update(*this); - // m_cb->swapGarrisonHero(town); - //TODO: choose the strongest hero. -} - - -void CGeniusAI::heroKilled(const CGHeroInstance* hero) -{ -} - - -void CGeniusAI::heroCreated(const CGHeroInstance* hero) -{ -} - - -void CGeniusAI::tileRevealed(int3 pos) -{ - std::vector objects = m_cb->getVisitableObjs(pos); - for (std::vector ::iterator o = objects.begin(); o != objects.end(); o++) - { - if ((*o)->id != -1) - knownVisitableObjects.insert(*o); - } - objects = m_cb->getFlaggableObjects(pos); - for (std::vector::iterator o = objects.begin(); o != objects.end(); o++) - if ((*o)->id != -1) - knownVisitableObjects.insert(*o); -} - -// eg. ship built in shipyard -void CGeniusAI::newObject(const CGObjectInstance* obj) -{ - knownVisitableObjects.insert(obj); -} - - -void CGeniusAI::objectRemoved(const CGObjectInstance *obj) //eg. collected resource, picked artifact, beaten hero -{ - std::set::iterator o = knownVisitableObjects.find(obj); - if (o != knownVisitableObjects.end()) - knownVisitableObjects.erase(o); -} - - -void CGeniusAI::tileHidden(int3 pos) -{ -} - - -void CGeniusAI::heroMoved(const TryMoveHero& TMH) -{ - // DbgBox("** CGeniusAI::heroMoved **"); -} - - -void CGeniusAI::heroGotLevel(const CGHeroInstance *hero, - int pskill, - std::vector& skills, - boost::function& callback) -{ - callback(rand() % skills.size()); -} - - -void geniusai::CGeniusAI::showGarrisonDialog(const CArmedInstance* up, - const CGHeroInstance* down, - bool removableUnits, - boost::function& onEnd) -{ - onEnd(); -} - - -void geniusai::CGeniusAI::playerBlocked(int reason) -{ - if (reason == 0) // Battle is coming... - m_state.setn(UPCOMING_BATTLE); -} - - -void geniusai::CGeniusAI::battleResultsApplied() -{ - assert(m_state.get() == ENDING_BATTLE); - m_state.setn(NO_BATTLE); -} - -// TODO: Shouldn't the parameters be made const (apart from cancel)? -void CGeniusAI::showBlockingDialog(const std::string& text, - const std::vector &components, - ui32 askID, - const int soundID, - bool selection, - bool cancel) -{ - m_cb->selectionMade(cancel ? false : true, askID); -} - - -/** - * occurs AFTER every action taken by any stack or by the hero - */ -void CGeniusAI::actionFinished(const BattleAction* action) -{ - std::string message("\t\tCGeniusAI::actionFinished - type("); - message += boost::lexical_cast((unsigned)action->actionType); - message += "), side("; - message += boost::lexical_cast((unsigned)action->side); - message += ")"; - DbgBox(message.c_str()); -} - - -/** - * occurs BEFORE every action taken by any stack or by the hero - */ -void CGeniusAI::actionStarted(const BattleAction *action) -{ - std::string message("\t\tCGeniusAI::actionStarted - type("); - message += boost::lexical_cast((unsigned)action->actionType); - message += "), side("; - message += boost::lexical_cast((unsigned)action->side); - message += ")"; - DbgBox(message.c_str()); -} - - -/** - * called when stack is performing attack - */ -void CGeniusAI::battleAttack(const BattleAttack* ba) -{ - DbgBox("\t\t\tCGeniusAI::battleAttack"); -} - - -/** - * called when stack receives damage (after battleAttack()) - */ -void CGeniusAI::battleStacksAttacked(const std::set& bsa) -{ - DbgBox("\t\t\tCGeniusAI::battleStacksAttacked"); -} - - -/** - * called by engine when battle starts; side=0 - left, side=1 - right - */ -void CGeniusAI::battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side) -{ - // TODO: Battle logic what... - assert(!m_battleLogic); - // We have been informed that battle will start (or we are neutral AI) - assert( (playerID > GameConstants::PLAYER_LIMIT) || (m_state.get() == UPCOMING_BATTLE) ); - - m_state.setn(ONGOING_BATTLE); - m_battleLogic = new BattleAI::CBattleLogic(m_cb, army1, army2, tile, hero1, - hero2, side); - - DbgBox("** CGeniusAI::battleStart **"); -} - - -/** - * - */ -void CGeniusAI::battleEnd(const BattleResult* br) -{ - switch (br->winner) - { - case 0: tlog6 << "The winner is the attacker." << std::endl; break; - case 1: tlog6 << "The winner is the defender." << std::endl; break; - case 2: tlog6 << "It's a draw." << std::endl; break; - }; - tlog6 << "lost "; - for (std::map::const_iterator i = br->casualties[0].begin(); i != br->casualties[0].end(); i++) - tlog6 << i->second << " " << VLC->creh->creatures[i->first]->namePl << endl; - - delete m_battleLogic; - m_battleLogic = NULL; - - assert(m_state.get() == ONGOING_BATTLE); - m_state.setn(ENDING_BATTLE); - - DbgBox("** CGeniusAI::battleEnd **"); -} - -/* - * Called at the beggining of each turn, round = -1 is the tactic phase, - * round = 0 is the first "normal" turn. - */ -void CGeniusAI::battleNewRound(int round) -{ - std::string message("\tCGeniusAI::battleNewRound - "); - message += boost::lexical_cast(round); - DbgBox(message.c_str()); - - m_battleLogic->SetCurrentTurn(round); -} - -/** - * - */ -void CGeniusAI::battleStackMoved(int ID, std::vector dest, int distance) -{ - std::string message("\t\t\tCGeniusAI::battleStackMoved ID("); - message += boost::lexical_cast(ID); - message += "), dest("; - message += boost::lexical_cast(dest.size()); - message += ")"; - DbgBox(message.c_str()); -} - - -/** - * - */ -void CGeniusAI::battleSpellCast(const BattleSpellCast *sc) -{ - DbgBox("\t\t\tCGeniusAI::battleSpellCast"); -} - - -/** - * called when battlefield is prepared, prior the battle beginning - */ -// void CGeniusAI::battlefieldPrepared(int battlefieldType, -// std::vector obstacles) -// { -// DbgBox("CGeniusAI::battlefieldPrepared"); -// } - - -/** - * - */ -// void CGeniusAI::battleStackMoved(int ID, -// BattleHex dest, -// bool startMoving, -// bool endMoving) -// { -// DbgBox("\t\t\tCGeniusAI::battleStackMoved"); -// } - - - -/** - * - */ -void CGeniusAI::battleStackIsAttacked(int ID, - int dmg, - int killed, - int IDby, - bool byShooting) -{ - DbgBox("\t\t\tCGeniusAI::battleStackIsAttacked"); -} - - -/** - * called when it's turn of that stack - */ -BattleAction CGeniusAI::activeStack(const CStack * stack) -{ - std::string message("\t\t\tCGeniusAI::activeStack stackID("); - - message += boost::lexical_cast(stack->ID); - message += ")"; - DbgBox(message.c_str()); - - return BattleAction::makeDefend(stack); -// -// BattleAction bact = m_battleLogic->MakeDecision(stack->ID); -// assert(m_cb->battleGetStackByID(bact.stackNumber)); -// return bact; -} - - -//WTF?!? why is this needed?!?!?! -BattleAction CGlobalAI::activeStack( const CStack * stack ) -{ - BattleAction ba; ba.actionType = BattleAction::DEFEND; - ba.stackNumber = stack->ID; - return ba; -} - diff --git a/AI/GeniusAI/CGeniusAI.h b/AI/GeniusAI/CGeniusAI.h deleted file mode 100644 index 9308997c7..000000000 --- a/AI/GeniusAI/CGeniusAI.h +++ /dev/null @@ -1,215 +0,0 @@ -#pragma once - -#include "Common.h" -#include "BattleLogic.h" -#include "GeneralAI.h" -#include "../../lib/CondSh.h" - -class CBuilding; - -namespace geniusai { - -enum BattleState -{ - NO_BATTLE, - UPCOMING_BATTLE, - ONGOING_BATTLE, - ENDING_BATTLE -}; - - -class Priorities; - -class CGeniusAI : public CGlobalAI -{ -private: - // TODO: cb... come back, croach busters!? - CCallback* m_cb; - geniusai::BattleAI::CBattleLogic* m_battleLogic; - geniusai::GeneralAI::CGeneralAI m_generalAI; - geniusai::Priorities* m_priorities; - - CondSh m_state; //are we engaged into battle? - - struct AIObjectContainer - { - AIObjectContainer(const CGObjectInstance * o):o(o){} - const CGObjectInstance * o; - bool operator<(const AIObjectContainer& b)const; - }; - - class HypotheticalGameState - { - public: - struct HeroModel - { - HeroModel(){} - HeroModel(const CGHeroInstance * h); - int3 pos; - int3 previouslyVisited_pos; - int3 interestingPos; - bool finished; - int remainingMovement; - const CGHeroInstance * h; - }; - struct TownModel - { - TownModel(const CGTownInstance *t); - const CGTownInstance *t; - std::vector > > creaturesToRecruit; - //CCreatureSet creaturesInGarrison; //type, num - bool hasBuilt; - }; - HypotheticalGameState(){} - HypotheticalGameState(CGeniusAI & ai); - - void update(CGeniusAI & ai); - CGeniusAI * AI; - std::vector AvailableHeroesToBuy; - std::vector resourceAmounts; - std::vector heroModels; - std::vector townModels; - std::set< AIObjectContainer > knownVisitableObjects; - }; - - class AIObjective - { - public: - enum Type - { - //hero objectives - visit, //done TODO: upon visit friendly hero, trade - attack, //done - //flee, - dismissUnits, - dismissYourself, - rearangeTroops, - finishTurn, //done //uses up remaining motion to get somewhere interesting. - - //town objectives - recruitHero, //done - buildBuilding, //done - recruitCreatures, //done - upgradeCreatures //done - }; - CGeniusAI * AI; - Type type; - virtual void fulfill(CGeniusAI &,HypotheticalGameState & hgs)=0; - virtual HypotheticalGameState pretend(const HypotheticalGameState&) =0; - virtual void print() const=0; - virtual double getValue() const=0; //how much is it worth to the AI to achieve - }; - - class HeroObjective: public AIObjective - { - public: - HypotheticalGameState hgs; - int3 pos; - const CGObjectInstance * object; //interactive object - mutable std::vector whoCanAchieve; - - //HeroObjective(){} - //HeroObjective(Type t):object(NULL){type = t;} - HeroObjective(const HypotheticalGameState &hgs, - Type t, - const CGObjectInstance* object, - HypotheticalGameState::HeroModel* h, - CGeniusAI* AI); - bool operator< (const HeroObjective &other) const; - void fulfill(CGeniusAI &,HypotheticalGameState & hgs); - HypotheticalGameState pretend(const HypotheticalGameState &hgs){return hgs;}; - double getValue() const; - void print() const; - private: - mutable double _value; - mutable double _cost; - }; - - //town objectives - //recruitHero - //buildBuilding - //recruitCreatures - //upgradeCreatures - - class TownObjective: public AIObjective - { - public: - HypotheticalGameState hgs; - HypotheticalGameState::TownModel * whichTown; - int which; //which hero, which building, which creature, - - TownObjective(const HypotheticalGameState &hgs,Type t,HypotheticalGameState::TownModel * tn,int Which,CGeniusAI * AI); - - bool operator < (const TownObjective &other)const; - void fulfill(CGeniusAI &,HypotheticalGameState & hgs); - HypotheticalGameState pretend(const HypotheticalGameState &hgs){return hgs;}; - double getValue() const; - void print() const; - private: - mutable double _value; - mutable double _cost; - }; - - class AIObjectivePtrCont - { - public: - AIObjectivePtrCont():obj(NULL){} - AIObjectivePtrCont(AIObjective * obj):obj(obj){}; - AIObjective * obj; - bool operator < (const AIObjectivePtrCont & other) const{return obj->getValue()getValue();} - }; - HypotheticalGameState trueGameState; - AIObjective * getBestObjective(); - void addHeroObjectives(HypotheticalGameState::HeroModel &h, HypotheticalGameState & hgs); - void addTownObjectives(HypotheticalGameState::TownModel &h, HypotheticalGameState & hgs); - void fillObjectiveQueue(HypotheticalGameState & hgs); - - void reportResources(); - void startFirstTurn(); - std::map isHeroStrong;//hero - std::set< AIObjectContainer > knownVisitableObjects; - std::set currentHeroObjectives; //can be fulfilled right now - std::set currentTownObjectives; - std::vector objectiveQueue; - -public: - CGeniusAI(); - virtual ~CGeniusAI(); - - virtual void init(CCallback * CB); - virtual void yourTurn(); - virtual void heroKilled(const CGHeroInstance *); - virtual void heroCreated(const CGHeroInstance *); - virtual void heroMoved(const TryMoveHero &); - virtual void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) {}; - virtual void showSelDialog(std::string text, std::vector & components, int askID){}; - virtual void showBlockingDialog(const std::string &text, const std::vector &components, ui32 askID, const int soundID, bool selection, bool cancel); //Show a dialog, player must take decision. If selection then he has to choose between one of given components, if cancel he is allowed to not choose. After making choice, CCallback::selectionMade should be called with number of selected component (1 - n) or 0 for cancel (if allowed) and askID. - virtual void tileRevealed(int3 pos); - virtual void tileHidden(int3 pos); - virtual void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector &skills, boost::function &callback); - virtual void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function &onEnd); - virtual void playerBlocked(int reason); - - virtual void objectRemoved(const CGObjectInstance *obj); //eg. collected resource, picked artifact, beaten hero - virtual void newObject(const CGObjectInstance * obj); //eg. ship built in shipyard - - - // battle - virtual void actionFinished(const BattleAction *action);//occurs AFTER every action taken by any stack or by the hero - virtual void actionStarted(const BattleAction *action);//occurs BEFORE every action taken by any stack or by the hero - virtual void battleAttack(const BattleAttack *ba); //called when stack is performing attack - virtual void battleStacksAttacked(const std::set & bsa); //called when stack receives damage (after battleAttack()) - virtual void battleEnd(const BattleResult *br); - virtual void battleNewRound(int round); //called at the beggining of each turn, round=-1 is the tactic phase, round=0 is the first "normal" turn - virtual void battleStackMoved(int ID, std::vector dest, int distance); - virtual void battleSpellCast(const BattleSpellCast *sc); - virtual void battleStart(const CCreatureSet *army1, const CCreatureSet *army2, int3 tile, const CGHeroInstance *hero1, const CGHeroInstance *hero2, bool side); //called by engine when battle starts; side=0 - left, side=1 - right - //virtual void battlefieldPrepared(int battlefieldType, std::vector obstacles); //called when battlefield is prepared, prior the battle beginning - // - //virtual void battleStackMoved(int ID, int dest, bool startMoving, bool endMoving); - virtual void battleStackIsAttacked(int ID, int dmg, int killed, int IDby, bool byShooting); - virtual BattleAction activeStack(const CStack * stack); - void battleResultsApplied(); - friend class Priorities; -}; -} \ No newline at end of file diff --git a/AI/GeniusAI/Common.h b/AI/GeniusAI/Common.h deleted file mode 100644 index bf669cb51..000000000 --- a/AI/GeniusAI/Common.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#ifdef __GNUC__ -#define strcpy_s(a, b, c) strncpy(a, c, b) -#endif - -#pragma warning (disable: 4100 4244) -#include "../../lib/AI_Base.h" -#pragma warning (default: 4100 4244) - -void DbgBox(const char *msg, bool messageBox = false); \ No newline at end of file diff --git a/AI/GeniusAI/DLLMain.cpp b/AI/GeniusAI/DLLMain.cpp deleted file mode 100644 index da73785dc..000000000 --- a/AI/GeniusAI/DLLMain.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include "StdInc.h" -#include "../../lib/AI_Base.h" -#include "CGeniusAI.h" - -using namespace geniusai; - -const char *g_cszAiName = "Genius 1.0"; - -extern "C" DLL_EXPORT int GetGlobalAiVersion() -{ - return AI_INTERFACE_VER; -} - -extern "C" DLL_EXPORT void GetAiName(char* name) -{ - strcpy_s(name, strlen(g_cszAiName) + 1, g_cszAiName); -} - -extern "C" DLL_EXPORT char* GetAiNameS() -{ - // need to be defined - return NULL; -} - -extern "C" DLL_EXPORT CGlobalAI* GetNewAI() -{ - return new CGeniusAI(); -} - -extern "C" DLL_EXPORT void ReleaseAI(CGlobalAI* i) -{ - delete (CGeniusAI*)i; -} - -extern "C" DLL_EXPORT CBattleGameInterface* GetNewBattleAI() -{ - return new CGeniusAI(); -} \ No newline at end of file diff --git a/AI/GeniusAI/ExpertSystem.cpp b/AI/GeniusAI/ExpertSystem.cpp deleted file mode 100644 index 8fe840eb3..000000000 --- a/AI/GeniusAI/ExpertSystem.cpp +++ /dev/null @@ -1,143 +0,0 @@ -#include "StdInc.h" -#include "GeneralAI.h" -#include "../../CCallback.h" -#include "ExpertSystem.h" - -/* - * ExpertSystem.cpp, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ - -template template void ExpertSystemShell::DataDrivenReasoning(runType type) -{ - std::vector::iterator ir; - std::list::iterator iF; - std::vector>::iterator ic; - bool factWasAdded = false; //carry it over inner loop - switch (type) - { - case ANY_GOAL: //first produced decision ends reasoning - { - int goalCounter = 0; - while(!goalCounter) //we reach goal or can't modify knowledge anymore - { - for (ir = knowledge.begin(); ir != knowledge.end(); ir++) - { - for (iF = factList.begin(); iF != factList.end(); iF++) - { - for (ic = ir->conditions.begin(); ic != ir->conditions.end(), ic++) - { - if (ic->first.object.matchesFact(iF->object)) //condition matches held object - { - (ic->second = *iF); - ++(ir->conditionCounter); - } - } - if (ir->conditions.size() >= ir->conditionCounter()); - { - ir->fireRule(); //all conditions matched - ir->conditionCounter = 0; //do it here or in rule itself? - if (dynamic_cast<&Goal>(*ir)) - ++goalCounter; - } - } - //modify set until something happens (hopefully!) - for (iF = factsToAdd.begin(); iF != factsToAdd.end(); iF++) - factList.insert(*iF); - if (factsToAdd.size()) - { - factsToAdd.clear(); - factWasAdded = true; - } - } - for (iF = factsToErase.begin(); iF != factsToErase.end(); iF++) //remove facts discarded in this run - factList.erase(knowledge.find(*iF)); - factsToErase.clear(); //erase only after all rules had a chance to trigger - for (ir = rulesToErase.begin(); ir != rulesToErase.end(); ir++) - knowledge.erase(knowledge.find(*ir)); - rulesToErase.clear(); - for (ir = rulesToAdd.begin(); ir != rulesToAdd.end(); ir++) - knowledge.insert(*ir); - if (!(factWasAdded || rulesToAdd.size())) //we can't do anything more - break; - rulesToAdd.clear(); - }; - } - break; - } -} -void BonusRule::fireRule() -{ - for (std::vector>::iterator it = cons.begin(); it != cons.end(); it++) - { - switch (it->first.parameter) - { //compare fact with condition - case BonusCondition::type: - if (!it->first.functor(it->second->object->type, it->first.value)) return; - break; - case BonusCondition::subtype: //probably suprfluous, Selector already handles that - if (!it->first.functor(it->second->object->subtype, it->first.value)) return; - break; - case BonusCondition::val: - if (!it->first.functor(it->second->object->val, it->first.value)) return; - break; - case BonusCondition::duration: - if (!it->first.functor(it->second->object->duration, it->first.value)) return; - break; - case BonusCondition::source: //likely to handle by selector - if (!it->first.functor(it->second->object->source, it->first.value)) return; - break; - case BonusCondition::id: - if (!it->first.functor(it->second->object->sid, it->first.value)) return; - break; - case BonusCondition::valType: //ever needed? - if (!it->first.functor(it->second->object->valType, it->first.value)) return; - break; - case BonusCondition::additionalInfo: - if (!it->first.functor(it->second->object->additionalInfo, it->first.value)) return; - break; - case BonusCondition::effectRange: - if (!it->first.functor(it->second->object->effectRange, it->first.value)) return; - break; - default: //ignore or accept? - break; - }; - } - //TODO: add new fact or modify existing one -} - -TLogic operator&&(const TLogic &first, const TLogic &second) -{ - return LogicConjunction(first, second); -} -TLogic operator||(const TLogic &first, const TLogic &second) -{ - return LogicAlternative(first, second); -} -template void Rule::refreshRule(std::vector &conditionSet) -{//replace conditions with new vector - cons.clear(); - std::pair para; - para.second = NULL; - for (std::vector::iterator it = conditionSet.begin(); it != conditionSet.end(); it++) - { - para.first = *it; - cons.push_back(para); //pointer to condition and null fact - } -} -template void Rule::refreshRule() -{//clear matching facts - for (std::vector>::iterator it = cons.begin(); it != cons.end(); it++) - it->second = NULL; -} -bool BonusCondition::matchesFact(Bonus &fact) -{ - if (object(&fact)) //Bonus(fact) matches local Selector(object) - return true; - return false; -} \ No newline at end of file diff --git a/AI/GeniusAI/ExpertSystem.h b/AI/GeniusAI/ExpertSystem.h deleted file mode 100644 index a1b20aa7d..000000000 --- a/AI/GeniusAI/ExpertSystem.h +++ /dev/null @@ -1,215 +0,0 @@ - -#include "../../CCallback.h" -#include "../../lib/HeroBonus.h" -#include -#include -#include - -/* - * ExpertSystem.h, part of VCMI engine - * - * Authors: listed in file AUTHORS in main folder - * - * License: GNU General Public License v2.0 or later - * Full text of license available in license.txt file, in main folder - * - */ -struct Bonus; -template class AIholder; -template class Rule; -typedef Rule BRule; -typedef boost::function TLogic; -bool greaterThan (int prop, si32 val); - -enum conditionType {LESS_THAN, EQUAL, GREATER_THAN, UNEQUAL, PRESENT}; - -template class ExpertSystemShell -{ - enum runType {ANY_GOAL, TRESHOLD, FULL}; //Treshold - stop when received decision has high AI value -private: - ICallback* m_cb; -protected: - std::vector knowledge; - std::vector rulesToErase; - std::vector rulesToAdd; - std::vector factsToErase; - std::vector factsToAdd; - ui16 goalCounter; //count / evaluate achieved goals for runType -public: - ExpertSystemShell(){goalCounter = 0;}; - std::list facts; //facts are AIholders with actual game objects, for eg. "my bonus is worthless" - - template void getKnowledge(const t1 &a1){}; - void getNextRule(){}; - void addRule(ruleType &rule){rulesToAdd.insert(rule);}; - void removeRule(ruleType &rule){rulesToErase.insert(rule);}; - template void returnGoals(const t2 &a2){}; - template void DataDrivenReasoning(runType type); -}; -template class Blackboard : public ExpertSystemShell -//handle Bonus info coming from different sections of the game -{ -public: - Blackboard(){this->goalCounter = 0;}; //template magic, do not touch! - std::vector experts; //modules responsible for different tasks -}; - -template class condition -{//compares selected object parameter with value using functor. universal (?) logic handler -public: - input object; //what the fact is, or what it's like (CSelector) - si32 value; - ui8 parameter; - TLogic functor; //value of selected parameter, condition value - - condition(){object = NULL; value = 0; parameter = 0; functor = greaterThan;}; - - bool matchesFact(input &fact){return false;}; -}; - -template class Rule -{ -friend class ExpertSystemShell ; -public: - bool fired; //if conditions of rule were met and it produces some output - ui8 conditionCounter; -protected: - std::vector> cons; //conditions and matching facts - input decision; - virtual void canBeFired(); //if this data makes any sense for rule - type check - virtual bool checkCondition(); //if condition is true or false - virtual bool checkCondition(std::vector &feed); - virtual void fireRule(); //use paired conditions and facts by default - virtual void fireRule(ExpertSystemShell &system); - virtual void fireRule(std::vector &feed); - virtual void refreshRule(); - virtual void refreshRule(std::vector &conditionSet); //in case conditions were erased -public: - Rule(){fired = false; conditionCounter = 0; decision = NULL;}; - template bool matchesInput() //if condition and data match type - {return dynamic_cast(&givenInput);}; -}; - -template class Goal : public Rule -{ -protected: - boost::function decision(); //do something with AI eventually -public: - void fireRule(){}; -}; - -template class Weight : public Rule -{ -public: - double multiplier; //multiply input by value and return to output - void fireTule(){}; -}; - -template class AIholder -{ //stores certain condition and its temporal value -public: - si32 aiValue; - input *object; - - AIholder(){object = NULL; aiValue = 0;} - AIholder(input &o){object = o; aiValue = 0;} - AIholder(input &o, si32 val){object = 0; aiValue = val;} -}; - -class BonusSystemExpert : public ExpertSystemShell -{ //TODO: less templates? - enum effectType {POSITIVE=1, NEGATIVE=2, EXCLUDING=4, ENEMY=8, ALLY=16}; //what is the influence of bonus and for who -}; - -class BonusCondition : public condition //used to test rule -{ -public: - enum Parameter - { - type, subtype, val, duration, source, id, valType, additionalInfo, effectRange, limiter //? - }; - bool matchesFact(Bonus &fact); -}; - -class BonusHolder : public AIholder -{ -public: - BonusHolder(Bonus &bonus){object = &bonus; aiValue = bonus.val;} - BonusHolder(Bonus &bonus, si32 val){object = &bonus; aiValue = val;} -}; - -class BonusRule : public Rule -{ -protected: - void fireRule(); -}; - -inline bool greaterThan (int prop, si32 val) //does it make any sense to keep functors inline? -{ - if ((si32)prop > val) - return true; - return false; -} -inline bool lessThan (int prop, si32 val) -{ - if ((si32)prop < val) - return true; - return false; -} -inline bool eqal (int prop, si32 val) -{ - if ((si32)prop == val) - return true; - return false; -} -inline bool unequal (int prop, si32 val) -{ - if ((si32)prop != val) - return true; - return false; -} -inline bool present (int prop, si32 val=0) -//inline bool present (int prop) //TODO: can we use function with less arguments? -{ - return(prop); //unfixable warning :( -} - -class LogicConjunction -{ - const TLogic first, second; //TODO: universal argument list of functions? -public: - LogicConjunction(const TLogic First, const TLogic Second) - :first(First), second(Second) - { - } - bool operator()(int prop, si32 val) const - { - return first(prop,val) && second(prop,val); - } -}; -TLogic operator&&(const TLogic &first, const TLogic &second); - -class LogicAlternative -{ - const TLogic first, second; -public: - LogicAlternative(const TLogic First, const TLogic Second) - :first(First), second(Second) - { - } - bool operator()(int prop, si32 val) const - { - return first(prop,val) || second(prop,val); - } -}; -TLogic operator||(const TLogic &first, const TLogic &second); - -class KnowledgeHandler///I'd opt for one omniscent knowledge manager, so no templates here -{ -public: - std::list knowledge; //permanent storage of rules - - void parseKnowledge(std::string &filename){}; - void addKnowledge(ExpertSystemShell &expert); - void addFacts(ExpertSystemShell &expert); -}; diff --git a/AI/GeniusAI/GeneralAI.cpp b/AI/GeniusAI/GeneralAI.cpp deleted file mode 100644 index d9521cb60..000000000 --- a/AI/GeniusAI/GeneralAI.cpp +++ /dev/null @@ -1,22 +0,0 @@ -#include "StdInc.h" -#include "GeneralAI.h" - -#include "../../CCallback.h" - -using namespace geniusai::GeneralAI; - -CGeneralAI::CGeneralAI() - : m_cb(NULL) -{ -} - -CGeneralAI::~CGeneralAI() -{ -} - -void CGeneralAI::init(CCallback *CB) -{ - assert(CB != NULL); - m_cb = CB; - CB->waitTillRealize = true; -} \ No newline at end of file diff --git a/AI/GeniusAI/GeneralAI.h b/AI/GeniusAI/GeneralAI.h deleted file mode 100644 index 48315b3cd..000000000 --- a/AI/GeniusAI/GeneralAI.h +++ /dev/null @@ -1,18 +0,0 @@ -#pragma once - -#include "Common.h" - -namespace geniusai { namespace GeneralAI { - - class CGeneralAI - { - public: - CGeneralAI(); - ~CGeneralAI(); - - void init(CCallback* CB); - private: - CCallback *m_cb; - }; - -}} \ No newline at end of file diff --git a/AI/GeniusAI/Makefile.am b/AI/GeniusAI/Makefile.am deleted file mode 100644 index 9f6699658..000000000 --- a/AI/GeniusAI/Makefile.am +++ /dev/null @@ -1,24 +0,0 @@ -vcmiaidir = $(VCMI_AI_LIBS_DIR) -BUILT_SOURCES = StdInc.h.gch -StdInc.h.gch: StdInc.h - $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< - -vcmiai_LTLIBRARIES = libGeniusAI.la -libGeniusAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la -libGeniusAI_la_CXXFLAGS = -DVCMI_DLL -libGeniusAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version -libGeniusAI_la_SOURCES = \ - AIPriorities.cpp \ - AIPriorities.h \ - BattleHelper.cpp \ - BattleHelper.h \ - BattleLogic.cpp \ - BattleLogic.h \ - CGeniusAI.cpp \ - CGeniusAI.h \ - Common.h \ - DLLMain.cpp \ - GeneralAI.cpp \ - GeneralAI.h \ - neuralNetwork.cpp \ - neuralNetwork.h diff --git a/AI/GeniusAI/Makefile.in b/AI/GeniusAI/Makefile.in deleted file mode 100644 index 912bc462d..000000000 --- a/AI/GeniusAI/Makefile.in +++ /dev/null @@ -1,675 +0,0 @@ -# Makefile.in generated by automake 1.11.1 from Makefile.am. -# @configure_input@ - -# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, -# 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, -# Inc. -# This Makefile.in is free software; the Free Software Foundation -# gives unlimited permission to copy and/or distribute it, -# with or without modifications, as long as this notice is preserved. - -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY, to the extent permitted by law; without -# even the implied warranty of MERCHANTABILITY or FITNESS FOR A -# PARTICULAR PURPOSE. - -@SET_MAKE@ - -VPATH = @srcdir@ -pkgdatadir = $(datadir)/@PACKAGE@ -pkgincludedir = $(includedir)/@PACKAGE@ -pkglibdir = $(libdir)/@PACKAGE@ -pkglibexecdir = $(libexecdir)/@PACKAGE@ -am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd -install_sh_DATA = $(install_sh) -c -m 644 -install_sh_PROGRAM = $(install_sh) -c -install_sh_SCRIPT = $(install_sh) -c -INSTALL_HEADER = $(INSTALL_DATA) -transform = $(program_transform_name) -NORMAL_INSTALL = : -PRE_INSTALL = : -POST_INSTALL = : -NORMAL_UNINSTALL = : -PRE_UNINSTALL = : -POST_UNINSTALL = : -build_triplet = @build@ -host_triplet = @host@ -subdir = AI/GeniusAI -DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in -ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 -am__aclocal_m4_deps = $(top_srcdir)/aclocal/m4/ax_boost_base.m4 \ - $(top_srcdir)/aclocal/m4/ax_boost_filesystem.m4 \ - $(top_srcdir)/aclocal/m4/ax_boost_iostreams.m4 \ - $(top_srcdir)/aclocal/m4/ax_boost_program_options.m4 \ - $(top_srcdir)/aclocal/m4/ax_boost_system.m4 \ - $(top_srcdir)/aclocal/m4/ax_boost_thread.m4 \ - $(top_srcdir)/aclocal/m4/ax_compiler_vendor.m4 \ - $(top_srcdir)/aclocal/m4/libtool.m4 \ - $(top_srcdir)/aclocal/m4/ltoptions.m4 \ - $(top_srcdir)/aclocal/m4/ltsugar.m4 \ - $(top_srcdir)/aclocal/m4/ltversion.m4 \ - $(top_srcdir)/aclocal/m4/lt~obsolete.m4 \ - $(top_srcdir)/configure.ac -am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ - $(ACLOCAL_M4) -mkinstalldirs = $(install_sh) -d -CONFIG_CLEAN_FILES = -CONFIG_CLEAN_VPATH_FILES = -am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; -am__vpath_adj = case $$p in \ - $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \ - *) f=$$p;; \ - esac; -am__strip_dir = f=`echo $$p | sed -e 's|^.*/||'`; -am__install_max = 40 -am__nobase_strip_setup = \ - srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*|]/\\\\&/g'` -am__nobase_strip = \ - for p in $$list; do echo "$$p"; done | sed -e "s|$$srcdirstrip/||" -am__nobase_list = $(am__nobase_strip_setup); \ - for p in $$list; do echo "$$p $$p"; done | \ - sed "s| $$srcdirstrip/| |;"' / .*\//!s/ .*/ ./; s,\( .*\)/[^/]*$$,\1,' | \ - $(AWK) 'BEGIN { files["."] = "" } { files[$$2] = files[$$2] " " $$1; \ - if (++n[$$2] == $(am__install_max)) \ - { print $$2, files[$$2]; n[$$2] = 0; files[$$2] = "" } } \ - END { for (dir in files) print dir, files[dir] }' -am__base_list = \ - sed '$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;$$!N;s/\n/ /g' | \ - sed '$$!N;$$!N;$$!N;$$!N;s/\n/ /g' -am__installdirs = "$(DESTDIR)$(vcmiaidir)" -LTLIBRARIES = $(vcmiai_LTLIBRARIES) -libGeniusAI_la_DEPENDENCIES = $(top_builddir)/lib/libvcmi.la -am_libGeniusAI_la_OBJECTS = libGeniusAI_la-AIPriorities.lo \ - libGeniusAI_la-BattleHelper.lo libGeniusAI_la-BattleLogic.lo \ - libGeniusAI_la-CGeniusAI.lo libGeniusAI_la-DLLMain.lo \ - libGeniusAI_la-GeneralAI.lo libGeniusAI_la-neuralNetwork.lo -libGeniusAI_la_OBJECTS = $(am_libGeniusAI_la_OBJECTS) -AM_V_lt = $(am__v_lt_$(V)) -am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) -am__v_lt_0 = --silent -libGeniusAI_la_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX \ - $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CXXLD) \ - $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) \ - $(libGeniusAI_la_LDFLAGS) $(LDFLAGS) -o $@ -DEFAULT_INCLUDES = -I.@am__isrc@ -depcomp = $(SHELL) $(top_srcdir)/depcomp -am__depfiles_maybe = depfiles -am__mv = mv -f -CXXCOMPILE = $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \ - $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CXXFLAGS) $(CXXFLAGS) -LTCXXCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CXXFLAGS) $(CXXFLAGS) -AM_V_CXX = $(am__v_CXX_$(V)) -am__v_CXX_ = $(am__v_CXX_$(AM_DEFAULT_VERBOSITY)) -am__v_CXX_0 = @echo " CXX " $@; -AM_V_at = $(am__v_at_$(V)) -am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) -am__v_at_0 = @ -CXXLD = $(CXX) -CXXLINK = $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CXXLD) $(AM_CXXFLAGS) \ - $(CXXFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CXXLD = $(am__v_CXXLD_$(V)) -am__v_CXXLD_ = $(am__v_CXXLD_$(AM_DEFAULT_VERBOSITY)) -am__v_CXXLD_0 = @echo " CXXLD " $@; -COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ - $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ - $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ - $(AM_CFLAGS) $(CFLAGS) -AM_V_CC = $(am__v_CC_$(V)) -am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) -am__v_CC_0 = @echo " CC " $@; -CCLD = $(CC) -LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ - $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ - $(AM_LDFLAGS) $(LDFLAGS) -o $@ -AM_V_CCLD = $(am__v_CCLD_$(V)) -am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) -am__v_CCLD_0 = @echo " CCLD " $@; -AM_V_GEN = $(am__v_GEN_$(V)) -am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) -am__v_GEN_0 = @echo " GEN " $@; -SOURCES = $(libGeniusAI_la_SOURCES) -DIST_SOURCES = $(libGeniusAI_la_SOURCES) -ETAGS = etags -CTAGS = ctags -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AR = @AR@ -AUTOCONF = @AUTOCONF@ -AUTOHEADER = @AUTOHEADER@ -AUTOMAKE = @AUTOMAKE@ -AWK = @AWK@ -BOOST_CPPFLAGS = @BOOST_CPPFLAGS@ -BOOST_FILESYSTEM_LIB = @BOOST_FILESYSTEM_LIB@ -BOOST_IOSTREAMS_LIB = @BOOST_IOSTREAMS_LIB@ -BOOST_LDFLAGS = @BOOST_LDFLAGS@ -BOOST_PROGRAM_OPTIONS_LIB = @BOOST_PROGRAM_OPTIONS_LIB@ -BOOST_SYSTEM_LIB = @BOOST_SYSTEM_LIB@ -BOOST_THREAD_LIB = @BOOST_THREAD_LIB@ -CC = @CC@ -CCDEPMODE = @CCDEPMODE@ -CFLAGS = @CFLAGS@ -CPP = @CPP@ -CPPFLAGS = @CPPFLAGS@ -CXX = @CXX@ -CXXCPP = @CXXCPP@ -CXXDEPMODE = @CXXDEPMODE@ -CXXFLAGS = @CXXFLAGS@ -CYGPATH_W = @CYGPATH_W@ -DEFS = @DEFS@ -DEPDIR = @DEPDIR@ -DLLTOOL = @DLLTOOL@ -DSYMUTIL = @DSYMUTIL@ -DUMPBIN = @DUMPBIN@ -ECHO_C = @ECHO_C@ -ECHO_N = @ECHO_N@ -ECHO_T = @ECHO_T@ -EGREP = @EGREP@ -EXEEXT = @EXEEXT@ -FFMPEG_CXXFLAGS = @FFMPEG_CXXFLAGS@ -FFMPEG_LIBS = @FFMPEG_LIBS@ -FGREP = @FGREP@ -GREP = @GREP@ -INSTALL = @INSTALL@ -INSTALL_DATA = @INSTALL_DATA@ -INSTALL_PROGRAM = @INSTALL_PROGRAM@ -INSTALL_SCRIPT = @INSTALL_SCRIPT@ -INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ -LD = @LD@ -LDFLAGS = @LDFLAGS@ -LIBOBJS = @LIBOBJS@ -LIBS = @LIBS@ -LIBTOOL = @LIBTOOL@ -LIPO = @LIPO@ -LN_S = @LN_S@ -LTLIBOBJS = @LTLIBOBJS@ -MAKEINFO = @MAKEINFO@ -MANIFEST_TOOL = @MANIFEST_TOOL@ -MKDIR_P = @MKDIR_P@ -NM = @NM@ -NMEDIT = @NMEDIT@ -OBJDUMP = @OBJDUMP@ -OBJEXT = @OBJEXT@ -OTOOL = @OTOOL@ -OTOOL64 = @OTOOL64@ -PACKAGE = @PACKAGE@ -PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@ -PACKAGE_NAME = @PACKAGE_NAME@ -PACKAGE_STRING = @PACKAGE_STRING@ -PACKAGE_TARNAME = @PACKAGE_TARNAME@ -PACKAGE_URL = @PACKAGE_URL@ -PACKAGE_VERSION = @PACKAGE_VERSION@ -PATH_SEPARATOR = @PATH_SEPARATOR@ -RANLIB = @RANLIB@ -SDL_CFLAGS = @SDL_CFLAGS@ -SDL_CONFIG = @SDL_CONFIG@ -SDL_CXXFLAGS = @SDL_CXXFLAGS@ -SDL_LIBS = @SDL_LIBS@ -SED = @SED@ -SET_MAKE = @SET_MAKE@ -SHELL = @SHELL@ -STRIP = @STRIP@ -VCMI_AI_LIBS_DIR = @VCMI_AI_LIBS_DIR@ -VCMI_SCRIPTING_LIBS_DIR = @VCMI_SCRIPTING_LIBS_DIR@ -VERSION = @VERSION@ -abs_builddir = @abs_builddir@ -abs_srcdir = @abs_srcdir@ -abs_top_builddir = @abs_top_builddir@ -abs_top_srcdir = @abs_top_srcdir@ -ac_ct_AR = @ac_ct_AR@ -ac_ct_CC = @ac_ct_CC@ -ac_ct_CXX = @ac_ct_CXX@ -ac_ct_DUMPBIN = @ac_ct_DUMPBIN@ -am__include = @am__include@ -am__leading_dot = @am__leading_dot@ -am__quote = @am__quote@ -am__tar = @am__tar@ -am__untar = @am__untar@ -bindir = @bindir@ -build = @build@ -build_alias = @build_alias@ -build_cpu = @build_cpu@ -build_os = @build_os@ -build_vendor = @build_vendor@ -builddir = @builddir@ -datadir = @datadir@ -datarootdir = @datarootdir@ -docdir = @docdir@ -dvidir = @dvidir@ -exec_prefix = @exec_prefix@ -host = @host@ -host_alias = @host_alias@ -host_cpu = @host_cpu@ -host_os = @host_os@ -host_vendor = @host_vendor@ -htmldir = @htmldir@ -includedir = @includedir@ -infodir = @infodir@ -install_sh = @install_sh@ -libdir = @libdir@ -libexecdir = @libexecdir@ -localedir = @localedir@ -localstatedir = @localstatedir@ -mandir = @mandir@ -mkdir_p = @mkdir_p@ -oldincludedir = @oldincludedir@ -pdfdir = @pdfdir@ -prefix = @prefix@ -program_transform_name = @program_transform_name@ -psdir = @psdir@ -sbindir = @sbindir@ -sharedstatedir = @sharedstatedir@ -srcdir = @srcdir@ -sysconfdir = @sysconfdir@ -target_alias = @target_alias@ -top_build_prefix = @top_build_prefix@ -top_builddir = @top_builddir@ -top_srcdir = @top_srcdir@ -vcmiaidir = $(VCMI_AI_LIBS_DIR) -BUILT_SOURCES = StdInc.h.gch -vcmiai_LTLIBRARIES = libGeniusAI.la -libGeniusAI_la_LIBADD = $(top_builddir)/lib/libvcmi.la -libGeniusAI_la_CXXFLAGS = -DVCMI_DLL -libGeniusAI_la_LDFLAGS = -L$(top_builddir)/lib -module -avoid-version -libGeniusAI_la_SOURCES = \ - AIPriorities.cpp \ - AIPriorities.h \ - BattleHelper.cpp \ - BattleHelper.h \ - BattleLogic.cpp \ - BattleLogic.h \ - CGeniusAI.cpp \ - CGeniusAI.h \ - Common.h \ - DLLMain.cpp \ - GeneralAI.cpp \ - GeneralAI.h \ - neuralNetwork.cpp \ - neuralNetwork.h - -all: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) all-am - -.SUFFIXES: -.SUFFIXES: .cpp .lo .o .obj -$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) - @for dep in $?; do \ - case '$(am__configure_deps)' in \ - *$$dep*) \ - ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ - && { if test -f $@; then exit 0; else break; fi; }; \ - exit 1;; \ - esac; \ - done; \ - echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu AI/GeniusAI/Makefile'; \ - $(am__cd) $(top_srcdir) && \ - $(AUTOMAKE) --gnu AI/GeniusAI/Makefile -.PRECIOUS: Makefile -Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status - @case '$?' in \ - *config.status*) \ - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ - *) \ - echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \ - cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \ - esac; - -$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh - -$(top_srcdir)/configure: $(am__configure_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(ACLOCAL_M4): $(am__aclocal_m4_deps) - cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh -$(am__aclocal_m4_deps): -install-vcmiaiLTLIBRARIES: $(vcmiai_LTLIBRARIES) - @$(NORMAL_INSTALL) - test -z "$(vcmiaidir)" || $(MKDIR_P) "$(DESTDIR)$(vcmiaidir)" - @list='$(vcmiai_LTLIBRARIES)'; test -n "$(vcmiaidir)" || list=; \ - list2=; for p in $$list; do \ - if test -f $$p; then \ - list2="$$list2 $$p"; \ - else :; fi; \ - done; \ - test -z "$$list2" || { \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 '$(DESTDIR)$(vcmiaidir)'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=install $(INSTALL) $(INSTALL_STRIP_FLAG) $$list2 "$(DESTDIR)$(vcmiaidir)"; \ - } - -uninstall-vcmiaiLTLIBRARIES: - @$(NORMAL_UNINSTALL) - @list='$(vcmiai_LTLIBRARIES)'; test -n "$(vcmiaidir)" || list=; \ - for p in $$list; do \ - $(am__strip_dir) \ - echo " $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f '$(DESTDIR)$(vcmiaidir)/$$f'"; \ - $(LIBTOOL) $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=uninstall rm -f "$(DESTDIR)$(vcmiaidir)/$$f"; \ - done - -clean-vcmiaiLTLIBRARIES: - -test -z "$(vcmiai_LTLIBRARIES)" || rm -f $(vcmiai_LTLIBRARIES) - @list='$(vcmiai_LTLIBRARIES)'; for p in $$list; do \ - dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \ - test "$$dir" != "$$p" || dir=.; \ - echo "rm -f \"$${dir}/so_locations\""; \ - rm -f "$${dir}/so_locations"; \ - done -libGeniusAI.la: $(libGeniusAI_la_OBJECTS) $(libGeniusAI_la_DEPENDENCIES) - $(AM_V_CXXLD)$(libGeniusAI_la_LINK) -rpath $(vcmiaidir) $(libGeniusAI_la_OBJECTS) $(libGeniusAI_la_LIBADD) $(LIBS) - -mostlyclean-compile: - -rm -f *.$(OBJEXT) - -distclean-compile: - -rm -f *.tab.c - -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-AIPriorities.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-BattleHelper.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-BattleLogic.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-CGeniusAI.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-DLLMain.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-GeneralAI.Plo@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libGeniusAI_la-neuralNetwork.Plo@am__quote@ - -.cpp.o: -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ $< - -.cpp.obj: -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(CXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ `$(CYGPATH_W) '$<'` -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Po -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(CXXCOMPILE) -c -o $@ `$(CYGPATH_W) '$<'` - -.cpp.lo: -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LTCXXCOMPILE) -MT $@ -MD -MP -MF $(DEPDIR)/$*.Tpo -c -o $@ $< -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/$*.Tpo $(DEPDIR)/$*.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LTCXXCOMPILE) -c -o $@ $< - -libGeniusAI_la-AIPriorities.lo: AIPriorities.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-AIPriorities.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-AIPriorities.Tpo -c -o libGeniusAI_la-AIPriorities.lo `test -f 'AIPriorities.cpp' || echo '$(srcdir)/'`AIPriorities.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-AIPriorities.Tpo $(DEPDIR)/libGeniusAI_la-AIPriorities.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='AIPriorities.cpp' object='libGeniusAI_la-AIPriorities.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-AIPriorities.lo `test -f 'AIPriorities.cpp' || echo '$(srcdir)/'`AIPriorities.cpp - -libGeniusAI_la-BattleHelper.lo: BattleHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-BattleHelper.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-BattleHelper.Tpo -c -o libGeniusAI_la-BattleHelper.lo `test -f 'BattleHelper.cpp' || echo '$(srcdir)/'`BattleHelper.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-BattleHelper.Tpo $(DEPDIR)/libGeniusAI_la-BattleHelper.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='BattleHelper.cpp' object='libGeniusAI_la-BattleHelper.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-BattleHelper.lo `test -f 'BattleHelper.cpp' || echo '$(srcdir)/'`BattleHelper.cpp - -libGeniusAI_la-BattleLogic.lo: BattleLogic.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-BattleLogic.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-BattleLogic.Tpo -c -o libGeniusAI_la-BattleLogic.lo `test -f 'BattleLogic.cpp' || echo '$(srcdir)/'`BattleLogic.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-BattleLogic.Tpo $(DEPDIR)/libGeniusAI_la-BattleLogic.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='BattleLogic.cpp' object='libGeniusAI_la-BattleLogic.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-BattleLogic.lo `test -f 'BattleLogic.cpp' || echo '$(srcdir)/'`BattleLogic.cpp - -libGeniusAI_la-CGeniusAI.lo: CGeniusAI.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-CGeniusAI.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-CGeniusAI.Tpo -c -o libGeniusAI_la-CGeniusAI.lo `test -f 'CGeniusAI.cpp' || echo '$(srcdir)/'`CGeniusAI.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-CGeniusAI.Tpo $(DEPDIR)/libGeniusAI_la-CGeniusAI.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='CGeniusAI.cpp' object='libGeniusAI_la-CGeniusAI.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-CGeniusAI.lo `test -f 'CGeniusAI.cpp' || echo '$(srcdir)/'`CGeniusAI.cpp - -libGeniusAI_la-DLLMain.lo: DLLMain.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-DLLMain.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-DLLMain.Tpo -c -o libGeniusAI_la-DLLMain.lo `test -f 'DLLMain.cpp' || echo '$(srcdir)/'`DLLMain.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-DLLMain.Tpo $(DEPDIR)/libGeniusAI_la-DLLMain.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='DLLMain.cpp' object='libGeniusAI_la-DLLMain.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-DLLMain.lo `test -f 'DLLMain.cpp' || echo '$(srcdir)/'`DLLMain.cpp - -libGeniusAI_la-GeneralAI.lo: GeneralAI.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-GeneralAI.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-GeneralAI.Tpo -c -o libGeniusAI_la-GeneralAI.lo `test -f 'GeneralAI.cpp' || echo '$(srcdir)/'`GeneralAI.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-GeneralAI.Tpo $(DEPDIR)/libGeniusAI_la-GeneralAI.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='GeneralAI.cpp' object='libGeniusAI_la-GeneralAI.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-GeneralAI.lo `test -f 'GeneralAI.cpp' || echo '$(srcdir)/'`GeneralAI.cpp - -libGeniusAI_la-neuralNetwork.lo: neuralNetwork.cpp -@am__fastdepCXX_TRUE@ $(AM_V_CXX)$(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -MT libGeniusAI_la-neuralNetwork.lo -MD -MP -MF $(DEPDIR)/libGeniusAI_la-neuralNetwork.Tpo -c -o libGeniusAI_la-neuralNetwork.lo `test -f 'neuralNetwork.cpp' || echo '$(srcdir)/'`neuralNetwork.cpp -@am__fastdepCXX_TRUE@ $(AM_V_at)$(am__mv) $(DEPDIR)/libGeniusAI_la-neuralNetwork.Tpo $(DEPDIR)/libGeniusAI_la-neuralNetwork.Plo -@am__fastdepCXX_FALSE@ $(AM_V_CXX) @AM_BACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='neuralNetwork.cpp' object='libGeniusAI_la-neuralNetwork.lo' libtool=yes @AMDEPBACKSLASH@ -@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@ -@am__fastdepCXX_FALSE@ $(LIBTOOL) $(AM_V_lt) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libGeniusAI_la_CXXFLAGS) $(CXXFLAGS) -c -o libGeniusAI_la-neuralNetwork.lo `test -f 'neuralNetwork.cpp' || echo '$(srcdir)/'`neuralNetwork.cpp - -mostlyclean-libtool: - -rm -f *.lo - -clean-libtool: - -rm -rf .libs _libs - -ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - mkid -fID $$unique -tags: TAGS - -TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - set x; \ - here=`pwd`; \ - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - shift; \ - if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ - test -n "$$unique" || unique=$$empty_fix; \ - if test $$# -gt 0; then \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - "$$@" $$unique; \ - else \ - $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ - $$unique; \ - fi; \ - fi -ctags: CTAGS -CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ - $(TAGS_FILES) $(LISP) - list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ - unique=`for i in $$list; do \ - if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ - done | \ - $(AWK) '{ files[$$0] = 1; nonempty = 1; } \ - END { if (nonempty) { for (i in files) print i; }; }'`; \ - test -z "$(CTAGS_ARGS)$$unique" \ - || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ - $$unique - -GTAGS: - here=`$(am__cd) $(top_builddir) && pwd` \ - && $(am__cd) $(top_srcdir) \ - && gtags -i $(GTAGS_ARGS) "$$here" - -distclean-tags: - -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags - -distdir: $(DISTFILES) - @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ - list='$(DISTFILES)'; \ - dist_files=`for file in $$list; do echo $$file; done | \ - sed -e "s|^$$srcdirstrip/||;t" \ - -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ - case $$dist_files in \ - */*) $(MKDIR_P) `echo "$$dist_files" | \ - sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ - sort -u` ;; \ - esac; \ - for file in $$dist_files; do \ - if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ - if test -d $$d/$$file; then \ - dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ - if test -d "$(distdir)/$$file"; then \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ - cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ - find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ - fi; \ - cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ - else \ - test -f "$(distdir)/$$file" \ - || cp -p $$d/$$file "$(distdir)/$$file" \ - || exit 1; \ - fi; \ - done -check-am: all-am -check: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) check-am -all-am: Makefile $(LTLIBRARIES) -installdirs: - for dir in "$(DESTDIR)$(vcmiaidir)"; do \ - test -z "$$dir" || $(MKDIR_P) "$$dir"; \ - done -install: $(BUILT_SOURCES) - $(MAKE) $(AM_MAKEFLAGS) install-am -install-exec: install-exec-am -install-data: install-data-am -uninstall: uninstall-am - -install-am: all-am - @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am - -installcheck: installcheck-am -install-strip: - $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ - install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ - `test -z '$(STRIP)' || \ - echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install -mostlyclean-generic: - -clean-generic: - -distclean-generic: - -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) - -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) - -maintainer-clean-generic: - @echo "This command is intended for maintainers to use" - @echo "it deletes files that may require special tools to rebuild." - -test -z "$(BUILT_SOURCES)" || rm -f $(BUILT_SOURCES) -clean: clean-am - -clean-am: clean-generic clean-libtool clean-vcmiaiLTLIBRARIES \ - mostlyclean-am - -distclean: distclean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -distclean-am: clean-am distclean-compile distclean-generic \ - distclean-tags - -dvi: dvi-am - -dvi-am: - -html: html-am - -html-am: - -info: info-am - -info-am: - -install-data-am: install-vcmiaiLTLIBRARIES - -install-dvi: install-dvi-am - -install-dvi-am: - -install-exec-am: - -install-html: install-html-am - -install-html-am: - -install-info: install-info-am - -install-info-am: - -install-man: - -install-pdf: install-pdf-am - -install-pdf-am: - -install-ps: install-ps-am - -install-ps-am: - -installcheck-am: - -maintainer-clean: maintainer-clean-am - -rm -rf ./$(DEPDIR) - -rm -f Makefile -maintainer-clean-am: distclean-am maintainer-clean-generic - -mostlyclean: mostlyclean-am - -mostlyclean-am: mostlyclean-compile mostlyclean-generic \ - mostlyclean-libtool - -pdf: pdf-am - -pdf-am: - -ps: ps-am - -ps-am: - -uninstall-am: uninstall-vcmiaiLTLIBRARIES - -.MAKE: all check install install-am install-strip - -.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \ - clean-libtool clean-vcmiaiLTLIBRARIES ctags distclean \ - distclean-compile distclean-generic distclean-libtool \ - distclean-tags distdir dvi dvi-am html html-am info info-am \ - install install-am install-data install-data-am install-dvi \ - install-dvi-am install-exec install-exec-am install-html \ - install-html-am install-info install-info-am install-man \ - install-pdf install-pdf-am install-ps install-ps-am \ - install-strip install-vcmiaiLTLIBRARIES installcheck \ - installcheck-am installdirs maintainer-clean \ - maintainer-clean-generic mostlyclean mostlyclean-compile \ - mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ - tags uninstall uninstall-am uninstall-vcmiaiLTLIBRARIES - -StdInc.h.gch: StdInc.h - $(CXXCOMPILE) -DVCMI_DLL -fPIC -c $< - -# Tell versions [3.59,3.63) of GNU make to not export all variables. -# Otherwise a system limit (for SysV at least) may be exceeded. -.NOEXPORT: diff --git a/AI/GeniusAI/StdInc.cpp b/AI/GeniusAI/StdInc.cpp deleted file mode 100644 index c8f4ddf05..000000000 --- a/AI/GeniusAI/StdInc.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// Creates the precompiled header -#include "StdInc.h" \ No newline at end of file diff --git a/AI/GeniusAI/StdInc.h b/AI/GeniusAI/StdInc.h deleted file mode 100644 index 81a6cb308..000000000 --- a/AI/GeniusAI/StdInc.h +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include "../../Global.h" - -// This header should be treated as a pre compiled header file(PCH) in the compiler building settings. - -// Here you can add specific libraries and macros which are specific to this project. \ No newline at end of file diff --git a/AI/GeniusAI/genius.vcxproj b/AI/GeniusAI/genius.vcxproj deleted file mode 100644 index b1ef241b5..000000000 --- a/AI/GeniusAI/genius.vcxproj +++ /dev/null @@ -1,244 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - RD - Win32 - - - RD - x64 - - - - {B6A14ED9-E7C1-411B-A596-2FE90B3145B4} - genius - Win32Proj - - - - DynamicLibrary - Unicode - true - - - DynamicLibrary - Unicode - true - - - DynamicLibrary - Unicode - - - DynamicLibrary - Unicode - - - - - - - - - - - - - - - - - - - - - - - <_ProjectFileVersion>10.0.30128.1 - $(SolutionDir)\AI\ - $(SolutionDir)\AI\ - $(Configuration)\ - $(Configuration)\ - true - true - $(SolutionDir)$(Configuration)\bin\AI\ - $(SolutionDir)$(Configuration)\bin\AI\ - $(Configuration)\ - $(Configuration)\ - false - false - false - false - AllRules.ruleset - AllRules.ruleset - - - - - AllRules.ruleset - AllRules.ruleset - - - - - $(IncludePath) - $(IncludePath) - $(IncludePath) - $(IncludePath) - $(LibraryPath) - $(LibraryPath) - $(LibraryPath) - $(LibraryPath) - - - - Disabled - %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;GENIUS_EXPORTS;%(PreprocessorDefinitions) - true - EnableFastChecks - MultiThreadedDebugDLL - Use - Level4 - EditAndContinue - 4512;%(DisableSpecificWarnings) - StdInc.h - - - VCMI_lib.lib;%(AdditionalDependencies) - $(OutDir)GeniusAI.dll - $(OutDir)..;%(AdditionalLibraryDirectories) - true - Windows - - - MachineX86 - false - - - - - Disabled - %(AdditionalIncludeDirectories) - WIN32;_DEBUG;_WINDOWS;_USRDLL;GENIUS_EXPORTS;%(PreprocessorDefinitions) - EnableFastChecks - MultiThreadedDebugDLL - - - Level4 - ProgramDatabase - 4512;%(DisableSpecificWarnings) - - - VCMI_lib.lib;%(AdditionalDependencies) - $(OutDir)GeniusAI.dll - $(OutDir)..;%(AdditionalLibraryDirectories) - true - Windows - - - false - - - - - /Oy- %(AdditionalOptions) - Full - true - %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;GENIUS_EXPORTS;%(PreprocessorDefinitions) - MultiThreadedDLL - true - - - All - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\GeniusAI.pdb - Level3 - ProgramDatabase - 4512;%(DisableSpecificWarnings) - - - VCMI_lib.lib;%(AdditionalDependencies) - $(OutDir)GeniusAI.dll - $(OutDir)..;%(AdditionalLibraryDirectories) - true - true - Windows - true - true - MachineX86 - - - - - /Oy- %(AdditionalOptions) - Full - true - %(AdditionalIncludeDirectories) - WIN32;NDEBUG;_WINDOWS;_USRDLL;GENIUS_EXPORTS;%(PreprocessorDefinitions) - MultiThreadedDLL - true - - - All - $(SolutionDir)$(Configuration)\ - $(SolutionDir)$(Configuration)\GeniusAI.pdb - Level3 - ProgramDatabase - 4512;%(DisableSpecificWarnings) - - - VCMI_lib.lib;%(AdditionalDependencies) - $(OutDir)GeniusAI.dll - $(OutDir)..;%(AdditionalLibraryDirectories) - true - true - Windows - true - true - - - - - - - - - - - - Create - StdInc.h - %(PreprocessorDefinitions) - - - - - - - - - - - - - - - - {b952ffc5-3039-4de1-9f08-90acda483d8f} - - - - - - \ No newline at end of file diff --git a/AI/GeniusAI/neuralNetwork.cpp b/AI/GeniusAI/neuralNetwork.cpp deleted file mode 100644 index c6f0cc45e..000000000 --- a/AI/GeniusAI/neuralNetwork.cpp +++ /dev/null @@ -1,417 +0,0 @@ -#include "StdInc.h" - -#include "neuralNetwork.h" -//using namespace std; - -#ifndef M_PI -#define M_PI 3.14159265358979323846 -#endif - -static double norm(void)//add desired mean, multiply to get desired SD -{ - static double kept = 0; - static bool in = 0; - if(!in) - { - double x = (rand() + 1) / static_cast(RAND_MAX + 1); - double f = sqrtf( - 2.0 * log(x) ); - x = (rand() + 1) / static_cast(RAND_MAX + 1); - kept = f * cosf( 2.0 * M_PI * x ); - in = true; - return f * sinf( 2.0 * M_PI * x ); - } - else - { - in = false; - return kept; - } -} - -/******************************************************************* -* Constructors -********************************************************************/ -neuralNetwork::neuralNetwork() : nInput(0), nHidden1(0), nHidden2(0), nOutput(0) -{ - inputNeurons = new double[1] ; - hiddenNeurons1 = new double[1] ; - hiddenNeurons2 = new double[1] ; - outputNeurons = new double[1] ; - wInputHidden = new double*[1] ; - wInputHidden[0] = new double[1]; - wHidden2Hidden = new double*[1] ; - wHidden2Hidden[0] = new (double[1]); - wHiddenOutput = new double*[1] ; - wHiddenOutput[0] = new double[1]; -} - -neuralNetwork::neuralNetwork(const neuralNetwork& other): nInput(0), nHidden1(0), nHidden2(0), nOutput(0) -{ - inputNeurons = new double[1] ; - hiddenNeurons1 = new double[1] ; - hiddenNeurons2 = new double[1] ; - outputNeurons = new double[1] ; - wInputHidden = new double*[1] ; - wInputHidden[0] = new double[1]; - wHidden2Hidden = new double*[1] ; - wHidden2Hidden[0] = new (double[1]); - wHiddenOutput = new double*[1] ; - wHiddenOutput[0] = new double[1]; - *this = other; -} - -neuralNetwork::neuralNetwork(int nI, int nH1, int nH2, int nO) : nInput(nI), nHidden1(nH1), nHidden2(nH2), nOutput(nO) -{ - //create neuron lists - //-------------------------------------------------------------------------------------------------------- - inputNeurons = new double[nInput + 1] ; - for ( int i=0; i < nInput; i++ ) inputNeurons[i] = 0; - - //create input bias neuron - inputNeurons[nInput] = -1; - - hiddenNeurons1 = new double[nHidden1 + 1] ; - for ( int i=0; i < nHidden1; i++ ) hiddenNeurons1[i] = 0; - - //create hidden bias neuron - hiddenNeurons1[nHidden1] = -1; - - hiddenNeurons2 = new double[nHidden2 + 1] ; - for ( int i=0; i < nHidden2; i++ ) hiddenNeurons2[i] = 0; - - //create hidden bias neuron - hiddenNeurons2[nHidden2] = -1; - - outputNeurons = new double[nOutput] ; - for ( int i=0; i < nOutput; i++ ) outputNeurons[i] = 0; - - //create weight lists (include bias neuron weights) - //-------------------------------------------------------------------------------------------------------- - wInputHidden = new double*[nInput + 1] ; - for ( int i=0; i <= nInput; i++ ) - { - wInputHidden[i] = new double[nHidden1]; - for ( int j=0; j < nHidden1; j++ ) wInputHidden[i][j] = 0; - } - - wHidden2Hidden = new double*[nHidden1 + 1] ; - for ( int i=0; i <= nHidden1; i++ ) - { - wHidden2Hidden[i] = new (double[nHidden2]); - for ( int j=0; j < nHidden2; j++ ) wHidden2Hidden[i][j] = 0; - } - - wHiddenOutput = new double*[nHidden2 + 1] ; - for ( int i=0; i <= nHidden2; i++ ) - { - wHiddenOutput[i] = new double[nOutput]; - for ( int j=0; j < nOutput; j++ ) wHiddenOutput[i][j] = 0; - } - - //initialize weights - //-------------------------------------------------------------------------------------------------------- - initializeWeights(); -} - - -void neuralNetwork::operator = (const neuralNetwork&cpy)//assumes same structure -{ - if( nInput != cpy.nInput || nHidden1 != cpy.nHidden1 || nHidden2 != cpy.nHidden2 || nOutput != cpy.nOutput) - { - delete[] inputNeurons; - delete[] hiddenNeurons1; - delete[] hiddenNeurons2; - delete[] outputNeurons; - - //delete weight storage - for (int i=0; i <= nInput; i++) delete[] wInputHidden[i]; - delete[] wInputHidden; - - for (int j=0; j <= nHidden2; j++) delete[] wHiddenOutput[j]; - delete[] wHiddenOutput; - - for (int j=0; j <= nHidden1; j++) delete[] wHidden2Hidden[j]; - delete[] wHidden2Hidden; - - nInput = cpy.nInput; - nHidden1 = cpy.nHidden1; - nHidden2 = cpy.nHidden2; - nOutput = cpy.nOutput; - - inputNeurons = new double[nInput + 1] ; - inputNeurons[nInput] = -1; - - hiddenNeurons1 = new double[nHidden1 + 1] ; - hiddenNeurons1[nHidden1] = -1; - - hiddenNeurons2 = new double[nHidden2 + 1] ; - hiddenNeurons2[nHidden2] = -1; - - outputNeurons = new double[nOutput] ; - - //create weight lists (include bias neuron weights) - //-------------------------------------------------------------------------------------------------------- - wInputHidden = new double*[nInput + 1] ; - for ( int i=0; i <= nInput; i++ ) - wInputHidden[i] = new double[nHidden1]; - - wHidden2Hidden = new double*[nHidden1 + 1] ; - for ( int i=0; i <= nHidden1; i++ ) - wHidden2Hidden[i] = new (double[nHidden2]); - - wHiddenOutput = new double*[nHidden2 + 1] ; - for ( int i=0; i <= nHidden2; i++ ) - wHiddenOutput[i] = new double[nOutput]; - } - - for ( int i=0; i < nInput; i++ ) inputNeurons[i] = cpy.inputNeurons[i]; - for ( int i=0; i < nHidden1; i++ ) hiddenNeurons1[i] = cpy.hiddenNeurons1[i]; - for ( int i=0; i < nHidden2; i++ ) hiddenNeurons2[i] = cpy.hiddenNeurons2[i]; - for ( int i=0; i < nOutput; i++ ) outputNeurons[i] = cpy.outputNeurons[i]; - - for ( int i=0; i <= nInput; i++ ) - for ( int j=0; j < nHidden1; j++ ) - wInputHidden[i][j] = cpy.wInputHidden[i][j]; - - for ( int i=0; i <= nHidden1; i++ ) - for ( int j=0; j < nHidden2; j++ ) - wHidden2Hidden[i][j] = cpy.wHidden2Hidden[i][j]; - - for ( int i=0; i <= nHidden2; i++ ) - for ( int j=0; j < nOutput; j++ ) - wHiddenOutput[i][j] = cpy.wHiddenOutput[i][j]; - -} -/******************************************************************* -* Destructor -********************************************************************/ -neuralNetwork::~neuralNetwork() -{ - //delete neurons - delete[] inputNeurons; - delete[] hiddenNeurons1; - delete[] hiddenNeurons2; - delete[] outputNeurons; - - //delete weight storage - for (int i=0; i <= nInput; i++) delete[] wInputHidden[i]; - delete[] wInputHidden; - - for (int j=0; j <= nHidden2; j++) delete[] wHiddenOutput[j]; - delete[] wHiddenOutput; - - for (int j=0; j <= nHidden1; j++) delete[] wHidden2Hidden[j]; - delete[] wHidden2Hidden; -} - -double* neuralNetwork::feedForwardPattern(double *pattern) -{ - feedForward(pattern); - - - return outputNeurons; -} - -void neuralNetwork::mate(const neuralNetwork&n1,const neuralNetwork&n2) -{ - for(int i = 0; i <= nInput; i++) - { - for(int j = 0; j < nHidden1; j++) - { - if(rand()%2==0) - wInputHidden[i][j] = n1.wInputHidden[i][j]; - else - wInputHidden[i][j] = n2.wInputHidden[i][j]; - } - } - for(int i = 0; i <= nHidden1; i++) - { - for(int j = 0; j < nHidden2; j++) - { - if(rand()%2==0) - wHidden2Hidden[i][j] =n1.wHidden2Hidden[i][j]; - else - wHidden2Hidden[i][j] =n2.wHidden2Hidden[i][j]; - } - } - - for(int i = 0; i <= nHidden2; i++) - { - for(int j = 0; j < nOutput; j++) - { - if(rand()%2==0) - wHiddenOutput[i][j] =n1.wHiddenOutput[i][j]; - else - wHiddenOutput[i][j] =n2.wHiddenOutput[i][j]; - } - } -} - -void neuralNetwork::tweakWeights(double howMuch) -{ - //set range - double rH = 1/sqrt( (double) nInput); - double rO = 1/sqrt( (double) nHidden1); - - for(int i = 0; i <= nInput; i++) - { - for(int j = 0; j < nHidden1; j++) - { - wInputHidden[i][j] += howMuch*norm(); - } - } - for(int i = 0; i <= nHidden1; i++) - { - for(int j = 0; j < nHidden2; j++) - { - wHidden2Hidden[i][j] += howMuch*norm(); - } - } - - for(int i = 0; i <= nHidden2; i++) - { - for(int j = 0; j < nOutput; j++) - { - wHiddenOutput[i][j] += howMuch* norm(); - } - } - //initializeWeights(); -} - -void neuralNetwork::initializeWeights() -{ - //set range - double rH = 2.0/sqrt( (double) nInput); - double rO = 2.0/sqrt( (double) nHidden1); - - //set weights between input and hidden - //-------------------------------------------------------------------------------------------------------- - for(int i = 0; i <= nInput; i++) - { - for(int j = 0; j < nHidden1; j++) - { - //set weights to random values - wInputHidden[i][j] = norm()* rH; - } - } - - for(int i = 0; i <= nHidden1; i++) - { - for(int j = 0; j < nHidden2; j++) - { - //set weights to random values - wHidden2Hidden[i][j] = norm()* rO; - } - } - - //set weights between hidden and output - //-------------------------------------------------------------------------------------------------------- - for(int i = 0; i <= nHidden2; i++) - { - for(int j = 0; j < nOutput; j++) - { - //set weights to random values - wHiddenOutput[i][j] = norm()* rO; - } - } -} -/******************************************************************* -* Activation Function -********************************************************************/ -inline double neuralNetwork::activationFunction( double x ) -{ - //sigmoid function - return 1/(1+exp(-x)); -} - -/******************************************************************* -* Feed Forward Operation -********************************************************************/ -void neuralNetwork::feedForward(double* pattern) -{ - //set input neurons to input values - for(int i = 0; i < nInput; i++) inputNeurons[i] = pattern[i]; - - //Calculate Hidden Layer values - include bias neuron - //-------------------------------------------------------------------------------------------------------- - for(int j=0; j < nHidden1; j++) - { - //clear value - hiddenNeurons1[j] = 0; - - //get weighted sum of pattern and bias neuron - for( int i=0; i <= nInput; i++ ) hiddenNeurons1[j] += inputNeurons[i] * wInputHidden[i][j]; - - //set to result of sigmoid - hiddenNeurons1[j] = activationFunction( hiddenNeurons1[j] ); - } - - for(int j=0; j < nHidden2; j++) - { - //clear value - hiddenNeurons2[j] = 0; - - //get weighted sum of pattern and bias neuron - for( int i=0; i <= nHidden1; i++ ) hiddenNeurons2[j] += hiddenNeurons1[i] * wHidden2Hidden[i][j]; - - //set to result of sigmoid - hiddenNeurons2[j] = activationFunction( hiddenNeurons2[j] ); - } - - //Calculating Output Layer values - include bias neuron - //-------------------------------------------------------------------------------------------------------- - for(int k=0; k < nOutput; k++) - { - //clear value - outputNeurons[k] = 0; - - //get weighted sum of pattern and bias neuron - for( int j=0; j <= nHidden2; j++ ) outputNeurons[k] += hiddenNeurons2[j] * wHiddenOutput[j][k]; - - //set to result of sigmoid - //outputNeurons[k] = activationFunction( outputNeurons[k] ); - } -} - -void neuralNetwork::backpropigate(double* pattern, double OLR, double H2LR, double H1LR ) -{ - //inputError = new double[nInput + 1] ; - double * hiddenError1 = new double[nHidden1 + 1] ; - double * hiddenError2 = new double[nHidden2 + 1] ; - double * outputError = new double[nOutput] ; - memset(hiddenError1,0,sizeof(double)*nHidden1); - memset(hiddenError2,0,sizeof(double)*nHidden2); - - for(int i = 0; i < nOutput; i++) - { - outputError[i] = (pattern[i]-outputNeurons[i]);//*(outputNeurons[i]*(1-outputNeurons[i])); - for(int ii = 0; ii <= nHidden2;ii++) - hiddenError2[ii]+=outputError[i]*wHiddenOutput[ii][i]; - for(int ii = 0; ii <= nHidden2;ii++) - wHiddenOutput[ii][i]+=OLR*hiddenNeurons2[ii]*outputError[i]; - - } - - for(int i = 0; i < nHidden2; i++) - { - hiddenError2[i] *= (hiddenNeurons2[i]*(1-hiddenNeurons2[i])); - for(int ii = 0; ii <= nHidden1;ii++) - hiddenError1[ii]+=hiddenError2[i]*wHidden2Hidden[ii][i]; - for(int ii = 0; ii <= nHidden1;ii++) - wHidden2Hidden[ii][i]+=H2LR*hiddenNeurons1[ii]*hiddenError2[i]; - - } - - for(int i = 0; i < nHidden1; i++) - { - hiddenError1[i] *= (hiddenNeurons1[i]*(1-hiddenNeurons1[i])); - - for(int ii = 0; ii <= nInput;ii++) - wInputHidden[ii][i]+=H1LR*inputNeurons[ii]*hiddenError1[i]; - - } - - - delete [] hiddenError1; - delete [] hiddenError2; - delete [] outputError; -} diff --git a/AI/GeniusAI/neuralNetwork.h b/AI/GeniusAI/neuralNetwork.h deleted file mode 100644 index 9002a93df..000000000 --- a/AI/GeniusAI/neuralNetwork.h +++ /dev/null @@ -1,61 +0,0 @@ - - -/******************************************************************* -* addapted by Trevor Standley for use as a function approximator -* Addapted from: -* Basic Feed Forward Neural Network Class -* ------------------------------------------------------------------ -* Bobby Anguelov - takinginitiative.wordpress.com (2008) -* MSN & email: banguelov@cs.up.ac.za -********************************************************************/ -#pragma once -//standard includes -#include - - -class neuralNetwork -{ -private: - - //number of neurons - int nInput, nHidden1, nHidden2, nOutput; - - //neurons - double* inputNeurons; - double* hiddenNeurons1; - double* hiddenNeurons2; - double* outputNeurons; - - //weights - double** wInputHidden; - double** wHidden2Hidden; - double** wHiddenOutput; - - -public: - - //constructor & destructor - neuralNetwork(int numInput, int numHidden1, int numHidden2, int numOutput); - neuralNetwork(const neuralNetwork&); - neuralNetwork(); - void operator = (const neuralNetwork&); - ~neuralNetwork(); - - //weight operations - double* feedForwardPattern( double* pattern ); - void backpropigate(double* pattern, double OLR, double H2LR, double H1LR ); - - void tweakWeights(double howMuch); - void mate(const neuralNetwork&n1,const neuralNetwork&n2); - - - -private: - void initializeWeights(); - inline double activationFunction( double x ); - void feedForward( double* pattern ); - -}; - -std::istream & operator >> (std::istream &, neuralNetwork & ann); -std::ostream & operator << (std::ostream &, const neuralNetwork & ann); \ No newline at end of file