ECF 1.5
IfFoodAhead.h
1#include "AntEvalOp.h"
2
3
11{
12public:
14 {
15 nArguments_ = 2;
16 name_ = "ifa";
17 }
18
19 void execute(void* evalOp, Tree::Tree& tree)
20 {
21 // get pointer to simulator from the context
22 AntEvalOp* ant = (AntEvalOp*) state_->getContext()->environment;
23
24 // query the simulator: are we facing food?
25 if(ant->facingFood()) {
26 // if yes, execute the first subtree
27 getNextArgument(evalOp, tree);
28 // and skip the second one
29 skipNextArgument(tree);
30 } else {
31 // otherwise...
32 skipNextArgument(tree);
33 getNextArgument(evalOp, tree);
34 }
35 }
36
38 { }
39};
Artificial ant evaluation class (and environment simulator)
Definition: AntEvalOp.h:51
bool facingFood()
Check if there's food in front.
Definition: AntEvalOp.cpp:256
GP function, checks if the food is ahead.
Definition: IfFoodAhead.h:11
void execute(void *evalOp, Tree::Tree &tree)
Execute the primitive.
Definition: IfFoodAhead.h:19
Base primitive class (Tree genotype).
Definition: Primitive.h:37
void skipNextArgument(Tree &tree)
Skip next child subtree (doesn't execute the subtree).
Definition: Primitive.cpp:82
void getNextArgument(void *result, Tree &tree)
Execute next child node's primitive (execute next subtree).
Definition: Primitive.cpp:71
Tree class - implements genotype as a tree.
Definition: Tree_c.h:29