- Split AIPlayer and AIPlayerBaka in 2 files. Moved all "AI" specific code into AIPlayerBaka, as much as possible.
-- This is a copy/paste and shouldn't have any impact on the logic. I just moved some functions from AIPlayer to AIPlayerBaka - Added back the possibility to select a different Resource folder with file Res.txt - Fix a crash when a token id does not exist
This commit is contained in:
@@ -34,6 +34,7 @@ LOCAL_SRC_FILES := $(SDL_PATH)/src/main/android/SDL_android_main.cpp \
|
|||||||
$(MTG_PATH)/src/AIHints.cpp \
|
$(MTG_PATH)/src/AIHints.cpp \
|
||||||
$(MTG_PATH)/src/AIMomirPlayer.cpp \
|
$(MTG_PATH)/src/AIMomirPlayer.cpp \
|
||||||
$(MTG_PATH)/src/AIPlayer.cpp \
|
$(MTG_PATH)/src/AIPlayer.cpp \
|
||||||
|
$(MTG_PATH)/src/AIPlayerBaka.cpp \
|
||||||
$(MTG_PATH)/src/AIStats.cpp \
|
$(MTG_PATH)/src/AIStats.cpp \
|
||||||
$(MTG_PATH)/src/AllAbilities.cpp \
|
$(MTG_PATH)/src/AllAbilities.cpp \
|
||||||
$(MTG_PATH)/src/CardDescriptor.cpp \
|
$(MTG_PATH)/src/CardDescriptor.cpp \
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIHints.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/IconButton.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/ModRules.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/ObjectAnalytics.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
|
OBJS = objs/ActionElement.o objs/ActionLayer.o objs/ActionStack.o objs/AIHints.o objs/AIMomirPlayer.o objs/AIPlayer.o objs/AIPlayerBaka.o objs/AIStats.o objs/AllAbilities.o objs/CardGui.o objs/CardDescriptor.o objs/CardDisplay.o objs/CardEffect.o objs/CardPrimitive.o objs/CardSelector.o objs/CardSelectorSingleton.o objs/Counters.o objs/Credits.o objs/Damage.o objs/DamagerDamaged.o objs/DeckDataWrapper.o objs/DeckEditorMenu.o objs/DeckMenu.o objs/DeckMenuItem.o objs/DeckMetaData.o objs/DeckStats.o objs/DuelLayers.o objs/Effects.o objs/ExtraCost.o objs/GameApp.o objs/GameLauncher.o objs/GameObserver.o objs/GameOptions.o objs/GameState.o objs/GameStateAwards.o objs/GameStateDeckViewer.o objs/GameStateDuel.o objs/DeckManager.o objs/GameStateMenu.o objs/GameStateOptions.o objs/GameStateShop.o objs/GameStateStory.o objs/GameStateTransitions.o objs/GuiAvatars.o objs/GuiBackground.o objs/GuiCardsController.o objs/GuiCombat.o objs/GuiFrame.o objs/GuiHand.o objs/GuiLayers.o objs/GuiMana.o objs/GuiPhaseBar.o objs/GuiPlay.o objs/GuiStatic.o objs/IconButton.o objs/ManaCost.o objs/ManaCostHybrid.o objs/MenuItem.o objs/ModRules.o objs/MTGAbility.o objs/MTGCardInstance.o objs/MTGCard.o objs/MTGDeck.o objs/MTGDefinitions.o objs/MTGGamePhase.o objs/MTGGameZones.o objs/MTGPack.o objs/MTGRules.o objs/Navigator.o objs/ObjectAnalytics.o objs/OptionItem.o objs/PhaseRing.o objs/Player.o objs/PlayerData.o objs/PlayGuiObjectController.o objs/PlayGuiObject.o objs/PlayRestrictions.o objs/Pos.o objs/PrecompiledHeader.o objs/PriceList.o objs/ReplacementEffects.o objs/Rules.o objs/SimpleMenu.o objs/SimpleMenuItem.o objs/SimplePad.o objs/SimplePopup.o objs/StoryFlow.o objs/StyleManager.o objs/Subtypes.o objs/TargetChooser.o objs/TargetsList.o objs/TextScroller.o objs/ThisDescriptor.o objs/Token.o objs/Translate.o objs/TranslateKeys.o objs/Trash.o objs/utils.o objs/WEvent.o objs/WResourceManager.o objs/WCachedResource.o objs/WDataSrc.o objs/WGui.o objs/WFilter.o objs/Tasks.o objs/WFont.o
|
||||||
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
|
DEPS = $(patsubst objs/%.o, deps/%.d, $(OBJS))
|
||||||
|
|
||||||
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)
|
RESULT = $(shell psp-config --psp-prefix 2> Makefile.cache)
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
|
../../wagic_res/
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
using std::string;
|
using std::string;
|
||||||
using std::vector;
|
using std::vector;
|
||||||
|
|
||||||
#include "AIPlayer.h"
|
#include "AIPlayerBaka.h"
|
||||||
|
|
||||||
class ManaCost;
|
class ManaCost;
|
||||||
class MTGAbility;
|
class MTGAbility;
|
||||||
@@ -24,7 +24,7 @@ public:
|
|||||||
class AIHints
|
class AIHints
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
AIPlayer * mPlayer;
|
AIPlayerBaka * mPlayer;
|
||||||
vector<AIHint *> hints;
|
vector<AIHint *> hints;
|
||||||
AIHint * getByCondition (string condition);
|
AIHint * getByCondition (string condition);
|
||||||
AIAction * findAbilityRecursive(AIHint * hint, ManaCost * potentialMana);
|
AIAction * findAbilityRecursive(AIHint * hint, ManaCost * potentialMana);
|
||||||
@@ -34,7 +34,7 @@ protected:
|
|||||||
bool findSource(int sourceId);
|
bool findSource(int sourceId);
|
||||||
bool abilityMatches(MTGAbility * a, AIHint * hint);
|
bool abilityMatches(MTGAbility * a, AIHint * hint);
|
||||||
public:
|
public:
|
||||||
AIHints (AIPlayer * player);
|
AIHints (AIPlayerBaka * player);
|
||||||
AIAction * suggestAbility(ManaCost * potentialMana);
|
AIAction * suggestAbility(ManaCost * potentialMana);
|
||||||
void add(string line);
|
void add(string line);
|
||||||
~AIHints();
|
~AIHints();
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#ifndef _AIMOMIRPLAYER_H_
|
#ifndef _AIMOMIRPLAYER_H_
|
||||||
#define _AIMOMIRPLAYER_H_
|
#define _AIMOMIRPLAYER_H_
|
||||||
|
|
||||||
#include "AIPlayer.h"
|
#include "AIPlayerBaka.h"
|
||||||
|
|
||||||
class AIMomirPlayer: public AIPlayerBaka
|
class AIMomirPlayer: public AIPlayerBaka
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
AIMomirPlayer(string file, string fileSmall, string avatarFile, MTGDeck * deck = NULL);
|
AIMomirPlayer(string file, string fileSmall, string avatarFile, MTGDeck * deck = NULL);
|
||||||
int getEfficiency(AIAction * action);
|
int getEfficiency(OrderedAIAction * action);
|
||||||
int momir();
|
int momir();
|
||||||
int computeActions();
|
int computeActions();
|
||||||
static MTGAbility * momirAbility;
|
static MTGAbility * momirAbility;
|
||||||
|
|||||||
@@ -2,6 +2,14 @@
|
|||||||
* Wagic, The Homebrew ?! is licensed under the BSD license
|
* Wagic, The Homebrew ?! is licensed under the BSD license
|
||||||
* See LICENSE in the Folder's root
|
* See LICENSE in the Folder's root
|
||||||
* http://wololo.net/wagic/
|
* http://wololo.net/wagic/
|
||||||
|
|
||||||
|
AIPlayer is the interface to represent a CPU Player.
|
||||||
|
At its core, AIPlayer inherits from Player, and its children need to implement the function "Act" which
|
||||||
|
pretty much handles all the logic.
|
||||||
|
A sample implementation can be found in AIPlayerBaka.
|
||||||
|
|
||||||
|
Ideally, mid-term, AIPlayer will handle all the mechanical tasks (clicking on cards, etc...) while its children are just in charge of the logic
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _IAPLAYER_H
|
#ifndef _IAPLAYER_H
|
||||||
@@ -12,20 +20,11 @@
|
|||||||
#include <queue>
|
#include <queue>
|
||||||
using std::queue;
|
using std::queue;
|
||||||
|
|
||||||
#define INFO_NBCREATURES 0
|
|
||||||
#define INFO_CREATURESPOWER 1
|
|
||||||
#define INFO_CREATURESRANK 2
|
|
||||||
#define INFO_CREATURESTOUGHNESS 3
|
|
||||||
#define INFO_CREATURESATTACKINGPOWER 4
|
|
||||||
|
|
||||||
|
|
||||||
class AIStats;
|
class AIStats;
|
||||||
class AIHints;
|
|
||||||
|
|
||||||
class AIAction
|
class AIAction
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
int efficiency;
|
|
||||||
static int currentId;
|
static int currentId;
|
||||||
public:
|
public:
|
||||||
MTGAbility * ability;
|
MTGAbility * ability;
|
||||||
@@ -39,7 +38,7 @@ public:
|
|||||||
//player targeting through abilities is handled completely seperate from spell targeting.
|
//player targeting through abilities is handled completely seperate from spell targeting.
|
||||||
|
|
||||||
AIAction(MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
|
AIAction(MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
|
||||||
: efficiency(-1), ability(a), player(NULL), click(c), target(t),playerAbilityTarget(NULL)
|
: ability(a), player(NULL), click(c), target(t),playerAbilityTarget(NULL)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
id = currentId++;
|
||||||
};
|
};
|
||||||
@@ -47,110 +46,57 @@ public:
|
|||||||
AIAction(MTGCardInstance * c, MTGCardInstance * t = NULL);
|
AIAction(MTGCardInstance * c, MTGCardInstance * t = NULL);
|
||||||
|
|
||||||
AIAction(Player * p)//player targeting through spells
|
AIAction(Player * p)//player targeting through spells
|
||||||
: efficiency(-1), ability(NULL), player(p), click(NULL), target(NULL),playerAbilityTarget(NULL)
|
: ability(NULL), player(p), click(NULL), target(NULL),playerAbilityTarget(NULL)
|
||||||
{
|
{
|
||||||
};
|
};
|
||||||
|
|
||||||
AIAction(MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
|
AIAction(MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
|
||||||
: efficiency(-1), ability(a), player(NULL), click(c), mAbilityTargets(targetCards),playerAbilityTarget(NULL)
|
: ability(a), player(NULL), click(c), mAbilityTargets(targetCards),playerAbilityTarget(NULL)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
id = currentId++;
|
||||||
};
|
};
|
||||||
|
|
||||||
AIAction(MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
|
AIAction(MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
|
||||||
: efficiency(-1), ability(a), click(c),target(NULL), playerAbilityTarget(p)
|
: ability(a), click(c),target(NULL), playerAbilityTarget(p)
|
||||||
{
|
{
|
||||||
id = currentId++;
|
id = currentId++;
|
||||||
};
|
};
|
||||||
int getEfficiency();
|
|
||||||
int Act();
|
int Act();
|
||||||
int clickMultiAct(vector<Targetable*>&actionTargets);
|
int clickMultiAct(vector<Targetable*>&actionTargets);
|
||||||
};
|
};
|
||||||
|
|
||||||
// compares Abilities efficiency
|
|
||||||
class CmpAbilities
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
bool operator()(const AIAction& a1, const AIAction& a2) const
|
|
||||||
{
|
|
||||||
AIAction* a1Ptr = const_cast<AIAction*>(&a1);
|
|
||||||
AIAction* a2Ptr = const_cast<AIAction*>(&a2);
|
|
||||||
int e1 = a1Ptr->getEfficiency();
|
|
||||||
int e2 = a2Ptr->getEfficiency();
|
|
||||||
if (e1 == e2) return a1Ptr->id < a2Ptr->id;
|
|
||||||
return (e1 > e2);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef std::map<AIAction, int, CmpAbilities> RankingContainer;
|
|
||||||
|
|
||||||
class AIPlayer: public Player{
|
class AIPlayer: public Player{
|
||||||
protected:
|
protected:
|
||||||
//Variables used by Test suite
|
|
||||||
MTGCardInstance * nextCardToPlay;
|
|
||||||
AIHints * hints;
|
|
||||||
queue<AIAction *> clickstream;
|
queue<AIAction *> clickstream;
|
||||||
bool payTheManaCost(ManaCost * cost, MTGCardInstance * card = NULL,vector<MTGAbility*> gotPayment = vector<MTGAbility*>());
|
int clickMultiTarget(TargetChooser * tc,vector<Targetable*>&potentialTargets);
|
||||||
int orderBlockers();
|
int clickSingleTarget(TargetChooser * tc,vector<Targetable*>&potentialTargets, MTGCardInstance * Choosencard = NULL);
|
||||||
int combatDamages();
|
|
||||||
int interruptIfICan();
|
|
||||||
int chooseAttackers();
|
|
||||||
int chooseBlockers();
|
|
||||||
int canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy);
|
|
||||||
int effectBadOrGood(MTGCardInstance * card, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL);
|
|
||||||
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
|
|
||||||
AIStats * getStats();
|
|
||||||
|
|
||||||
// returns 1 if the AI algorithm supports a given cost (ex:simple mana cost), 0 otherwise (ex: cost involves Sacrificing a target)
|
|
||||||
int CanHandleCost(ManaCost * cost);
|
|
||||||
|
|
||||||
//Tries to play an ability recommended by the deck creator
|
|
||||||
int selectHintAbility();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
AIStats * stats;
|
|
||||||
|
//These variables are used by TestSuite and Rules.cpp... TODO change that?
|
||||||
int agressivity;
|
int agressivity;
|
||||||
bool forceBestAbilityUse;
|
bool forceBestAbilityUse;
|
||||||
|
|
||||||
void End(){};
|
void End(){};
|
||||||
virtual int displayStack() {return 0;};
|
virtual int displayStack() {return 0;};
|
||||||
int receiveEvent(WEvent * event);
|
virtual int receiveEvent(WEvent * event);
|
||||||
void Render();
|
virtual void Render();
|
||||||
ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
|
|
||||||
vector<MTGAbility*> canPayMana(MTGCardInstance * card = NULL,ManaCost * mCost = NULL);
|
|
||||||
vector<MTGAbility*> canPaySunBurst(ManaCost * mCost = NULL);
|
|
||||||
AIPlayer(string deckFile, string deckFileSmall, MTGDeck * deck = NULL);
|
AIPlayer(string deckFile, string deckFileSmall, MTGDeck * deck = NULL);
|
||||||
virtual ~AIPlayer();
|
virtual ~AIPlayer();
|
||||||
virtual MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
|
|
||||||
virtual int selectMenuOption();
|
virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget = NULL, MTGCardInstance * Chosencard = NULL, bool checkonly = false) = 0;
|
||||||
virtual int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL,MTGCardInstance * Choosencard = NULL,bool checkonly = false);
|
virtual int affectCombatDamages(CombatStep) = 0;
|
||||||
virtual int clickMultiTarget(TargetChooser * tc,vector<Targetable*>&potentialTargets);
|
virtual int Act(float dt) = 0;
|
||||||
virtual int clickSingleTarget(TargetChooser * tc,vector<Targetable*>&potentialTargets,int nbtargets = 0,MTGCardInstance * Choosencard = NULL);
|
|
||||||
virtual int Act(float dt);
|
|
||||||
virtual int affectCombatDamages(CombatStep);
|
|
||||||
int isAI(){return 1;};
|
int isAI(){return 1;};
|
||||||
int canHandleCost(MTGAbility * ability);
|
|
||||||
int selectAbility();
|
|
||||||
int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, RankingContainer& ranking);
|
|
||||||
int useAbility();
|
|
||||||
virtual int getEfficiency(AIAction * action);
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class AIPlayerBaka: public AIPlayer{
|
|
||||||
protected:
|
|
||||||
int oldGamePhase;
|
|
||||||
float timer;
|
|
||||||
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
|
|
||||||
public:
|
|
||||||
vector<MTGAbility*>gotPayments;
|
|
||||||
int deckId;
|
|
||||||
AIPlayerBaka(string deckFile, string deckfileSmall, string avatarFile, MTGDeck * deck = NULL);
|
|
||||||
virtual int Act(float dt);
|
|
||||||
void initTimer();
|
|
||||||
virtual int computeActions();
|
|
||||||
};
|
|
||||||
|
|
||||||
class AIPlayerFactory{
|
class AIPlayerFactory{
|
||||||
public:
|
public:
|
||||||
AIPlayer * createAIPlayer(MTGAllCards * collection, Player * opponent, int deckid = 0);
|
AIPlayer * createAIPlayer(MTGAllCards * collection, Player * opponent, int deckid = 0);
|
||||||
|
|||||||
@@ -0,0 +1,131 @@
|
|||||||
|
#ifndef _AI_PLAYER_BAKA_H_
|
||||||
|
#define _AI_PLAYER_BAKA_H_
|
||||||
|
|
||||||
|
#include "AIPlayer.h"
|
||||||
|
|
||||||
|
class AIStats;
|
||||||
|
class AIHints;
|
||||||
|
|
||||||
|
|
||||||
|
//Would love to define those classes as private nested classes inside of AIPlayerBaka, but they are used by AIHints (which itself should be known only by AIPlayerBaka anyways)
|
||||||
|
// Any way to clean this up and make all the AIPlayerBaka universe (AIHints, AIPlayerBaka, OrderedAIAction) "closed" ?
|
||||||
|
class OrderedAIAction: public AIAction
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
int efficiency;
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
|
||||||
|
OrderedAIAction(MTGAbility * a, MTGCardInstance * c, MTGCardInstance * t = NULL)
|
||||||
|
: AIAction(a, c, t), efficiency(-1)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
OrderedAIAction(MTGCardInstance * c, MTGCardInstance * t = NULL);
|
||||||
|
|
||||||
|
OrderedAIAction(Player * p)//player targeting through spells
|
||||||
|
: AIAction(p), efficiency(-1)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
OrderedAIAction(MTGAbility * a, MTGCardInstance * c, vector<Targetable*>targetCards)
|
||||||
|
: AIAction(a, c, targetCards), efficiency(-1)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
|
||||||
|
OrderedAIAction(MTGAbility * a, Player * p, MTGCardInstance * c)//player targeting through abilities.
|
||||||
|
: AIAction(a, p, c), efficiency(-1)
|
||||||
|
{
|
||||||
|
};
|
||||||
|
int getEfficiency();
|
||||||
|
};
|
||||||
|
|
||||||
|
// compares Abilities efficiency
|
||||||
|
class CmpAbilities
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
bool operator()(const OrderedAIAction& a1, const OrderedAIAction& a2) const
|
||||||
|
{
|
||||||
|
OrderedAIAction* a1Ptr = const_cast<OrderedAIAction*>(&a1);
|
||||||
|
OrderedAIAction* a2Ptr = const_cast<OrderedAIAction*>(&a2);
|
||||||
|
int e1 = a1Ptr->getEfficiency();
|
||||||
|
int e2 = a2Ptr->getEfficiency();
|
||||||
|
if (e1 == e2) return a1Ptr->id < a2Ptr->id;
|
||||||
|
return (e1 > e2);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef std::map<OrderedAIAction, int, CmpAbilities> RankingContainer;
|
||||||
|
|
||||||
|
|
||||||
|
class AIPlayerBaka: public AIPlayer{
|
||||||
|
private:
|
||||||
|
|
||||||
|
MTGCardInstance * nextCardToPlay;
|
||||||
|
AIHints * hints;
|
||||||
|
AIStats * stats;
|
||||||
|
|
||||||
|
int orderBlockers();
|
||||||
|
int combatDamages();
|
||||||
|
int interruptIfICan();
|
||||||
|
int chooseAttackers();
|
||||||
|
int chooseBlockers();
|
||||||
|
int canFirstStrikeKill(MTGCardInstance * card, MTGCardInstance *ennemy);
|
||||||
|
int effectBadOrGood(MTGCardInstance * card, int mode = MODE_PUTINTOPLAY, TargetChooser * tc = NULL);
|
||||||
|
|
||||||
|
|
||||||
|
// returns 1 if the AI algorithm supports a given cost (ex:simple mana cost), 0 otherwise (ex: cost involves Sacrificing a target)
|
||||||
|
int CanHandleCost(ManaCost * cost);
|
||||||
|
|
||||||
|
//Tries to play an ability recommended by the deck creator
|
||||||
|
int selectHintAbility();
|
||||||
|
|
||||||
|
vector<MTGAbility*> canPayMana(MTGCardInstance * card = NULL,ManaCost * mCost = NULL);
|
||||||
|
vector<MTGAbility*> canPaySunBurst(ManaCost * mCost = NULL);
|
||||||
|
|
||||||
|
MTGCardInstance * chooseCard(TargetChooser * tc, MTGCardInstance * source, int random = 0);
|
||||||
|
int selectMenuOption();
|
||||||
|
int useAbility();
|
||||||
|
|
||||||
|
AIStats * getStats();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
int oldGamePhase;
|
||||||
|
float timer;
|
||||||
|
MTGCardInstance * FindCardToPlay(ManaCost * potentialMana, const char * type);
|
||||||
|
|
||||||
|
//used by MomirPlayer, hence protected instead of private
|
||||||
|
virtual int getEfficiency(OrderedAIAction * action);
|
||||||
|
bool payTheManaCost(ManaCost * cost, MTGCardInstance * card = NULL,vector<MTGAbility*> gotPayment = vector<MTGAbility*>());
|
||||||
|
int getCreaturesInfo(Player * player, int neededInfo = INFO_NBCREATURES , int untapMode = 0, int canAttack = 0);
|
||||||
|
ManaCost * getPotentialMana(MTGCardInstance * card = NULL);
|
||||||
|
int selectAbility();
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum {
|
||||||
|
INFO_NBCREATURES,
|
||||||
|
INFO_CREATURESPOWER,
|
||||||
|
INFO_CREATURESRANK,
|
||||||
|
INFO_CREATURESTOUGHNESS,
|
||||||
|
INFO_CREATURESATTACKINGPOWER
|
||||||
|
};
|
||||||
|
|
||||||
|
vector<MTGAbility*>gotPayments;
|
||||||
|
int deckId;
|
||||||
|
AIPlayerBaka(string deckFile, string deckfileSmall, string avatarFile, MTGDeck * deck = NULL);
|
||||||
|
virtual int Act(float dt);
|
||||||
|
void initTimer();
|
||||||
|
virtual int computeActions();
|
||||||
|
virtual void Render();
|
||||||
|
virtual int receiveEvent(WEvent * event);
|
||||||
|
virtual ~AIPlayerBaka();
|
||||||
|
int affectCombatDamages(CombatStep step);
|
||||||
|
int canHandleCost(MTGAbility * ability);
|
||||||
|
int chooseTarget(TargetChooser * tc = NULL, Player * forceTarget =NULL,MTGCardInstance * Choosencard = NULL,bool checkonly = false);
|
||||||
|
|
||||||
|
//used by AIHInts, therefore public instead of private :/
|
||||||
|
int createAbilityTargets(MTGAbility * a, MTGCardInstance * c, RankingContainer& ranking);
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -6,7 +6,7 @@
|
|||||||
#define MAX_TESTSUITE_ACTIONS 100
|
#define MAX_TESTSUITE_ACTIONS 100
|
||||||
#define MAX_TESTUITE_CARDS 100
|
#define MAX_TESTUITE_CARDS 100
|
||||||
|
|
||||||
#include "AIPlayer.h"
|
#include "AIPlayerBaka.h"
|
||||||
|
|
||||||
class TestSuiteActions
|
class TestSuiteActions
|
||||||
{
|
{
|
||||||
@@ -95,6 +95,7 @@ public:
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO This should inherit from AIPlayer instead!
|
||||||
class TestSuiteAI:public AIPlayerBaka
|
class TestSuiteAI:public AIPlayerBaka
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
#include "PrecompiledHeader.h"
|
#include "PrecompiledHeader.h"
|
||||||
|
|
||||||
#include "AIHints.h"
|
#include "AIHints.h"
|
||||||
#include "AIPlayer.h"
|
#include "AIPlayerBaka.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
#include "AllAbilities.h"
|
#include "AllAbilities.h"
|
||||||
|
|
||||||
@@ -33,7 +33,7 @@ AIHint::AIHint(string _line)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
AIHints::AIHints(AIPlayer * player): mPlayer(player)
|
AIHints::AIHints(AIPlayerBaka * player): mPlayer(player)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ AIMomirPlayer::AIMomirPlayer(string file, string fileSmall, string avatarFile, M
|
|||||||
agressivity = 100;
|
agressivity = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AIMomirPlayer::getEfficiency(AIAction * action)
|
int AIMomirPlayer::getEfficiency(OrderedAIAction * action)
|
||||||
{
|
{
|
||||||
MTGAbility * ability = action->ability;
|
MTGAbility * ability = action->ability;
|
||||||
ManaCost * cost = ability->getCost();
|
ManaCost * cost = ability->getCost();
|
||||||
|
|||||||
+13
-2255
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -97,7 +97,33 @@ void GameApp::Create()
|
|||||||
|
|
||||||
WResourceManager::Instance()->ResetCacheLimits();
|
WResourceManager::Instance()->ResetCacheLimits();
|
||||||
|
|
||||||
JFileSystem::init("User/", "Res/");
|
string systemFolder = "Res/";
|
||||||
|
string foldersRoot = "";
|
||||||
|
|
||||||
|
//Find the Res folder
|
||||||
|
ifstream mfile("Res.txt");
|
||||||
|
string resPath;
|
||||||
|
if (mfile)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
while (!found && std::getline(mfile, resPath))
|
||||||
|
{
|
||||||
|
if (resPath[resPath.size() - 1] == '\r')
|
||||||
|
resPath.erase(resPath.size() - 1); //Handle DOS files
|
||||||
|
string testfile = resPath + systemFolder;
|
||||||
|
testfile.append("graphics/simon.dat");
|
||||||
|
ifstream tempfile(testfile.c_str());
|
||||||
|
if (tempfile)
|
||||||
|
{
|
||||||
|
found = true;
|
||||||
|
tempfile.close();
|
||||||
|
foldersRoot = resPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mfile.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
JFileSystem::init(foldersRoot + "User/", foldersRoot + systemFolder);
|
||||||
|
|
||||||
// Create User Folders (for write access) if they don't exist
|
// Create User Folders (for write access) if they don't exist
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1470,7 +1470,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG
|
|||||||
{
|
{
|
||||||
MTGCard * safetycard = MTGCollection()->getCardById(tokenId);
|
MTGCard * safetycard = MTGCollection()->getCardById(tokenId);
|
||||||
if (!safetycard) //Error, card not foudn in DB
|
if (!safetycard) //Error, card not foudn in DB
|
||||||
return NEW ATokenCreator(id, card, target, NULL, "ID NOT FOUND", "ERROR ID",0, 0, "",0, NULL,0);
|
return NEW ATokenCreator(id, card, target, NULL, "ID NOT FOUND", "ERROR ID",0, 0, "","", NULL,0);
|
||||||
|
|
||||||
ATokenCreator * tok = NEW ATokenCreator(id, card,target, NULL, tokenId, starfound, multiplier, who);
|
ATokenCreator * tok = NEW ATokenCreator(id, card,target, NULL, tokenId, starfound, multiplier, who);
|
||||||
tok->oneShot = 1;
|
tok->oneShot = 1;
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
#include "MTGDefinitions.h"
|
#include "MTGDefinitions.h"
|
||||||
#include "WResourceManager.h"
|
#include "WResourceManager.h"
|
||||||
#include "AIPlayer.h"
|
#include "AIPlayer.h"
|
||||||
|
|
||||||
|
//TODO remove this dependency
|
||||||
|
#include "AIPlayerBaka.h"
|
||||||
|
|
||||||
#include "Rules.h"
|
#include "Rules.h"
|
||||||
#include "Credits.h"
|
#include "Credits.h"
|
||||||
#include "PlayerData.h"
|
#include "PlayerData.h"
|
||||||
|
|||||||
@@ -263,7 +263,6 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta
|
|||||||
string numberCD = attribute.substr(operatorPosition + 1, attribute.size() - operatorPosition - 1);
|
string numberCD = attribute.substr(operatorPosition + 1, attribute.size() - operatorPosition - 1);
|
||||||
WParsedInt * val = NEW WParsedInt(numberCD,NULL, card);
|
WParsedInt * val = NEW WParsedInt(numberCD,NULL, card);
|
||||||
comparisonCriterion = val->getValue();
|
comparisonCriterion = val->getValue();
|
||||||
/*atoi(attribute.substr(operatorPosition + 1, attribute.size() - operatorPosition - 1).c_str());*/
|
|
||||||
delete val;
|
delete val;
|
||||||
switch (attribute[operatorPosition - 1])
|
switch (attribute[operatorPosition - 1])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,6 +4,10 @@
|
|||||||
#include "Player.h"
|
#include "Player.h"
|
||||||
#include "Tasks.h"
|
#include "Tasks.h"
|
||||||
#include "AIPlayer.h"
|
#include "AIPlayer.h"
|
||||||
|
|
||||||
|
// Todo remove this dependency!
|
||||||
|
#include "AIPlayerBaka.h"
|
||||||
|
|
||||||
#include "Translate.h"
|
#include "Translate.h"
|
||||||
#include "MTGDefinitions.h"
|
#include "MTGDefinitions.h"
|
||||||
#include <JRenderer.h>
|
#include <JRenderer.h>
|
||||||
|
|||||||
@@ -391,7 +391,7 @@ void TestSuite::initGame()
|
|||||||
g->currentGamePhase = initState.phase;
|
g->currentGamePhase = initState.phase;
|
||||||
for (int i = 0; i < 2; i++)
|
for (int i = 0; i < 2; i++)
|
||||||
{
|
{
|
||||||
AIPlayer * p = (AIPlayer *) (g->players[i]);
|
AIPlayerBaka * p = (AIPlayerBaka *) (g->players[i]);
|
||||||
p->forceBestAbilityUse = forceAbility;
|
p->forceBestAbilityUse = forceAbility;
|
||||||
p->life = initState.playerData[i].life;
|
p->life = initState.playerData[i].life;
|
||||||
MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay };
|
MTGGameZone * playerZones[] = { p->game->graveyard, p->game->library, p->game->hand, p->game->inPlay };
|
||||||
|
|||||||
@@ -308,6 +308,8 @@
|
|||||||
<ClCompile Include="src\AIHints.cpp" />
|
<ClCompile Include="src\AIHints.cpp" />
|
||||||
<ClCompile Include="src\AIMomirPlayer.cpp" />
|
<ClCompile Include="src\AIMomirPlayer.cpp" />
|
||||||
<ClCompile Include="src\AIPlayer.cpp" />
|
<ClCompile Include="src\AIPlayer.cpp" />
|
||||||
|
<ClCompile Include="src\AIPlayerBaka.cpp" />
|
||||||
|
<ClCompile Include="src\AIPlayerBakaB.cpp" />
|
||||||
<ClCompile Include="src\AIStats.cpp" />
|
<ClCompile Include="src\AIStats.cpp" />
|
||||||
<ClCompile Include="src\AllAbilities.cpp" />
|
<ClCompile Include="src\AllAbilities.cpp" />
|
||||||
<ClCompile Include="src\CardDescriptor.cpp" />
|
<ClCompile Include="src\CardDescriptor.cpp" />
|
||||||
@@ -442,6 +444,8 @@
|
|||||||
<ClInclude Include="include\AIHints.h" />
|
<ClInclude Include="include\AIHints.h" />
|
||||||
<ClInclude Include="include\AIMomirPlayer.h" />
|
<ClInclude Include="include\AIMomirPlayer.h" />
|
||||||
<ClInclude Include="include\AIPlayer.h" />
|
<ClInclude Include="include\AIPlayer.h" />
|
||||||
|
<ClInclude Include="include\AIPlayerBaka.h" />
|
||||||
|
<ClInclude Include="include\AIPlayerBakaB.h" />
|
||||||
<ClInclude Include="include\AIStats.h" />
|
<ClInclude Include="include\AIStats.h" />
|
||||||
<ClInclude Include="include\AllAbilities.h" />
|
<ClInclude Include="include\AllAbilities.h" />
|
||||||
<ClInclude Include="include\CacheEngine.h" />
|
<ClInclude Include="include\CacheEngine.h" />
|
||||||
|
|||||||
@@ -313,6 +313,12 @@
|
|||||||
<ClCompile Include="src\PriceList.cpp">
|
<ClCompile Include="src\PriceList.cpp">
|
||||||
<Filter>src</Filter>
|
<Filter>src</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\AIPlayerBaka.cpp">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
|
<ClCompile Include="src\AIPlayerBakaB.cpp">
|
||||||
|
<Filter>src</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="include\ActionElement.h">
|
<ClInclude Include="include\ActionElement.h">
|
||||||
@@ -651,6 +657,12 @@
|
|||||||
<ClInclude Include="include\IconButton.h">
|
<ClInclude Include="include\IconButton.h">
|
||||||
<Filter>inc</Filter>
|
<Filter>inc</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\AIPlayerBaka.h">
|
||||||
|
<Filter>inc</Filter>
|
||||||
|
</ClInclude>
|
||||||
|
<ClInclude Include="include\AIPlayerBakaB.h">
|
||||||
|
<Filter>inc</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="Makefile" />
|
<None Include="Makefile" />
|
||||||
|
|||||||
@@ -51,6 +51,7 @@ SOURCES += \
|
|||||||
src/AIHints.cpp\
|
src/AIHints.cpp\
|
||||||
src/AIMomirPlayer.cpp\
|
src/AIMomirPlayer.cpp\
|
||||||
src/AIPlayer.cpp\
|
src/AIPlayer.cpp\
|
||||||
|
src/AIPlayerBaka.cpp\
|
||||||
src/AIStats.cpp\
|
src/AIStats.cpp\
|
||||||
src/AllAbilities.cpp\
|
src/AllAbilities.cpp\
|
||||||
src/CardDescriptor.cpp\
|
src/CardDescriptor.cpp\
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ SOURCES += \
|
|||||||
src/AIHints.cpp\
|
src/AIHints.cpp\
|
||||||
src/AIMomirPlayer.cpp\
|
src/AIMomirPlayer.cpp\
|
||||||
src/AIPlayer.cpp\
|
src/AIPlayer.cpp\
|
||||||
|
src/AIPlayerBaka.cpp\
|
||||||
src/AIStats.cpp\
|
src/AIStats.cpp\
|
||||||
src/AllAbilities.cpp\
|
src/AllAbilities.cpp\
|
||||||
src/CardDescriptor.cpp\
|
src/CardDescriptor.cpp\
|
||||||
|
|||||||
Reference in New Issue
Block a user