Go to the documentation of this file.00001 #include "Move2DVarRel.h"
00002
00003
00004 Move2DVarRel::Move2DVarRel(SharedPointer<Variable> actionVar, SharedPointer<Map2DPosVar> robotPosVar)
00005 {
00006 this->actionVar = actionVar;
00007 this->posVar = robotPosVar;
00008 this->addSourceVar(actionVar);
00009 this->addSourceVar(robotPosVar);
00010 this->setDestVariable(robotPosVar);
00011 }
00012
00013 Move2DVarRel::~Move2DVarRel(void)
00014 {
00015 }
00016
00017 vector<SharedPointer<RelEntry> > Move2DVarRel::getProb(map<string, SharedPointer<IVariableValue> > sourceVals)
00018 {
00019 string action = sourceVals[actionVar->getVariableName()]->getValueName();
00020 SharedPointer<Map2DPosValue> curPos = dynamic_pointer_cast<Map2DPosValue>(sourceVals[posVar->getVariableName()]);
00021 SharedPointer<Map2DPosValue> nextPos = curPos->duplicate();
00022 if(action == "left")
00023 {
00024 if(nextPos->x >0 )
00025 {
00026 nextPos->x --;
00027 }
00028 }
00029 else if(action == "right")
00030 {
00031 if(nextPos->x < posVar->width - 1)
00032 {
00033 nextPos->x ++;
00034 }
00035 }
00036 else if(action == "up")
00037 {
00038 if(nextPos->y >0 )
00039 {
00040 nextPos->y --;
00041 }
00042 }
00043 else if(action == "down")
00044 {
00045 if(nextPos->y < posVar->height - 1 )
00046 {
00047 nextPos->y ++;
00048 }
00049 }
00050 else if(action == "noop")
00051 {
00052 }
00053 else
00054 {
00055 cout << "Error: unkonwn action " << action << endl;
00056 throw runtime_error("Error: unkonwn action ");
00057 }
00058
00059 vector<SharedPointer<RelEntry> > result;
00060
00061 {
00062 SharedPointer<RelEntry> newEntry (new RelEntry());
00063
00064
00065 newEntry->destValues[this->getDestVariable()->getVariableName()] = nextPos;
00066 newEntry->prob = 1;
00067 result.push_back(newEntry);
00068 }
00069
00070 return result;
00071 }