Skip to content

Commit 2e8233a

Browse files
committed
Update buy
1 parent 3310190 commit 2e8233a

File tree

6 files changed

+93
-15
lines changed

6 files changed

+93
-15
lines changed

make_solution.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ echo "$(date +"%Y-%m-%d %T"): Creating $OUTPUT" | tee -a $LOG_FILE
1515
mkdir -p $OUTPUT
1616

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

2121
echo "$(date +"%Y-%m-%d %T"): Creating zip $OUTPUT/solutions.zip" | tee -a $LOG_FILE

src/bin/score.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
use clap::{App, Arg};
22
use icfpc::models::*;
33
use icfpc::parse::read_all_inputs;
4+
5+
use icfpc::parse::read_buy;
46
use icfpc::parse::read_commands;
57
use icfpc::utils::Matrix;
68
use std::collections::HashMap;
79

810
use std::fs::File;
911
use std::io::Read;
1012

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

102+
let mut sum_buy = 0;
99103
let mut sum_scores = 0.0;
100104
for input in inputs {
101105
let commands = {
@@ -105,6 +109,16 @@ fn main() {
105109
output_file.read_to_string(&mut output_str).unwrap();
106110
read_commands(&output_str)
107111
};
112+
let buy = {
113+
let output_path = format!("{}/{}", output_root, input.buy_file_name());
114+
if let Ok(mut output_file) = File::open(&output_path) {
115+
let mut output_str = String::new();
116+
output_file.read_to_string(&mut output_str).unwrap();
117+
read_buy(&output_str)
118+
} else {
119+
Buy::new()
120+
}
121+
};
108122
let mut counter = HashMap::new();
109123
for b in &input.task.boosters {
110124
*counter.entry(b.kind.clone()).or_insert(0) += 1;
@@ -119,9 +133,17 @@ fn main() {
119133
counter.get(&BoosterType::Cloning).unwrap_or(&0),
120134
);
121135
let score_info = score_small(input.task, commands);
122-
eprintln!("{}: {} ({})", input.id, score_info.debug(), count_info);
136+
eprintln!(
137+
"{}: {} (buy: {}) ({})",
138+
input.id,
139+
score_info.debug(),
140+
buy.money(),
141+
count_info
142+
);
123143
sum_scores += score_info.score();
144+
sum_buy += buy.money();
124145
}
125146
println!("output: {}", output_root);
126147
println!("total_score: {}", sum_scores);
148+
println!("total_buy: {}", sum_buy);
127149
}

src/mine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ impl Client {
131131
info!("solving puzzle");
132132
let puzzle_answer = solve_puzzle(puzzle);
133133
info!("solving task");
134-
let task_answer = solve_small_while(task, &Buy::empty(), std::time::Duration::from_secs(300));
134+
let task_answer = solve_small_while(task, &Buy::new(), std::time::Duration::from_secs(300));
135135
info!("dumping");
136136

137137
self.dump_task_answer(block, task_answer);

src/models.rs

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,18 +412,31 @@ impl fmt::Display for Commands {
412412
}
413413
}
414414

415+
#[derive(Default)]
415416
pub struct Buy(Vec<BoosterType>);
416417

417418
impl Buy {
418-
pub fn empty() -> Buy {
419-
Buy::new(Vec::new())
420-
}
421-
pub fn new(bs: Vec<BoosterType>) -> Buy {
422-
Buy(bs)
419+
pub fn new() -> Buy {
420+
Buy(Vec::new())
423421
}
424422
pub fn push(&mut self, b: &BoosterType) {
425423
self.0.push(b.clone());
426424
}
425+
pub fn iter(&self) -> impl Iterator<Item=&BoosterType> {
426+
self.0.iter()
427+
}
428+
pub fn money(&self) -> usize {
429+
self.0.iter().map(|b|
430+
match b {
431+
BoosterType::Cloning => 2000,
432+
BoosterType::Drill => 700,
433+
BoosterType::Teleports => 1200,
434+
BoosterType::FastMove => 300,
435+
BoosterType::NewHand => 1000,
436+
BoosterType::Spawn => unreachable!(),
437+
}
438+
).sum::<usize>()
439+
}
427440
}
428441

429442
impl fmt::Display for Buy {

src/parse.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,3 +256,20 @@ pub fn read_puzzle(s: &str) -> Puzzle {
256256
excludes: excludes.0,
257257
}
258258
}
259+
260+
pub fn read_buy(s: &str) -> Buy {
261+
let mut buy = Buy::new();
262+
for c in s.chars() {
263+
let booster_type = match c {
264+
'B' => BoosterType::NewHand,
265+
'F' => BoosterType::FastMove,
266+
'L' => BoosterType::Drill,
267+
'X' => BoosterType::Spawn,
268+
'R' => BoosterType::Teleports,
269+
'C' => BoosterType::Cloning,
270+
_ => panic!("unknown type {}", c),
271+
};
272+
buy.push(&booster_type);
273+
}
274+
buy
275+
}

src/solve.rs

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ pub struct State<'a> {
104104
remaining_clone: usize,
105105
remaining_pass: usize,
106106
hand_count: usize,
107-
tele_count: usize,
108107
clone_count: usize,
109108
robots: Vec<Robot>,
110109
}
@@ -154,11 +153,18 @@ impl<'a> State<'a> {
154153
}
155154

156155
let turn = 0;
157-
let hand_count = 0;
158-
let tele_count = 0;
159-
let clone_count = 0;
156+
let mut hand_count = 0;
157+
let mut clone_count = 0;
160158
let robots = vec![Robot::initialize(task)];
161159

160+
for b in buy.iter() {
161+
match b {
162+
BoosterType::Cloning => clone_count += 1,
163+
BoosterType::NewHand => hand_count += 1,
164+
_ => {}
165+
}
166+
}
167+
162168
State {
163169
task,
164170
turn,
@@ -169,7 +175,6 @@ impl<'a> State<'a> {
169175
remaining_clone,
170176
remaining_pass,
171177
hand_count,
172-
tele_count,
173178
clone_count,
174179
robots,
175180
}
@@ -359,7 +364,6 @@ impl<'a> State<'a> {
359364
self.booster_map.set(current_point, None);
360365
}
361366
BoosterType::Teleports => {
362-
self.tele_count += 1;
363367
self.booster_map.set(current_point, None);
364368
}
365369
BoosterType::Drill => {
@@ -493,5 +497,27 @@ pub fn solve_small(task: Task, buy: &Buy) -> Commands {
493497
}
494498

495499
pub fn determine_buy(task: &Task) -> Buy {
496-
Buy::empty()
500+
let mut buy = Buy::new();
501+
502+
let has_spawn = task
503+
.boosters
504+
.iter()
505+
.filter(|b| b.kind == BoosterType::Spawn)
506+
.count()
507+
!= 0;
508+
let count_clone = task
509+
.boosters
510+
.iter()
511+
.filter(|b| b.kind == BoosterType::Cloning)
512+
.count();
513+
let size = task.width * task.height;
514+
515+
let clone_target = 1;
516+
let threshold = 20_000;
517+
if has_spawn && count_clone < clone_target && size > threshold {
518+
for _ in 0..clone_target - count_clone {
519+
buy.push(&BoosterType::Cloning);
520+
}
521+
}
522+
buy
497523
}

0 commit comments

Comments
 (0)