function collect([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], duration, collection, robots, robot_turn) {
if (robot_turn < 0) {
let a0 = collect([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], duration, collection, robots, 0);
let a1 = collect([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], duration, collection, robots, 1);
let a2 = collect([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], duration, collection, robots, 2);
let a3 = collect([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], duration, collection, robots, 3);
let top = [a0, a1, a2, a3].sort(([p,c,r,d], [p1,c1,r1,d1]) => {
if (c1.geo > c.geo) return 1;
if (c1.geo < c.geo) return -1;
if (r1.geo > r.geo) return 1;
if (r1.geo < r.geo) return -1;
if (c1.obs > c.obs) return 1;
if (c1.obs < c.obs) return -1;
if (r1.obs > r.obs) return 1;
if (r1.obs < r.obs) return -1;
if (c1.clay > c.clay) return 1;
if (c1.clay < c.clay) return -1;
if (r1.clay > r.clay) return 1;
if (r1.clay < r.clay) return -1;
if (c1.ore > c.ore) return 1;
if (c1.ore < c.ore) return -1;
else return 0
});
return top[0];
}
let col = { ...collection };
let rob = { ...robots };
while (duration > 0 && !canCreate([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], col, robot_turn)) {
duration--;
col.ore += robots.ore;
col.clay += robots.clay;
col.obs += robots.obs;
col.geo += robots.geo;
}
if (duration === 0) {
return [[robot_turn], col, rob, 0];
}
duration--;
[rob, col] = consume([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], rob, col, robot_turn);
col.ore += robots.ore;
col.clay += robots.clay;
col.obs += robots.obs;
col.geo += robots.geo;
if (duration === 0) {
return [[robot_turn], col, rob, 0];
}
let [sim_path, sim_col, sim_rob, sim_dur] = collect([bp, ore, clay, ob_ore, ob_clay, geo_ore, geo_obs], duration, col, rob, -1);
return [[robot_turn, ...sim_path], sim_col, sim_rob, sim_dur];
}