Mercurial > repos > icfp2012
diff src/lifter.tp @ 39:9bccdb3ac979
Add priority queue implementation to lifter. Add methods for cloning playfield and determining valid moves.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 15 Jul 2012 14:27:21 -0700 |
parents | f7a1daaec925 |
children | 0c09730c173e |
line wrap: on
line diff
--- a/src/lifter.tp Sun Jul 15 14:25:05 2012 -0700 +++ b/src/lifter.tp Sun Jul 15 14:27:21 2012 -0700 @@ -1,4 +1,49 @@ #{ + pqueue <- { + normalnode <- :pri val { + #{ + priority <- pri + value <- val + next <- false + higherPriority? <- :other { + priority > (other priority) + } + if:else <- :self trueblock :elseblock { + trueblock: + } + } + } + head <- #{ + higherPriority? <- :other {false} + next <- { self } + value <- { false } + } + #{ + take <- { + cur <- head + head <- cur next + cur value + } + insert:atPriority <- :val pri { + node <- normalnode: pri val + cur <- head + last <- false + while: {cur higherPriority?: node} do: { + last <- cur + cur <- cur next + } + if: last { + node next!: (last next) + last next!: node + } else: { + node next!: head + head <- node + } + self + } + } + } + abs <- :val { if: val < 0 { 0 - val } else: { val } } @@ -13,5 +58,14 @@ os write: 2 text os write: 2 "width: " . (string: (playfield width)) . "\n" os write: 2 "height: " . (string: (playfield height)) . "\n" + me <-playfield getRobot + os write: 2 "robot x: " . (me x) . " y: " . (me y) . "\n" + neighbors <- playfield validMoves: (me x) (me y) + foreach: neighbors :idx move { + os write: 2 "move: " . move . "\n" + curfield <- playfield clone + curfield advance: (move cmd) + curfield printGrid + } } }