Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yitonghe00/786146a238020d68827017fc80e877c0 to your computer and use it in GitHub Desktop.
Save yitonghe00/786146a238020d68827017fc80e877c0 to your computer and use it in GitHub Desktop.
countSteps = (state, robot, memory) => {
for (let turn = 0;; turn++) {
if (state.parcels.length == 0) {
return turn;
}
let action = robot(state, memory);
state = state.move(action.direction);
memory = action.memory;
}
}
function compareRobots(robot1, memory1, robot2, memory2) {
// Your code here
let steps1 = 0, steps2 = 0;
for (let i = 0; i < 100; i++) {
const task = VillageState.random();
steps1 += countSteps(task, robot1, memory1);
steps2 += countSteps(task, robot2, memory2);
}
console.log(`Robot1 usually takes ${steps1 / 100} steps`);
console.log(`Robot2 usually takes ${steps2 / 100} steps`);
}
compareRobots(routeRobot, [], goalOrientedRobot, []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment