comparison src/sim.tp @ 32:0a55ee387d69

Change grid order
author Mike Pavone <pavone@retrodev.com>
date Sat, 14 Jul 2012 23:03:04 -0700
parents f7a1daaec925
children efa82c5e95c2
comparison
equal deleted inserted replaced
31:f7a1daaec925 32:0a55ee387d69
100 moves <- moves + 1 100 moves <- moves + 1
101 doUpdate: 101 doUpdate:
102 self 102 self
103 } 103 }
104 printGrid <- { 104 printGrid <- {
105 grid foreach: :index value { 105 cur <- (grid length) - width
106 os write: 2 (value str) 106 col <- 0
107 if: index % width = width - 1 { 107 while: {cur >= 0} do: {
108 os write: 2 ((grid get: cur) str)
109 cur <- cur + 1
110 col <- col + 1
111 if: col = width {
112 col <- 0
113 cur <- cur - (width + width)
108 os write: 2 "\n" 114 os write: 2 "\n"
109 } 115 }
110 } 116 }
111 } 117 }
112 } 118 }
113 foreach: in_grid :index el{ 119 foreach: in_grid :index el{
114 nextGrid append: el 120 nextGrid append: el
115 if: (el isrobot) { 121 if: (el isrobot) {
116 robot <- el 122 robot <- el
117 ret updatePos: robot index 123 ret updatePos: robot index
118 } 124 }
119 } 125 }
120 ret 126 ret
121 } 127 }
128
122 fromStr <- :str { 129 fromStr <- :str {
123 strLen <- str byte_length: 130 strLen <- str byte_length:
124 maxCol <- 0 131 maxCol <- 0
125 col <- 0
126 rows <- 0
127 nl <- (cellTypes newline) id 132 nl <- (cellTypes newline) id
128 blank <- cellTypes empty 133 blank <- cellTypes empty
134 lines <- #[]
135 curline <- #[]
129 eachbyte: str :index element { 136 eachbyte: str :index element {
130 if: element = nl { 137 if: element = nl {
138 col <- curline length
131 maxCol <- if: col > maxCol {col} else: {maxCol} 139 maxCol <- if: col > maxCol {col} else: {maxCol}
132 col <- 0 140 lines append: curline
133 rows <- rows + 1 141 curline <- #[]
134 } else: { 142 } else: {
135 col <- col + 1 143 curline append: (cellTypes find: element)
136 } 144 }
137 } 145 }
138 col <- 0
139 grid <- #[] 146 grid <- #[]
140 eachbyte: str :index element { 147 cur <- (lines length) - 1
141 if: element = nl { 148 while: { cur >= 0 } do: {
142 // add spaces 149 curline <- (lines get: cur)
143 while: { col < maxCol } do: { 150 foreach: curline :idx el {
144 grid append: blank 151 grid append: el
145 col <- col + 1 152 }
146 } 153 extra <- maxCol - (curline length)
147 col <- 0 154 while: { extra > 0 } do: {
148 } else: { 155 grid append: blank
149 grid append: (cellTypes find: element) 156 extra <- extra - 1
150 col <- col + 1 157 }
151 } 158 cur <- cur - 1
152 } 159 }
153 new: grid maxCol rows 160 new: grid maxCol (lines length)
154 } 161 }
155 } 162 }
156 163
157 testMoves <- { 164 testMoves <- {
158 myStep <- 0 165 myStep <- 0