some minor pruning, but whatever
This commit is contained in:
21
src/day19.rs
21
src/day19.rs
@@ -113,32 +113,35 @@ fn find_best_geodes(bp: &Blueprint, time: usize) -> usize {
|
|||||||
obsidian: state.obsidian - bp.geode_bot_cost.1 + state.obsidian_bots,
|
obsidian: state.obsidian - bp.geode_bot_cost.1 + state.obsidian_bots,
|
||||||
..state.tick()
|
..state.tick()
|
||||||
};
|
};
|
||||||
if visited.insert(next.clone()) {
|
if visited.insert(next) {
|
||||||
stack.push(next);
|
stack.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Obsidian bots are nice too
|
// Obsidian bots are nice too, unless we have enough
|
||||||
if state.ore >= bp.obsidian_bot_cost.0 && state.clay >= bp.obsidian_bot_cost.1 {
|
if state.ore >= bp.obsidian_bot_cost.0
|
||||||
|
&& state.clay >= bp.obsidian_bot_cost.1
|
||||||
|
&& state.obsidian_bots < bp.geode_bot_cost.1
|
||||||
|
{
|
||||||
let next = State {
|
let next = State {
|
||||||
obsidian_bots: state.obsidian_bots + 1,
|
obsidian_bots: state.obsidian_bots + 1,
|
||||||
ore: state.ore - bp.obsidian_bot_cost.0 + state.ore_bots,
|
ore: state.ore - bp.obsidian_bot_cost.0 + state.ore_bots,
|
||||||
clay: state.clay - bp.obsidian_bot_cost.1 + state.clay_bots,
|
clay: state.clay - bp.obsidian_bot_cost.1 + state.clay_bots,
|
||||||
..state.tick()
|
..state.tick()
|
||||||
};
|
};
|
||||||
if visited.insert(next.clone()) {
|
if visited.insert(next) {
|
||||||
stack.push(next);
|
stack.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clay?
|
// Clay? also prune if we have enough for obsidian bots
|
||||||
if state.ore >= bp.clay_bot_cost {
|
if state.ore >= bp.clay_bot_cost && state.clay_bots < bp.obsidian_bot_cost.1 {
|
||||||
let next = State {
|
let next = State {
|
||||||
clay_bots: state.clay_bots + 1,
|
clay_bots: state.clay_bots + 1,
|
||||||
ore: state.ore - bp.clay_bot_cost + state.ore_bots,
|
ore: state.ore - bp.clay_bot_cost + state.ore_bots,
|
||||||
..state.tick()
|
..state.tick()
|
||||||
};
|
};
|
||||||
if visited.insert(next.clone()) {
|
if visited.insert(next) {
|
||||||
stack.push(next);
|
stack.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,14 +153,14 @@ fn find_best_geodes(bp: &Blueprint, time: usize) -> usize {
|
|||||||
ore: state.ore - bp.ore_bot_cost + state.ore_bots,
|
ore: state.ore - bp.ore_bot_cost + state.ore_bots,
|
||||||
..state.tick()
|
..state.tick()
|
||||||
};
|
};
|
||||||
if visited.insert(next.clone()) {
|
if visited.insert(next) {
|
||||||
stack.push(next);
|
stack.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Final option, do nothing
|
// Final option, do nothing
|
||||||
let next = state.tick();
|
let next = state.tick();
|
||||||
if visited.insert(next.clone()) {
|
if visited.insert(next) {
|
||||||
stack.push(next);
|
stack.push(next);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user