Mercurial > repos > icfp2012
comparison src/sim.tp @ 10:370a1eeb8812
merge and stuff
author | William Morgan <bill@mrgn.org> |
---|---|
date | Sat, 14 Jul 2012 01:58:43 -0700 |
parents | 66ea6fdd3fcb |
children | f28e465e9ee6 |
comparison
equal
deleted
inserted
replaced
9:66ea6fdd3fcb | 10:370a1eeb8812 |
---|---|
1 #{ | 1 #{ |
2 | |
3 // utilities | |
2 true <- #{ | 4 true <- #{ |
3 if:else <- :self trueblock :elseblock { | 5 if:else <- :self trueblock :elseblock { |
4 trueblock: | 6 trueblock: |
5 } | 7 } |
6 } | 8 } |
9 if:else <- :self trueblock :elseblock { | 11 if:else <- :self trueblock :elseblock { |
10 elseblock: | 12 elseblock: |
11 } | 13 } |
12 } | 14 } |
13 | 15 |
16 foreach <- :string action { | |
17 strLen <- string byte_length: | |
18 index <- 0 | |
19 while: {index < strLen} do { | |
20 element <- (string byte: index) | |
21 action: index element | |
22 index <- index + 1 | |
23 } | |
24 } | |
25 // end utilities | |
26 | |
27 | |
14 cellTypes <- #{ | 28 cellTypes <- #{ |
15 allstr <- #[] | 29 allstr <- #[] |
16 allobj <- #[] | 30 allobj <- #[] |
17 make <- :idstr { | 31 new <- :idstr { |
18 ret <- #{ | 32 ret <- #{ |
19 id <- (idstr byte: 0) | 33 id <- (idstr byte: 0) |
34 isrobot <- { false } | |
20 } | 35 } |
21 allobj append: ret | 36 allobj append: ret |
22 allstr append: idstr | 37 allstr append: idstr |
23 ret | 38 ret |
24 } | 39 } |
37 } else: { | 52 } else: { |
38 empty | 53 empty |
39 } | 54 } |
40 } | 55 } |
41 } | 56 } |
42 wall <- make: "#" | 57 wall <- new: "#" |
43 empty <- make: " " | 58 empty <- new: " " |
44 earth <- make: "." | 59 earth <- new: "." |
45 rock <- make: "*" | 60 rock <- new: "*" |
46 lambda <- make: "\\" | 61 lambda <- new: "\\" |
47 closedlift <- make: "L" | 62 closedlift <- new: "L" |
48 openlift <- make: "O" | 63 openlift <- new: "O" |
49 newline <- make: "\n" | 64 newline <- new: "\n" |
50 robot <- { | 65 robot <- { |
51 #{ | 66 #{ |
52 id <- ("R" byte: 0) | 67 id <- ("R" byte: 0) |
68 isrobot <- { true } | |
53 heldBreath <- 0 | 69 heldBreath <- 0 |
54 } | 70 } |
55 } | 71 } |
56 | 72 |
57 state <- #{ | 73 state <- #{ |
58 new <- :in_grid in_width in_height { | 74 new <- :in_grid in_width in_height { |
59 next_grid <- #[] | 75 nextGrid <- #[] |
76 robot <- false | |
60 foreach: in_grid :index el{ | 77 foreach: in_grid :index el{ |
61 next_grid append: el | 78 nextGrid append: el |
79 if: (el isrobot) { robot <- el } else: { true } | |
62 } | 80 } |
63 #{ | 81 #{ |
64 grid <- in_grid | 82 grid <- in_grid |
65 width <- in_width | 83 width <- in_width |
66 height <- in_height | 84 height <- in_height |
67 robot <- cellTypes robot | |
68 address <- :x y { x + y * width } | 85 address <- :x y { x + y * width } |
69 setCell <- :x y cell { | 86 setCell <- :x y val { |
70 grid set: (address: x y) cell | 87 grid set: (address: x y) val |
71 } | 88 } |
72 getCell <- :x y { | 89 getCell <- :x y { |
73 grid get: (address: x y) | 90 grid get: (address: x y) |
74 } | 91 } |
75 water <- 0 | 92 water <- 0 |
97 } | 114 } |
98 | 115 |
99 } | 116 } |
100 } | 117 } |
101 fromStr <- :str { | 118 fromStr <- :str { |
119 | |
102 strLen <- str byte_length: | 120 strLen <- str byte_length: |
103 index <- 0 | |
104 maxRow <- 0 | 121 maxRow <- 0 |
105 curRow <- 0 | 122 curRow <- 0 |
106 while: {index < strLen} do: { | 123 foreach: str :index element { |
107 curByte <- str byte: index | 124 if: element = ((cellTypes newline) id) { |
108 if: curByte = (cellType newline id) { | 125 maxRow <- if: curRow > maxRow {curRow} else: {maxRow} |
109 maxRow <- if: curRow > maxRow {curRow} else: {maxRow} | 126 curRow <- 0 |
127 } else: { | |
128 curRow <- curRow + 1 | |
129 } | |
130 } | |
131 | |
132 foreach: str :index element { | |
133 if: element = ((cellTypes newline) id) { | |
134 // add spaces | |
135 curRow <- 0 | |
110 } else: { | 136 } else: { |
111 curRow = curRow + 1 | 137 curRow = curRow + 1 |
112 } | 138 } |
113 } | 139 } |
114 grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0) ( "#" byte: 0) (" " byte: 0) ("#" byte: 0) ( "#" byte: 0) ("#" byte: 0) ("#" byte: 0)] | 140 grid <- #[ ("#" byte: 0) ("#" byte: 0) ("#" byte: 0) ( "#" byte: 0) (" " byte: 0) ("#" byte: 0) ( "#" byte: 0) ("#" byte: 0) ("#" byte: 0)] |