comparison src/sim.tp @ 31:f7a1daaec925

Use dictionary
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 21:27:36 -0700
parents 031d46ff76a9
children 0a55ee387d69
comparison
equal deleted inserted replaced
30:031d46ff76a9 31:f7a1daaec925
12 debugLog <- :str { 12 debugLog <- :str {
13 os write: 2 str 13 os write: 2 str
14 } 14 }
15 15
16 makeCellTypes <- { 16 makeCellTypes <- {
17 allid <- #[] 17 typedict <- dict linear
18 allobj <- #[]
19 new <- :idStr { 18 new <- :idStr {
20 ret <- #{ 19 ret <- #{
21 id <- (idStr byte: 0) 20 id <- (idStr byte: 0)
22 str <- idStr 21 str <- idStr
23 isrobot <- { false } 22 isrobot <- { false }
24 } 23 }
25 allobj append: ret 24 typedict set: (ret id) ret
26 allid append: (ret id)
27 ret 25 ret
28 } 26 }
29 #{ 27 #{
30 find <- :id { 28 find <- :id {
31 if: id = ("R" byte: 0) { robot: } else: { 29 if: id = ("R" byte: 0) { robot: } else: {
32 index <- 0 30 typedict get: id withDefault: empty
33 while: {
34 if: index < (allid length) {
35 (allid get: index) != id
36 }
37 } do: {
38 index <- index + 1
39 }
40 if: index < (allid length) {
41 allobj get: index
42 } else: {
43 empty
44 }
45 } 31 }
46 } 32 }
47 wall <- new: "#" 33 wall <- new: "#"
48 empty <- new: " " 34 empty <- new: " "
49 earth <- new: "." 35 earth <- new: "."