Mercurial > repos > icfp2012
comparison src/sim.tp @ 6:86cdb799f950
unbarfed some things
author | William Morgan <bill@mrgn.org> |
---|---|
date | Fri, 13 Jul 2012 21:48:03 -0700 |
parents | be946b2a2cbc |
children | 1bd46f854dbb 5941e6b3684c |
comparison
equal
deleted
inserted
replaced
5:be946b2a2cbc | 6:86cdb799f950 |
---|---|
9 if:else <- :self trueblock :elseblock { | 9 if:else <- :self trueblock :elseblock { |
10 elseblock: | 10 elseblock: |
11 } | 11 } |
12 } | 12 } |
13 | 13 |
14 cellType <- # { | 14 cellType <- #{ |
15 robot <- "R" byte 0 | 15 robot <- ("R" byte: 0) |
16 wall <- "#" byte 0 | 16 wall <- ("#" byte: 0) |
17 rock <- "*" byte 0 | 17 rock <- ("*" byte: 0) |
18 lambda <- "\" byte 0 | 18 lambda <- ("\\" byte: 0) |
19 closedlift <- "L" byte 0 | 19 closedlift <- ("L" byte: 0) |
20 openlift <- "O" byte 0 | 20 openlift <- ("O" byte: 0) |
21 earth <- "." byte 0 | 21 earth <- ("." byte: 0) |
22 empty <- " " byte 0 | 22 empty <- (" " byte: 0) |
23 newline <- "\n" byte 0 | 23 newline <- ("\n" byte: 0) |
24 } | 24 } |
25 | 25 |
26 state <- #{ | 26 state <- #{ |
27 new <- : in_grid in_width in_height { | 27 new <- :in_grid in_width in_height { |
28 dst_grid <- #[] | 28 next_grid <- #[] |
29 foreach: in_grid :index el{ | 29 foreach: in_grid :index el{ |
30 dst_grid append: el | 30 dst_grid append: el |
31 } | 31 } |
32 #{ | 32 #{ |
33 grid <- [] | 33 grid <- [] |
41 grid get: (address: x y) | 41 grid get: (address: x y) |
42 } | 42 } |
43 collected <- 0 | 43 collected <- 0 |
44 moves <- 0 | 44 moves <- 0 |
45 ended <- false | 45 ended <- false |
46 doMove <- :roboMove { | |
47 ended <- roboMove = "A" | |
48 } | |
46 advance <- :roboMove { | 49 advance <- :roboMove { |
47 nextState <- deepCopy: self | 50 doMove: roboMove |
48 nextState <- doMove: | 51 moves <- moves + 1 |
49 nextState ended <- ended: | 52 self |
50 nextState moves <- moves + 1 | |
51 } | 53 } |
52 | 54 |
53 } | 55 } |
54 } | 56 } |
55 fromStr <- :str { | 57 fromStr <- :str { |
58 maxRow <- 0 | 60 maxRow <- 0 |
59 curRow <- 0 | 61 curRow <- 0 |
60 while: {index < strLen} do { | 62 while: {index < strLen} do { |
61 curByte <- str byte: index | 63 curByte <- str byte: index |
62 if: curByte = (cellType newline) { | 64 if: curByte = (cellType newline) { |
63 | 65 maxRow <- if: curRow > maxRow {curRow} else: {maxRow} |
64 } else: { | 66 } else: { |
65 curRow = curRow + 1 | 67 curRow = curRow + 1 |
66 } | 68 } |
67 } | 69 } |
68 grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0) ( "#" byte: 0) (" " byte: 0) ("#" byte: 0) ( "#" byte: 0) ("#" byte: 0) ("#" byte: 0)] | 70 grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0) ( "#" byte: 0) (" " byte: 0) ("#" byte: 0) ( "#" byte: 0) ("#" byte: 0) ("#" byte: 0)] |
87 myStep <- myStep + 1 | 89 myStep <- myStep + 1 |
88 if: myStep > 5 {"A"} else: {"W"} | 90 if: myStep > 5 {"A"} else: {"W"} |
89 } | 91 } |
90 } | 92 } |
91 | 93 |
92 ended <- :simState roboMove { | |
93 if: roboMove = "A" {} | |
94 } | |
95 | |
96 main <- { | 94 main <- { |
97 | 95 |
98 } | 96 } |
99 | 97 |
100 /* | 98 /* |