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
AIFSM.h
Go to the documentation of this file.
1 // Copyright (C) 2004-2008 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 AIFSM_H
22 #define AIFSM_H
23 
24 #include "AIBase.h"
25 
33 namespace OpenSkyNet {
34  namespace AI {
42  class State {
43  public:
44  int _stateId;
45  std::vector<Action> _actions;
46  std::vector<int> _inputs;
47  std::vector<State*> _next;
48 
49  State(int stateId_=-1) : _stateId(stateId_) {}
50  State(int stateId_, const std::vector<Action>& actions_) : _stateId(stateId_), _actions(actions_) {}
51 
52  State* getNextState(int input_);
53 
54  int serialize(std::ofstream& fout_) const;
55  int assemble(std::ifstream& fin_, std::vector<int>& nextStateIds_);
56  };
57 
61  extern std::vector<State> g_states;
62 
74  class FSM {
75  static bool _areGlobalStatesSerialized;
76  static bool _areGlobalStatesAssembled;
77  FSM_IDS _fSMId;
78  bool _isInitialStateSet;
79  int _statesIndex;
80  State* _states[FSM_STATE_MAX];
81  public:
86  FSM(FSM_IDS fSMId_);
87  FSM(FSM_IDS fSMId_, State& initialState_);
88 
92  inline FSM_IDS getFSMId() const { return _fSMId; }
93 
102  bool setInitialState(State& initialState_);
103 
109  inline State*& getInitialState() { return _states[0]; }
110 
118  bool addState(State& currState_, int input_, State& nextState_);
119 
124  State* getStateById(int Id_) const;
125 
131  static void initAIFSMFileIO() {
132  _areGlobalStatesSerialized = false;
133  _areGlobalStatesAssembled = false;
134  }
135 
141  int serialize(std::ofstream& fout_) const;
142 
148  int assemble(std::ifstream& fin_);
149  };
150 
151  namespace FileIO {
158  template <>
159  int serialize(std::ofstream& fout_, const std::vector<State>& stateVector_);
160 
167  template <>
168  int assemble(std::ifstream& fin_, std::vector<State>& stateVector_);
169  }
170  }
171 }
172 
173 #endif //AIFSM_H
bool addState(State &currState_, int input_, State &nextState_)
Definition: AIFSM.cpp:92
vector< State > g_states
Definition: AIFSM.cpp:64
Definition: AIFSM.h:74
bool setInitialState(State &initialState_)
Definition: AIFSM.cpp:83
State *& getInitialState()
Definition: AIFSM.h:109
const int FSM_STATE_MAX
Definition: AIConsts.h:26
int serialize(std::ofstream &fout_) const
Definition: AIFSM.cpp:136
State * getNextState(int input_)
Definition: AIFSM.cpp:9
int serialize(std::ofstream &fout_) const
Definition: AIFSM.cpp:18
int serialize(std::ofstream &fout_, const std::vector< T > &vector_)
Definition: AIBase.h:193
int _stateId
Definition: AIFSM.h:44
State(int stateId_, const std::vector< Action > &actions_)
Definition: AIFSM.h:50
std::vector< int > _inputs
Definition: AIFSM.h:46
std::vector< State * > _next
Definition: AIFSM.h:47
int assemble(std::ifstream &fin_, std::vector< T > &vector_)
Definition: AIBase.h:218
State * getStateById(int Id_) const
Definition: AIFSM.cpp:129
FSM_IDS
Definition: AIConsts.h:28
Definition: AIFSM.h:42
static void initAIFSMFileIO()
Definition: AIFSM.h:131
FSM(FSM_IDS fSMId_)
Definition: AIFSM.cpp:71
FSM_IDS getFSMId() const
Definition: AIFSM.h:92
Premise, Action, and Record.
State(int stateId_=-1)
Definition: AIFSM.h:49
std::vector< Action > _actions
Definition: AIFSM.h:45
int assemble(std::ifstream &fin_)
Definition: AIFSM.cpp:165
int assemble(std::ifstream &fin_, std::vector< int > &nextStateIds_)
Definition: AIFSM.cpp:39