Tactics: Western Philosophers Vs. Musicians  0.12
A turn-based tactical game combining rules and gameplay elements inspired by Final Fantasy Tactics and the Mayfair Exponential Game System. Unlike most games of this type, motion is in full, grid-less 3D.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
AILogic.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2007 Dylan Blair
3 //
4 // email: dblair@alumni.cs.utexas.edu
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 
21 #ifndef AILOGIC_H
22 #define AILOGIC_H
23 
24 #include "AIFSM.h"
25 #include "AIKB.h"
26 
27 namespace OpenSkyNet {
28  namespace AI {
29  extern KB* g_kB;
30 
35  class Logic {
36  public:
37  //I would prefer Rule to be private, but I don't know how to make it accessible
38  //for the explicitly instantiated versions of FileIO::serialize and
39  //FileIO::assemble declared below.
40  struct Rule {
41  std::vector<Premise> _antecedents;
42  std::vector<int> _numOfParamsInAntecsToCheck;
44  std::vector<int> _timesFound;
45  std::vector<bool> _acceptOnlyNewSinceStateChange;
46  std::vector<float> _secondsOld;
47  std::vector<Premise> _conseKBPrems;
48  std::vector<Premise> _remKBPrems;
49  std::vector<bool> _remAll;
50 
51  int serialize(std::ofstream& fout_) const;
52  int assemble(std::ifstream& fin_);
53  };
54  private:
55  LOGIC_IDS _logicId;
56  std::vector<Rule> _rules;
57  int _maxRules;
58 
59  void checkPremises(const std::list<Record>& premsToCheck_, int& antecIndex_, float& timeStamp_);
60 
64  bool antecCheck, allAntecsCheck, doChangeState, ruleCheck, returnVal;
65  int countFound, findThisMany, rulesSize, premsSize, stateInputsSize;
66  int* stateInput;
67  float currTime;
68  Rule* currRule;
69  Premise* currPrem;
70  Record record;
71  public:
77  Logic(LOGIC_IDS logicId_, const int maxRules_=-1);
78 
82  inline LOGIC_IDS getLogicId() const { return _logicId; }
83 
99  bool createDerivationRule(const std::vector<Premise>& antecedents_,
100  const std::vector<int>& numOfParamsInAntecsToCheck_,
101  int consequentStateInput_,
102  const std::vector<int>& timesFound_,
103  const std::vector<bool>& acceptOnlyNewSinceStateChange_,
104  const std::vector<float>& secondsOld_,
105  const std::vector<Premise>& conseKBPrems_,
106  const std::vector<Premise>& remKBPrems_,
107  const std::vector<bool>& remAll_);
108 
116  bool performLogic(State*& state_, KB*& kB_, float& timeStamp_,
117  bool includeGlobalKB_=false);
118 
124  int serialize(std::ofstream& fout_) const;
125 
131  int assemble(std::ifstream& fin_);
132  };
133 
134  namespace FileIO {
141  template <>
142  int serialize(std::ofstream& fout_, const std::vector<Logic::Rule>& ruleVector_);
143 
150  template <>
151  int assemble(std::ifstream& fin_, std::vector<Logic::Rule>& ruleVector_);
152  }
153  }
154 }
155 
156 #endif //AILOGIC_H
Definition: AIBase.h:148
int serialize(std::ofstream &fout_) const
Definition: AILogic.cpp:231
KB * g_kB
Definition: AIManager.cpp:10
std::vector< int > _numOfParamsInAntecsToCheck
Definition: AILogic.h:42
int serialize(std::ofstream &fout_, const std::vector< T > &vector_)
Definition: AIBase.h:193
std::vector< Premise > _conseKBPrems
Definition: AILogic.h:47
int assemble(std::ifstream &fin_)
Definition: AILogic.cpp:32
Definition: AIKB.h:33
std::vector< float > _secondsOld
each float is how many secs ago to accept premises for this antec
Definition: AILogic.h:46
bool createDerivationRule(const std::vector< Premise > &antecedents_, const std::vector< int > &numOfParamsInAntecsToCheck_, int consequentStateInput_, const std::vector< int > &timesFound_, const std::vector< bool > &acceptOnlyNewSinceStateChange_, const std::vector< float > &secondsOld_, const std::vector< Premise > &conseKBPrems_, const std::vector< Premise > &remKBPrems_, const std::vector< bool > &remAll_)
Definition: AILogic.cpp:53
State, FSM.
std::vector< bool > _remAll
for each premise to be removed, remove all of its type?
Definition: AILogic.h:49
int assemble(std::ifstream &fin_, std::vector< T > &vector_)
Definition: AIBase.h:218
int serialize(std::ofstream &fout_) const
Definition: AILogic.cpp:13
std::vector< bool > _acceptOnlyNewSinceStateChange
Definition: AILogic.h:45
Definition: AIBase.h:52
Definition: AILogic.h:40
Logic(LOGIC_IDS logicId_, const int maxRules_=-1)
Definition: AILogic.cpp:51
LOGIC_IDS getLogicId() const
Definition: AILogic.h:82
std::vector< Premise > _remKBPrems
Definition: AILogic.h:48
LOGIC_IDS
Definition: AIConsts.h:32
Definition: AILogic.h:35
std::vector< Premise > _antecedents
Definition: AILogic.h:41
Definition: AIFSM.h:42
bool performLogic(State *&state_, KB *&kB_, float &timeStamp_, bool includeGlobalKB_=false)
returns true if state_ changed, false otherwise
Definition: AILogic.cpp:144
std::vector< int > _timesFound
Definition: AILogic.h:44
int assemble(std::ifstream &fin_)
Definition: AILogic.cpp:241
int _consequentStateInput
Definition: AILogic.h:43