Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members

AIFSM.h

Go to the documentation of this file.
00001 
00002 //      Copyright (C) 2004 Dylan Blair
00003 //
00004 //      email: dblair@alumni.cs.utexas.edu
00005 //
00006 //      This library is free software; you can redistribute it and/or
00007 //      modify it under the terms of the GNU Lesser General Public
00008 //      License as published by the Free Software Foundation; either
00009 //      version 2.1 of the License, or (at your option) any later version.
00010 //
00011 //      This library is distributed in the hope that it will be useful,
00012 //      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 //      Lesser General Public License for more details.
00015 //
00016 //      You should have received a copy of the GNU Lesser General Public
00017 //      License along with this library; if not, write to the Free Software
00018 //      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020 
00021 #ifndef AIFSM_H
00022 #define AIFSM_H
00023 
00024 #include "AIBase.h"
00025 
00040 class AIState {
00041 public:
00042         int                   stateID;
00043         std::vector<AIAction> theactions;
00044         std::vector<int>      inputs;
00045         std::vector<AIState*> next;
00046 
00047         AIState(int stateID_=-1, std::vector<AIAction> theactions_=std::vector<AIAction>());
00048         AIState* returnNextState(int input_);
00049 
00050         int serialize(std::ofstream& fout_) const;
00051         int assemble(std::ifstream& fin_, std::vector<int>& nextStateIDs_);
00052 };
00053 
00057 extern std::vector<AIState> states;
00058 
00070 class AIFSM {
00071         static bool areGlobalStatesSerialized;
00072         static bool areGlobalStatesAssembled;
00073         AI_FSM_IDS  FSMID;
00074         bool        isInitialStateSet;
00075         int         statesindex;
00076         AIState*    thestates[AI_FSM_STATE_MAX];
00077 public:
00082         AIFSM(AI_FSM_IDS FSMID_);
00083         AIFSM(AI_FSM_IDS FSMID_, AIState& initialstate_);
00084 
00088         AI_FSM_IDS getFSMID() const { return FSMID; }
00089 
00098         bool setInitialState(AIState& initialstate_);
00099 
00105         AIState*& getInitialState() { return thestates[0]; }
00106 
00114         bool addState(AIState& currentstate_, int input_, AIState& nextstate_);
00115 
00120         AIState* getStateByID(int ID_) const;
00121 
00127         static void initAIFSMFileIO() {
00128                 areGlobalStatesSerialized = false;
00129                 areGlobalStatesAssembled = false;
00130         }
00131 
00137         int serialize(std::ofstream& fout_) const;
00138 
00144         int assemble(std::ifstream& fin_);
00145 };
00146 
00150 namespace AIFileIO {
00157         template <>
00158         int serialize(std::ofstream& fout_, const std::vector<AIState>& stateVector_);
00159 
00166         template <>
00167         int assemble(std::ifstream& fin_, std::vector<AIState>& stateVector_);
00168 }
00169 
00170 #endif //AIFSM_H

Generated on Sun Apr 11 05:05:55 2004 for FSM_API by doxygen 1.3.6