Skip to content
Permalink
Browse files

Add drill

  • Loading branch information...
ichyo committed Jun 22, 2019
1 parent 0ff6ddf commit 4f1a2846a7c8e08af067838b626c71d262a1784d
Showing with 42 additions and 11 deletions.
  1. +2 −0 src/models.rs
  2. +40 −11 src/solve.rs
@@ -150,6 +150,7 @@ pub enum Command {
TurnLeft,
NewHand(Point),
FastWheel,
Drill,
}

impl fmt::Display for Command {
@@ -164,6 +165,7 @@ impl fmt::Display for Command {
Command::TurnLeft => write!(f, "Q"),
Command::NewHand(p) => write!(f, "B({}, {})", p.x, p.y),
Command::FastWheel => write!(f, "F"),
Command::Drill => write!(f, "L"),
}
}
}
@@ -17,6 +17,7 @@ fn find_shortest_path(
start: Point,
bodies_diff: &[Point],
booster_map: &Matrix<Option<BoosterType>>,
drill_mode: bool,
) -> Vec<Move> {
let mut rng = thread_rng();
let mut moves = [
@@ -43,13 +44,18 @@ fn find_shortest_path(
Some(false) => true,
_ => false,
});

let is_booster = match booster_map.get(c) {
Some(Some(BoosterType::NewHand)) => true,
Some(Some(BoosterType::Drill)) => true,
Some(Some(_)) => true,
_ => false,
};

if not_passed || is_booster {
let is_valid = match valid.get(c) {
Some(true) => true,
_ => false,
};

if is_valid && (not_passed || is_booster) {
let mut res = Vec::new();
let mut iter = c;
while iter != start {
@@ -68,9 +74,12 @@ fn find_shortest_path(
for m in &moves {
let nc = c.move_with(m);
if let Some(None) = data.get(nc) {
if let Some(true) = valid.get(nc) {
data.set(nc, Some((m.clone(), cost + 1)));
queue.push_back(nc);
match (valid.get(nc), drill_mode) {
(Some(true), _) | (Some(false), true) => {
data.set(nc, Some((m.clone(), cost + 1)));
queue.push_back(nc);
}
_ => {}
}
}
}
@@ -153,7 +162,6 @@ pub fn solve_small(task: Task) -> Vec<Command> {

let mut hand_count = 0;
let mut drill_count = 0;
let mut drill_turns = 0;

while remaining > 0 {
while hand_count > 0 && !new_bodies.is_empty() {
@@ -162,10 +170,6 @@ pub fn solve_small(task: Task) -> Vec<Command> {
bodies_diff.push(new_hand);
res.push(Command::NewHand(new_hand));
}
if drill_count > 0 && drill_turns == 0 {
drill_count -= 1;
drill_turns = 30;
}
update_point(
current_point,
&bodies_diff,
@@ -183,7 +187,32 @@ pub fn solve_small(task: Task) -> Vec<Command> {
current_point,
&bodies_diff,
&booster_map,
false,
);
let moves = if drill_count > 0 {
let drill_moves = find_shortest_path(
width,
height,
&valid,
&passed,
current_point,
&bodies_diff,
&booster_map,
true,
);
if drill_moves.len() * 2 <= moves.len()
&& drill_moves.len() >= 10
&& drill_moves.len() < 30
{
drill_count -= 1;
res.push(Command::Drill);
drill_moves
} else {
moves
}
} else {
moves
};
for m in moves {
current_point = current_point.move_with(&m);
update_point(

0 comments on commit 4f1a284

Please sign in to comment.
You can’t perform that action at this time.