11use clap:: { App , Arg } ;
22use icfpc:: models:: * ;
33use icfpc:: parse:: read_all_inputs;
4+
5+ use icfpc:: parse:: read_buy;
46use icfpc:: parse:: read_commands;
57use icfpc:: utils:: Matrix ;
68use std:: collections:: HashMap ;
79
810use std:: fs:: File ;
911use std:: io:: Read ;
1012
13+
1114struct 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}
0 commit comments