git @ Cat's Eye Technologies ALPACA / 30a1d28
Flesh out more examples, implement state predicate. catseye 12 years ago
4 changed file(s) with 45 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
174174
175175 ##### State Referents #####
176176
177 -> Tests for functionality "Evolve ALPACA CA one generation"
178
177179 A state referent may be:
178180
179181 * the name of a defined state, to refer to that state directly
181183 * a chain of _arrows_, to refer to the state of the cell found at
182184 that relative position in the playfield
183185
184 Example: a somewhat less simple ALPACA description. Here the states
185 have transition rules that cause each cell to take on the state of the
186 cell to the "north" (immediately above it.) The effect would be to
187 make any form in this cellular automaton "scroll downwards":
188
189 | state Space
186 Example: a somewhat less simple ALPACA description. Here the (non-empty)
187 states have transition rules that cause each cell to take on the state of one
188 of its neighbours; `Up` cells take on the state of the cell to the "north"
189 (immediately above it) while `Down` cells take on the state of the cell to
190 the "south" (immediately below it.) The effect in this example is for the
191 cells to "swap places":
192
193 | state Space " ";
194 | state Up "U"
190195 | to ^ when true;
191 | state Thing
192 | to ^ when true.
193 = ok
196 | state Down "D"
197 | to v when true
198 | begin
199 | DDD
200 | UUU
201 = -----
202 = UUU
203 = DDD
204 = -----
194205
195206 An arrow is either `^` (referring to one cell "north" or "above" the
196207 current cell,) `v` (one cell "south" or "below",) `<` (one cell "west"
203214 Example: an ALPACA description of a cellular automaton where `Thing`
204215 elements grow "streaks" to the northwest (diagonally up and to the left.)
205216
206 | state Space
217 | state Space " "
207218 | to Thing when v> Thing;
208 | state Thing.
209 = ok
219 | state Thing "*"
220 | begin
221 | *
222 | *
223 = -----
224 = *
225 = **
226 = *
227 = -----
210228
211229 ##### Boolean Expressions #####
230
231 -> Tests for functionality "Parse ALPACA Description"
212232
213233 The boolean expression may be:
214234
0 state Space " "
1 to Thing when v> Thing;
2 state Thing "*"
3 begin
4 *
5 *
4646 #print "(%d,%d) has %d neighbours that are %s" % (x, y, count, state)
4747 return count >= int(ast.value)
4848 elif ast.type == 'Relational':
49 raise NotImplementedError
49 state0 = eval_state_ref(playfield, x, y, ast.children[0])
50 state1 = eval_state_ref(playfield, x, y, ast.children[1])
51 return state0 == state1
5052 elif ast.type == 'BoolLit':
5153 if ast.value == 'true':
5254 return True
215215 else:
216216 s1 = self.state_ref()
217217 self.scanner.consume('=') # optional
218 if self.scanner.consume('is'):
219 classid = self.scanner.consume_type('identifier')
220 return AST('RelationalClass', [s1], value=classid)
218 if self.scanner.on('is'):
219 c = self.class_decl()
220 return AST('RelationalClass', [s1, c])
221221 s2 = self.state_ref()
222 return AST('Relational', [s2])
222 return AST('Relational', [s1, s2])
223223
224224
225225 def resolve_arrow_chain(s):