comparison src/sim.tp @ 11:f28e465e9ee6

tried to unf*ck, ashamed rebarfing
author William Morgan <bill@mrgn.org>
date Sat, 14 Jul 2012 02:21:32 -0700
parents 370a1eeb8812
children 6ef6dc8ab95e
comparison
equal deleted inserted replaced
10:370a1eeb8812 11:f28e465e9ee6
1 #{ 1 {
2
3 // utilities
4 true <- #{ 2 true <- #{
5 if:else <- :self trueblock :elseblock { 3 if:else <- :self trueblock :elseblock {
6 trueblock: 4 trueblock:
7 } 5 }
8 } 6 }
11 if:else <- :self trueblock :elseblock { 9 if:else <- :self trueblock :elseblock {
12 elseblock: 10 elseblock:
13 } 11 }
14 } 12 }
15 13
16 foreach <- :string action { 14 makeCellTypes <- {
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
28 cellTypes <- #{
29 allstr <- #[] 15 allstr <- #[]
30 allobj <- #[] 16 allobj <- #[]
31 new <- :idstr { 17 new <- :idstr {
32 ret <- #{ 18 ret <- #{
33 id <- (idstr byte: 0) 19 id <- (idstr byte: 0)
35 } 21 }
36 allobj append: ret 22 allobj append: ret
37 allstr append: idstr 23 allstr append: idstr
38 ret 24 ret
39 } 25 }
40 find <- :idstr {
41 if: idstr = "R" { robot } else: {
42 index <- 0
43 while: {
44 if: index < (allstr length) {
45 (allstr get: index) != idstr
46 } else: {false}
47 } do: {
48 index <- index + 1
49 }
50 if: index <- (allstr length) {
51 allobj get: index
52 } else: {
53 empty
54 }
55 }
56 }
57 wall <- new: "#"
58 empty <- new: " "
59 earth <- new: "."
60 rock <- new: "*"
61 lambda <- new: "\\"
62 closedlift <- new: "L"
63 openlift <- new: "O"
64 newline <- new: "\n"
65 robot <- {
66 #{ 26 #{
67 id <- ("R" byte: 0) 27 find <- :idstr {
68 isrobot <- { true } 28 if: idstr = "R" { robot } else: {
69 heldBreath <- 0 29 index <- 0
30 while: {
31 if: index < (allstr length) {
32 (allstr get: index) != idstr
33 } else: {false}
34 } do: {
35 index <- index + 1
36 }
37 if: index < (allstr length) {
38 allobj get: index
39 } else: {
40 empty
41 }
42 }
43 }
44 wall <- new: "#"
45 empty <- new: " "
46 earth <- new: "."
47 rock <- new: "*"
48 lambda <- new: "\\"
49 closedlift <- new: "L"
50 openlift <- new: "O"
51 newline <- new: "\n"
52 robot <- {
53 #{
54 id <- ("R" byte: 0)
55 isrobot <- { true }
56 heldBreath <- 0
57 }
58 }
70 } 59 }
71 } 60 }
61 ttrue <- true
62 tfalse <- false
63 #{
64
65 // utilities
66 true <- {ttrue}
67
68 false <- {tfalse}
69
70 foreach <- :string action {
71 strLen <- string byte_length:
72 index <- 0
73 while: {index < strLen} do: {
74 element <- (string byte: index)
75 action: index element
76 index <- index + 1
77 }
78 }
79 // end utilities
80
81
82 cellTypes <- makeCellTypes:
72 83
73 state <- #{ 84 state <- #{
74 new <- :in_grid in_width in_height { 85 new <- :in_grid in_width in_height {
75 nextGrid <- #[] 86 nextGrid <- #[]
76 robot <- false 87 robot <- false
100 robo <- doMove r 111 robo <- doMove r
101 nexty <- doMove y 112 nexty <- doMove y
102 ended <- roboMove = "A" 113 ended <- roboMove = "A"
103 } 114 }
104 doUpdate <- { 115 doUpdate <- {
105 updateCell <- :x, y { 116 updateCell <- :x y {
106 if 117 //if
107 } 118 }
108 } 119 }
109 advance <- :roboCmd { 120 advance <- :roboCmd {
110 robot move: roboCmd 121 robot move: roboCmd
111 moves <- moves + 1 122 moves <- moves + 1
187 } 198 }
188 } 199 }
189 } 200 }
190 201
191 } 202 }
203 }