00001 #include "AntEvalOp.h" 00002 00003 00010 class IfFoodAhead : public Tree::Primitives::Primitive 00011 { 00012 public: 00013 IfFoodAhead() 00014 { 00015 nArguments_ = 2; 00016 name_ = "ifa"; 00017 } 00018 00019 void execute(void* evalOp, Tree::Tree& tree) 00020 { 00021 // get pointer to simulator from the context 00022 AntEvalOp* ant = (AntEvalOp*) state_->getContext()->environment; 00023 00024 // query the simulator: are we facing food? 00025 if(ant->facingFood()) { 00026 // if yes, execute the first subtree 00027 getNextArgument(evalOp, tree); 00028 // and skip the second one 00029 skipNextArgument(tree); 00030 } else { 00031 // otherwise... 00032 skipNextArgument(tree); 00033 getNextArgument(evalOp, tree); 00034 } 00035 } 00036 00037 ~IfFoodAhead() 00038 { } 00039 };