var rob = new Critter({mind: new CritterMind({decisionTree: moveForwardOrThink})});
function getCoord() {
- return Math.floor(Math.random() * 10);
+ return Math.floor(Math.random() * 10);
}
function getCoords() {
- return {x: getCoord(), y: getCoord()};
+ return {x: getCoord(), y: getCoord()};
}
for(var i = 0; i < 50; i++) {
- world.place(new Resource(), getCoords());
+ world.place(new Resource(), getCoords());
}
for(var i = 0; i < 50; i++) {
- var blocker = new Rock();
- world.place(blocker, getCoords());
+ var blocker = new Rock();
+ world.place(blocker, getCoords());
}
rob.direction = _.sample(CardinalDirection.ALL_DIRECTIONS);
@@ -98,7 +101,7 @@
Finding food
};
var turnLeftOrTurnRight = new DecisionNode(isNothingToTheLeftOfMe, Critter.Actions.TURN_LEFT, Critter.Actions.TURN_RIGHT);
- var eatItOrThink = new DecisionNode(isThingInFrontOfMeEdible, Critter.Actions.MOVE_FORWARD, turnLeftOrTurnRight
+ var eatItOrThink = new DecisionNode(isThingInFrontOfMeEdible, Critter.Actions.MOVE_FORWARD, turnLeftOrTurnRight);
var moveForwardOrThink = new DecisionNode(isSomethingInFrontOfMe, eatItOrThink, Critter.Actions.MOVE_FORWARD);
var rob = new Critter({mind: new CritterMind({decisionTree: moveForwardOrThink})});
@@ -127,7 +130,7 @@
Zig Zag
var zig = [Critter.Actions.TURN_RIGHT, Critter.Actions.MOVE_FORWARD, Critter.Actions.DECREMENT_COUNTER];
var zag = [Critter.Actions.TURN_LEFT, Critter.Actions.MOVE_FORWARD, Critter.Actions.INCREMENT_COUNTER];
var toZigOrToZagThatIsTheQuestion = function(stimuli, vitals) {
- return vitals.counter === 0;
+ return vitals.counter === 0;
};
var zigZag = new DecisionNode(toZigOrToZagThatIsTheQuestion, zig, zag);
anna = new Critter({mind: new CritterMind({decisionTree:zigZag })});
@@ -148,3 +151,18 @@