Mercurial > repos > icfp2012
diff src/lifter.tp @ 60:7d4e51b4769a
Add hashset based pruning
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 16 Jul 2012 01:55:04 -0700 |
parents | 397089dccb32 |
children | f851895ea67a |
line wrap: on
line diff
--- a/src/lifter.tp Mon Jul 16 01:24:47 2012 -0700 +++ b/src/lifter.tp Mon Jul 16 01:55:04 2012 -0700 @@ -100,6 +100,7 @@ #{ curbest <- (field clone) advance: "A" states <- #[field] + visitedStates <- sets hash bestMove:withMaxSteps <- :self :max{ n <- 0 while: { if: (states length) > 0 { if: n < max { not: (curbest succeeded) } } } do: { @@ -110,15 +111,18 @@ foreach: candidates :idx move { curfield <- curstate clone curfield advance: (move cmd) - if: (curfield ended) { - if: (curfield score) > (curbest score) { - curbest <- curfield - } - } else: { - //check theoretical max score for current map state - //discard paths that can never be better than our current best - if: (curfield maxScore) > (curbest score) { - nextstates append: curfield + if: (not: (visitedStates contains?: curfield)) { + visitedStates add: curfield + if: (curfield ended) { + if: (curfield score) > (curbest score) { + curbest <- curfield + } + } else: { + //check theoretical max score for current map state + //discard paths that can never be better than our current best + if: (curfield maxScore) > (curbest score) { + nextstates append: curfield + } } } } @@ -198,14 +202,15 @@ os write: 2 "--------iteration results-------\n" os write: 2 "Best:\n" (finder curbest) printGrid + os write: 2 "Hash: " . ((finder curbest) hash) os write: 2 "Current before cull\n" os write: 2 " Best Heuristic: " . best . "\n" os write: 2 " Best Score: " . bestscore . "\n" - os write: 2 "After cull:\n" - foreach: (finder states) :idx el{ - os write: 2 " " . idx . " Heuristic: " . (el heuristic) . "\n" - os write: 2 " " . idx . " Score: " . (el score) . "\n" - } + //os write: 2 "After cull:\n" + //foreach: (finder states) :idx el{ + // os write: 2 " " . idx . " Heuristic: " . (el heuristic) . "\n" + // os write: 2 " " . idx . " Score: " . (el score) . "\n" + //} //os write: 2 "Current:\n" //(finder playfield) printGrid }