Skip to content
Permalink
Browse files

Update buy

  • Loading branch information...
ichyo committed Jun 24, 2019
1 parent 3310190 commit 2e8233a681ece79b94411fa87b2af11aec77ae94
Showing with 93 additions and 15 deletions.
  1. +1 −1 make_solution.sh
  2. +23 −1 src/bin/score.rs
  3. +1 −1 src/mine.rs
  4. +18 −5 src/models.rs
  5. +17 −0 src/parse.rs
  6. +33 −7 src/solve.rs
@@ -15,7 +15,7 @@ echo "$(date +"%Y-%m-%d %T"): Creating $OUTPUT" | tee -a $LOG_FILE
mkdir -p $OUTPUT

SECONDS=0
./target/release/icfpc2019 --output $OUTPUT --input ./input --duration 90000
./target/release/icfpc2019 --output $OUTPUT --input ./input --duration 300
echo "$(date +"%Y-%m-%d %T"): running time is $SECONDS secs" | tee -a $LOG_FILE

echo "$(date +"%Y-%m-%d %T"): Creating zip $OUTPUT/solutions.zip" | tee -a $LOG_FILE
@@ -1,13 +1,16 @@
use clap::{App, Arg};
use icfpc::models::*;
use icfpc::parse::read_all_inputs;

use icfpc::parse::read_buy;
use icfpc::parse::read_commands;
use icfpc::utils::Matrix;
use std::collections::HashMap;

use std::fs::File;
use std::io::Read;


struct ScoreInfo {
width: usize,
height: usize,
@@ -96,6 +99,7 @@ fn main() {
let output_root = matches.value_of("output").expect("no output specified");
let inputs = read_all_inputs(input_root);

let mut sum_buy = 0;
let mut sum_scores = 0.0;
for input in inputs {
let commands = {
@@ -105,6 +109,16 @@ fn main() {
output_file.read_to_string(&mut output_str).unwrap();
read_commands(&output_str)
};
let buy = {
let output_path = format!("{}/{}", output_root, input.buy_file_name());
if let Ok(mut output_file) = File::open(&output_path) {
let mut output_str = String::new();
output_file.read_to_string(&mut output_str).unwrap();
read_buy(&output_str)
} else {
Buy::new()
}
};
let mut counter = HashMap::new();
for b in &input.task.boosters {
*counter.entry(b.kind.clone()).or_insert(0) += 1;
@@ -119,9 +133,17 @@ fn main() {
counter.get(&BoosterType::Cloning).unwrap_or(&0),
);
let score_info = score_small(input.task, commands);
eprintln!("{}: {} ({})", input.id, score_info.debug(), count_info);
eprintln!(
"{}: {} (buy: {}) ({})",
input.id,
score_info.debug(),
buy.money(),
count_info
);
sum_scores += score_info.score();
sum_buy += buy.money();
}
println!("output: {}", output_root);
println!("total_score: {}", sum_scores);
println!("total_buy: {}", sum_buy);
}
@@ -131,7 +131,7 @@ impl Client {
info!("solving puzzle");
let puzzle_answer = solve_puzzle(puzzle);
info!("solving task");
let task_answer = solve_small_while(task, &Buy::empty(), std::time::Duration::from_secs(300));
let task_answer = solve_small_while(task, &Buy::new(), std::time::Duration::from_secs(300));
info!("dumping");

self.dump_task_answer(block, task_answer);
@@ -412,18 +412,31 @@ impl fmt::Display for Commands {
}
}

#[derive(Default)]
pub struct Buy(Vec<BoosterType>);

impl Buy {
pub fn empty() -> Buy {
Buy::new(Vec::new())
}
pub fn new(bs: Vec<BoosterType>) -> Buy {
Buy(bs)
pub fn new() -> Buy {
Buy(Vec::new())
}
pub fn push(&mut self, b: &BoosterType) {
self.0.push(b.clone());
}
pub fn iter(&self) -> impl Iterator<Item=&BoosterType> {
self.0.iter()
}
pub fn money(&self) -> usize {
self.0.iter().map(|b|
match b {
BoosterType::Cloning => 2000,
BoosterType::Drill => 700,
BoosterType::Teleports => 1200,
BoosterType::FastMove => 300,
BoosterType::NewHand => 1000,
BoosterType::Spawn => unreachable!(),
}
).sum::<usize>()
}
}

impl fmt::Display for Buy {
@@ -256,3 +256,20 @@ pub fn read_puzzle(s: &str) -> Puzzle {
excludes: excludes.0,
}
}

pub fn read_buy(s: &str) -> Buy {
let mut buy = Buy::new();
for c in s.chars() {
let booster_type = match c {
'B' => BoosterType::NewHand,
'F' => BoosterType::FastMove,
'L' => BoosterType::Drill,
'X' => BoosterType::Spawn,
'R' => BoosterType::Teleports,
'C' => BoosterType::Cloning,
_ => panic!("unknown type {}", c),
};
buy.push(&booster_type);
}
buy
}
@@ -104,7 +104,6 @@ pub struct State<'a> {
remaining_clone: usize,
remaining_pass: usize,
hand_count: usize,
tele_count: usize,
clone_count: usize,
robots: Vec<Robot>,
}
@@ -154,11 +153,18 @@ impl<'a> State<'a> {
}

let turn = 0;
let hand_count = 0;
let tele_count = 0;
let clone_count = 0;
let mut hand_count = 0;
let mut clone_count = 0;
let robots = vec![Robot::initialize(task)];

for b in buy.iter() {
match b {
BoosterType::Cloning => clone_count += 1,
BoosterType::NewHand => hand_count += 1,
_ => {}
}
}

State {
task,
turn,
@@ -169,7 +175,6 @@ impl<'a> State<'a> {
remaining_clone,
remaining_pass,
hand_count,
tele_count,
clone_count,
robots,
}
@@ -359,7 +364,6 @@ impl<'a> State<'a> {
self.booster_map.set(current_point, None);
}
BoosterType::Teleports => {
self.tele_count += 1;
self.booster_map.set(current_point, None);
}
BoosterType::Drill => {
@@ -493,5 +497,27 @@ pub fn solve_small(task: Task, buy: &Buy) -> Commands {
}

pub fn determine_buy(task: &Task) -> Buy {
Buy::empty()
let mut buy = Buy::new();

let has_spawn = task
.boosters
.iter()
.filter(|b| b.kind == BoosterType::Spawn)
.count()
!= 0;
let count_clone = task
.boosters
.iter()
.filter(|b| b.kind == BoosterType::Cloning)
.count();
let size = task.width * task.height;

let clone_target = 1;
let threshold = 20_000;
if has_spawn && count_clone < clone_target && size > threshold {
for _ in 0..clone_target - count_clone {
buy.push(&BoosterType::Cloning);
}
}
buy
}

0 comments on commit 2e8233a

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