00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "nel/ai/logic/bool_cond.h"
00021
00022 namespace NLAILOGIC
00023 {
00024 using namespace NLAIAGENT;
00025
00026 IBaseCond::IBaseCond()
00027 {
00028 }
00029
00030 IBaseCond::IBaseCond(std::list<IBaseBoolType *> &conds)
00031 {
00032 std::list<IBaseBoolType *>::iterator it_c = conds.begin();
00033 while ( it_c != conds.end() )
00034 {
00035 _Conds.push_back( (IBaseBoolType *) (*it_c)->clone() );
00036 it_c++;
00037 }
00038 }
00039
00040 IBaseCond::~IBaseCond()
00041 {
00042 std::list<IBaseBoolType *>::iterator it_c = _Conds.begin();
00043 while ( it_c != _Conds.end() )
00044 {
00045 ( *it_c )->release();
00046 it_c++;
00047 }
00048 }
00049
00050 void IBaseCond::addCond(IBaseBoolType *cond)
00051 {
00052 _Conds.push_back( (IBaseBoolType *) cond->clone() );
00053 }
00054
00055 CondAnd::CondAnd()
00056 {
00057 }
00058
00059 CondAnd::CondAnd(std::list<IBaseBoolType *> &conds) : IBaseCond( conds )
00060 {
00061 }
00062
00063 float CondAnd::truthValue() const
00064 {
00065 float truth = 1.0;
00066 std::list<IBaseBoolType *>::const_iterator it_c = _Conds.begin();
00067 while ( it_c != _Conds.end() )
00068 {
00069 if ( ( *it_c )->truthValue() < truth )
00070 truth = ( *it_c )->truthValue();
00071 }
00072 return truth;
00073 };
00074
00075 bool CondAnd::isTrue()
00076 {
00077 std::list<IBaseBoolType *>::iterator it_c = _Conds.begin();
00078 while ( it_c != _Conds.end() )
00079 {
00080 if ( ! ( *it_c )->isTrue() )
00081 return false;
00082 }
00083 return true;
00084 }
00085
00086 CondOr::CondOr()
00087 {
00088 }
00089
00090 CondOr::CondOr(std::list<IBaseBoolType *> &conds) : IBaseCond( conds )
00091 {
00092 }
00093
00094 float CondOr::truthValue() const
00095 {
00096 float truth = 0.0;
00097 std::list<IBaseBoolType *>::const_iterator it_c = _Conds.begin();
00098 while ( it_c != _Conds.end() )
00099 {
00100 if ( ( *it_c )->truthValue() > truth )
00101 truth = ( *it_c )->truthValue();
00102 }
00103 return truth;
00104 };
00105
00106 bool CondOr::isTrue()
00107 {
00108 std::list<IBaseBoolType *>::iterator it_c = _Conds.begin();
00109 while ( it_c != _Conds.end() )
00110 {
00111 if ( ! ( *it_c )->isTrue() )
00112 return true;
00113 }
00114 return false;
00115 }
00116 }