git @ Cat's Eye Technologies Samovar / fb5a00f
Generate until events meet goal. Chris Pressey 6 years ago
3 changed file(s) with 41 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
7070
7171 * (+) Allow scenarios to define a termination condition, so that the implementation
7272 can generate a scene where the condition is met (by whatever method).
73 * (+) Allow scenarios to specify a minimum number of events to generate.
7473 * (+) Consider what it would take to add a predicate that evaluates to whether
7574 a given action has been taken previously or not.
7675 * (+) Consider macros.
8887 #### Probably we don't do
8988
9089 * (+) Allow sentence trees to be given for actions.
90 * (+) Allow scenarios to specify a minimum number of events to generate.
9191 description to be spread over multiple source files, but there is no
9292 facility to reference one source file from another in Samovar, so how
9393 they are located and collected is up to the implementation.
94
95 Goals
96 -----
97
98 A scenario is run until it meets the goal. How it meets the goal
99 is up to the implementation. Our implementation generates events
100 randomly, until it comes up with a series of events wherein the
101 goal is met, generating more events each time.
102
103 A goal of `[]`, as above, is trivially met.
104
105 Generation of events does not stop immediately once the goal is
106 met. A number of events are generated, and then the check is made.
107
108 scenario UntilHoldBrick {
109 [actor(α),item(β),~holding(α,β)] α picks up the β. [holding(α,β)]
110 [actor(α),item(β),holding(α,β)] α puts down the β. [~holding(α,β)]
111 actor(Ignatz).
112 item(brick).
113 item(oilcan).
114 goal [holding(Ignatz,brick)].
115 }
116 ===> Ignatz picks up the oilcan.
117 ===> Ignatz puts down the oilcan.
118 ===> Ignatz picks up the brick.
119 ===> Ignatz picks up the oilcan.
94120
95121 chairs
96122 ------
3131 self.state.add(term)
3232
3333 def generate_events(self, count):
34 if self.debug:
35 self.debug_state()
36 moves = []
37 for i in xrange(0, count):
38 moves.append(self.generate_move())
34 acceptable = False
35 while not acceptable:
36 if self.debug:
37 self.debug_state()
38 moves = []
39 for i in xrange(0, count):
40 moves.append(self.generate_move())
41 acceptable = self.events_meet_goal(moves)
42 if not acceptable:
43 count *= 2
3944 return moves
45
46 def events_meet_goal(self, moves):
47 matches = match_all(self.state, self.scenario.goal.exprs, {})
48 return len(matches) > 0
4049
4150 def generate_move(self):
4251 candidates = self.get_candidate_rules()