00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020
00021 #ifndef AIBASE_H
00022 #define AIBASE_H
00023
00024 #include "AIConsts.h"
00025
00037 class AIPremise {
00038 public:
00039 std::vector<int> params;
00040 float entrytime;
00041 bool negated;
00042
00047 AIPremise(std::vector<int> params_=std::vector<int>());
00048
00053 virtual bool operator==(const AIPremise& rhs) const;
00054
00059 virtual bool equals(const AIPremise& rhs, int numparamstocheck_) const;
00060
00065 AIPremise& operator=(int param_) {
00066 params.clear();
00067 params.push_back(param_);
00068 entrytime = -1.0f;
00069 negated = false;
00070 return *this;
00071 }
00072
00077 AIPremise& operator+=(int param_) {
00078 params.push_back(param_);
00079 return *this;
00080 }
00081
00087 virtual int serialize(std::ofstream& fout_) const;
00088
00094 virtual int assemble(std::ifstream& fin_);
00095
00096 virtual ~AIPremise() {}
00097 };
00098
00102 class AIAction : public AIPremise {
00103 public:
00104 AIAction(std::vector<int> params_=std::vector<int>());
00105
00106 AIAction& operator=(int param_) {
00107 AIPremise::operator=(param_);
00108 return *this;
00109 }
00110
00111 AIAction& operator+=(int param_) {
00112 AIPremise::operator+=(param_);
00113 return *this;
00114 }
00115
00116 virtual ~AIAction() {}
00117 };
00118
00119 class AIWrapper;
00120
00125 class AIException : public AIPremise {
00126 public:
00127 AIWrapper* n;
00128 float badgoodscalevalue;
00129 int stateIDduringexception;
00130
00131 AIException(std::vector<int> params_=std::vector<int>(), AIWrapper* n_=0, float badgoodscalevalue_=0.0f,
00132 int stateIDduringexception_=-1);
00133
00138 AIException& operator=(int param_) {
00139 AIPremise::operator=(param_);
00140 return *this;
00141 }
00142
00143 AIException& operator+=(int param_) {
00144 AIPremise::operator+=(param_);
00145 return *this;
00146 }
00147
00148 virtual ~AIException() {}
00149 };
00150
00154 namespace AIFileIO {
00161 template <class T>
00162 int serialize(std::ofstream& fout_, const std::vector<T>& vector_) {
00163 static const unsigned int sizeoftype = sizeof(T);
00164 unsigned int byteswritten = 0;
00165 unsigned int vectorsize = vector_.size();
00166
00167 fout_.write((char*)&vectorsize,sizeoftype);
00168 byteswritten += sizeoftype;
00169
00170 for (int i = 0; i < vectorsize; i++)
00171 fout_.write((char*)&(vector_[i]),sizeoftype);
00172 byteswritten += vectorsize*sizeoftype;
00173
00174 return byteswritten;
00175 }
00176
00183 template <class T>
00184 int assemble(std::ifstream& fin_, std::vector<T>& vector_) {
00185 static const unsigned int sizeoftype = sizeof(T);
00186 unsigned int bytesread = 0;
00187 unsigned int vectorsize = 0;
00188 vector_.clear();
00189
00190 fin_.read((char*)&vectorsize,sizeoftype);
00191 bytesread += sizeoftype;
00192
00193 vector_.resize(vectorsize);
00194 for (int i = 0; i < vectorsize; i++)
00195 fin_.read((char*)&(vector_[i]),sizeoftype);
00196 bytesread += vectorsize*sizeoftype;
00197
00198 return bytesread;
00199 }
00200
00207 template <>
00208 int serialize(std::ofstream& fout_, const std::vector<AIPremise>& premVector_);
00209
00216 template <>
00217 int assemble(std::ifstream& fin_, std::vector<AIPremise>& premVector_);
00218
00225 template <>
00226 int serialize(std::ofstream& fout_, const std::vector<AIAction>& actVector_);
00227
00234 template <>
00235 int assemble(std::ifstream& fin_, std::vector<AIAction>& actVector_);
00236 }
00237
00238 #endif //AIBASE_H