📄 cognitive.cpp.svn-base
字号:
/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "Cognitive.h"Cognitive::Cognitive(){ cout << "inicializacao do Cognitivo" << endl; mInferenceEngine.loadFacts(&mFactsBase); mInferenceEngine.loadRules(&mRulesBase); mFactsBase.addLogicPattern("local_goal", "current", "none"); mFactsBase.addLogicPattern("local_goal", "status", "active"); mFactsBase.addLogicPattern("global_goal", "current", "none"); mFactsBase.addLogicPattern("global_goal", "status", "active"); mFactsBase.addLogicPattern("ball","localization","AREA_ILLEGAL"); mFactsBase.addLogicPattern("teammate","has_ball","false"); mFactsBase.addLogicPattern("dead_ball","situation","none"); /*cout << " Cognitive Base " << endl; mFactsBase.print();*/ WM = WorldModel::getInstance();}void Cognitive::loadRulesBase(){ string fileName; // convertendo inteiro em string com strigstream stringstream ss; string playerNumber; ss << WM->getPlayerNumber(); ss >> playerNumber; fileName = RulesBase::RulesPath + "cognitive" + playerNumber + ".rules"; cout <<"cognitive rules file: "<< fileName << endl; mRulesBase.loadRulesFile( (char*)fileName.c_str() ); //Impressao da base de regras //mRulesBase.print();}string Cognitive::makeInference(LocalGoal lc, string ballLocalization){ // gera mensagem para escolha do comportamento /*if( updateFactsBase(lc,ballLocalization) ) { if ( WM->getPlayerNumber() == 9 ) mFactsBase.print(); }*/ updateFactsBase(lc,ballLocalization); mInferenceEngine.inference(); mLocalGoal.current = mInferenceEngine.getLocalGoalCurrent(); if ( mLocalGoal.current.empty() ) mLocalGoal.current = "none"; mLocalGoal.status = mInferenceEngine.getLocalGoalStatus(); if ( mLocalGoal.status.empty() ) mLocalGoal.status = "none" ; return mInferenceEngine.getOutputMessage();}LocalGoal Cognitive::getLocalGoal(){ return mLocalGoal;}bool Cognitive::updateFactsBase(LocalGoal lc, string ballLocalization){ bool bNovaMsg = false; bool ballOurPossesion = WM->isBallInOurPossesion(); string deadBall = ModeUsOrThem(); if ( (lc.current != "none") and (lc.status != "none") ) { mFactsBase.addLogicPattern("local_goal", "current", lc.current ); mFactsBase.addLogicPattern("local_goal", "status", lc.status ); bNovaMsg = true; } if( pastBallLocalization != ballLocalization ) { if( ballLocalization == "AREA_ATTACK" ) mFactsBase.addLogicPattern("ball","localization","AREA_ATTACK"); else if( ballLocalization == "AREA_DEFENSE" ) mFactsBase.addLogicPattern("ball","localization","AREA_DEFENSE"); else if( ballLocalization == "AREA_SIDE" ) mFactsBase.addLogicPattern("ball","localization","AREA_SIDE"); else if( ballLocalization == "AREA_SIDE_ATTACK" ) mFactsBase.addLogicPattern("ball","localization","AREA_SIDE_ATTACK"); else if( ballLocalization == "AREA_SIDE_DEFENSE" ) mFactsBase.addLogicPattern("ball","localization","AREA_SIDE_DEFENSE"); else if( ballLocalization == "AREA_CENTRAL" ) mFactsBase.addLogicPattern("ball","localization","AREA_CENTRAL"); else if( ballLocalization == "AREA_CENTRAL_ATTACK" ) mFactsBase.addLogicPattern("ball","localization","AREA_CENTRAL_ATTACK"); else if( ballLocalization == "AREA_CENTRAL_DEFENSE" ) mFactsBase.addLogicPattern("ball","localization","AREA_CENTRAL_DEFENSE"); else mFactsBase.addLogicPattern("ball","localization","AREA_ILLEGAL"); pastBallLocalization = ballLocalization; bNovaMsg = true; } if( pastBallOurPossesion != ballOurPossesion ) { if(ballOurPossesion) mFactsBase.addLogicPattern("teammate","has_ball","true"); else mFactsBase.addLogicPattern("teammate","has_ball","false"); pastBallOurPossesion = ballOurPossesion; bNovaMsg = true; } if( pastDeadBall != deadBall ) { if(deadBall == "us") mFactsBase.addLogicPattern("dead_ball","situation","us"); else if (deadBall == "them") mFactsBase.addLogicPattern("dead_ball","situation","them"); else mFactsBase.addLogicPattern("dead_ball","situation","none"); pastDeadBall = deadBall; bNovaMsg = true; } return bNovaMsg;}/*! Este método verifica nas situações de bola parada de quem é a bola\return De quem é a bola nossa, ou dos adversários*/string Cognitive::ModeUsOrThem( ){ PlayModeT pm = WM->getPlayMode(); if( WM->isDeadBallUs(pm) ) return "us"; if( WM->isDeadBallThem(pm) ) return "them"; return "none";}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -