Mercurial > repos > icfp2012
comparison src/lifter.tp @ 61:f851895ea67a
Add cullwhenover option and more tuning results
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 16 Jul 2012 02:20:38 -0700 |
parents | 7d4e51b4769a |
children | ff2b38518a58 |
comparison
equal
deleted
inserted
replaced
60:7d4e51b4769a | 61:f851895ea67a |
---|---|
101 curbest <- (field clone) advance: "A" | 101 curbest <- (field clone) advance: "A" |
102 states <- #[field] | 102 states <- #[field] |
103 visitedStates <- sets hash | 103 visitedStates <- sets hash |
104 bestMove:withMaxSteps <- :self :max{ | 104 bestMove:withMaxSteps <- :self :max{ |
105 n <- 0 | 105 n <- 0 |
106 hashelim <- 0 | |
106 while: { if: (states length) > 0 { if: n < max { not: (curbest succeeded) } } } do: { | 107 while: { if: (states length) > 0 { if: n < max { not: (curbest succeeded) } } } do: { |
107 nextstates <- #[] | 108 nextstates <- #[] |
108 foreach: states :idx curstate { | 109 foreach: states :idx curstate { |
109 me <-curstate getRobot | 110 me <-curstate getRobot |
110 candidates <- curstate validMoves: (me x) (me y) | 111 candidates <- curstate validMoves: (me x) (me y) |
135 } else: { | 136 } else: { |
136 (states length) > 0 | 137 (states length) > 0 |
137 } | 138 } |
138 } | 139 } |
139 cullStatesTo <- :n { | 140 cullStatesTo <- :n { |
140 print: "culling " . (states length) . " to " . n . "\n" | 141 os write: 2 "culling " . (states length) . " to " . n . "\n" |
141 if: n < (states length) { | 142 if: n < (states length) { |
142 states <- topN: states n | 143 states <- topN: states n |
143 } | 144 } |
144 print: "states length is now " . (states length) . "\n" | 145 os write: 2 "states length is now " . (states length) . "\n" |
145 } | 146 } |
146 } | 147 } |
147 } | 148 } |
148 | 149 |
149 main <- :args { | 150 main <- :args { |
150 initmaxsteps <- 6 | 151 initmaxsteps <- 6 |
151 aftermaxsteps <- 5 | 152 aftermaxsteps <- 5 |
152 cullstates <- 8 | 153 cullstates <- 8 |
153 curarg <- 1 | 154 curarg <- 1 |
155 cullwhenover <- 0 | |
154 while: { curarg < (args length) } do: { | 156 while: { curarg < (args length) } do: { |
155 if: (args get: curarg) = "-is" { | 157 if: (args get: curarg) = "-is" { |
156 curarg <- curarg + 1 | 158 curarg <- curarg + 1 |
157 if: curarg < (args length) { | 159 if: curarg < (args length) { |
158 initmaxsteps <- ((args get: curarg) int32) | 160 initmaxsteps <- ((args get: curarg) int32) |
167 if: (args get: curarg) = "-cs" { | 169 if: (args get: curarg) = "-cs" { |
168 curarg <- curarg + 1 | 170 curarg <- curarg + 1 |
169 if: curarg < (args length) { | 171 if: curarg < (args length) { |
170 cullstates <- ((args get: curarg) int32) | 172 cullstates <- ((args get: curarg) int32) |
171 } | 173 } |
174 } else: { | |
175 if: (args get: curarg) = "-co" { | |
176 curarg <- curarg + 1 | |
177 if: curarg < (args length) { | |
178 cullwhenover <- ((args get: curarg) int32) | |
179 } | |
180 } | |
172 } | 181 } |
173 } | 182 } |
174 } | 183 } |
175 curarg <- curarg + 1 | 184 curarg <- curarg + 1 |
176 } | 185 } |
183 | 192 |
184 finder <- moveFinder: initial | 193 finder <- moveFinder: initial |
185 | 194 |
186 maxsteps <- initmaxsteps | 195 maxsteps <- initmaxsteps |
187 while: { bestMove: finder withMaxSteps: maxsteps } do: { | 196 while: { bestMove: finder withMaxSteps: maxsteps } do: { |
188 best <- -1000000 | 197 //best <- -1000000 |
189 bestscore <- -1000000 | 198 //bestscore <- -1000000 |
190 foreach: (finder states) :idx el { | 199 //foreach: (finder states) :idx el { |
191 h <- (el heuristic) | 200 // h <- (el heuristic) |
192 s <- (el score) | 201 // s <- (el score) |
193 if: (h > best) { | 202 // if: (h > best) { |
194 best <- h | 203 // best <- h |
195 } | 204 // } |
196 if: (s > bestscore) { | 205 // if: (s > bestscore) { |
197 bestscore <- s | 206 // bestscore <- s |
198 } | 207 // } |
199 } | 208 //} |
200 finder cullStatesTo: cullstates | 209 if: ((finder states) length) > cullwhenover { |
210 finder cullStatesTo: cullstates | |
211 } | |
201 maxsteps <- aftermaxsteps | 212 maxsteps <- aftermaxsteps |
202 os write: 2 "--------iteration results-------\n" | 213 os write: 2 "--------iteration results-------\n" |
203 os write: 2 "Best:\n" | 214 os write: 2 "Best:\n" |
204 (finder curbest) printGrid | 215 (finder curbest) printGrid |
205 os write: 2 "Hash: " . ((finder curbest) hash) | 216 //os write: 2 "Hash: " . ((finder curbest) hash) |
206 os write: 2 "Current before cull\n" | 217 //os write: 2 "Current before cull\n" |
207 os write: 2 " Best Heuristic: " . best . "\n" | 218 //os write: 2 " Best Heuristic: " . best . "\n" |
208 os write: 2 " Best Score: " . bestscore . "\n" | 219 //os write: 2 " Best Score: " . bestscore . "\n" |
209 //os write: 2 "After cull:\n" | 220 //os write: 2 "After cull:\n" |
210 //foreach: (finder states) :idx el{ | 221 //foreach: (finder states) :idx el{ |
211 // os write: 2 " " . idx . " Heuristic: " . (el heuristic) . "\n" | 222 // os write: 2 " " . idx . " Heuristic: " . (el heuristic) . "\n" |
212 // os write: 2 " " . idx . " Score: " . (el score) . "\n" | 223 // os write: 2 " " . idx . " Score: " . (el score) . "\n" |
213 //} | 224 //} |