Mercurial > repos > icfp2012
comparison 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 |
comparison
equal
deleted
inserted
replaced
38:cd3ec7d99330 | 39:9bccdb3ac979 |
---|---|
1 #{ | 1 #{ |
2 pqueue <- { | |
3 normalnode <- :pri val { | |
4 #{ | |
5 priority <- pri | |
6 value <- val | |
7 next <- false | |
8 higherPriority? <- :other { | |
9 priority > (other priority) | |
10 } | |
11 if:else <- :self trueblock :elseblock { | |
12 trueblock: | |
13 } | |
14 } | |
15 } | |
16 head <- #{ | |
17 higherPriority? <- :other {false} | |
18 next <- { self } | |
19 value <- { false } | |
20 } | |
21 #{ | |
22 take <- { | |
23 cur <- head | |
24 head <- cur next | |
25 cur value | |
26 } | |
27 insert:atPriority <- :val pri { | |
28 node <- normalnode: pri val | |
29 cur <- head | |
30 last <- false | |
31 while: {cur higherPriority?: node} do: { | |
32 last <- cur | |
33 cur <- cur next | |
34 } | |
35 if: last { | |
36 node next!: (last next) | |
37 last next!: node | |
38 } else: { | |
39 node next!: head | |
40 head <- node | |
41 } | |
42 self | |
43 } | |
44 } | |
45 } | |
46 | |
2 abs <- :val { | 47 abs <- :val { |
3 if: val < 0 { 0 - val } else: { val } | 48 if: val < 0 { 0 - val } else: { val } |
4 } | 49 } |
5 | 50 |
6 distanceFrom:to <- :sx sy :dx dy { | 51 distanceFrom:to <- :sx sy :dx dy { |
11 text <- sim readFd: 0 | 56 text <- sim readFd: 0 |
12 playfield <- (sim state) fromStr: text | 57 playfield <- (sim state) fromStr: text |
13 os write: 2 text | 58 os write: 2 text |
14 os write: 2 "width: " . (string: (playfield width)) . "\n" | 59 os write: 2 "width: " . (string: (playfield width)) . "\n" |
15 os write: 2 "height: " . (string: (playfield height)) . "\n" | 60 os write: 2 "height: " . (string: (playfield height)) . "\n" |
61 me <-playfield getRobot | |
62 os write: 2 "robot x: " . (me x) . " y: " . (me y) . "\n" | |
63 neighbors <- playfield validMoves: (me x) (me y) | |
64 foreach: neighbors :idx move { | |
65 os write: 2 "move: " . move . "\n" | |
66 curfield <- playfield clone | |
67 curfield advance: (move cmd) | |
68 curfield printGrid | |
69 } | |
16 } | 70 } |
17 } | 71 } |