Generate until events meet goal.
Chris Pressey
6 years ago
70 | 70 | |
71 | 71 | * (+) Allow scenarios to define a termination condition, so that the implementation |
72 | 72 | can generate a scene where the condition is met (by whatever method). |
73 | * (+) Allow scenarios to specify a minimum number of events to generate. | |
74 | 73 | * (+) Consider what it would take to add a predicate that evaluates to whether |
75 | 74 | a given action has been taken previously or not. |
76 | 75 | * (+) Consider macros. |
88 | 87 | #### Probably we don't do |
89 | 88 | |
90 | 89 | * (+) Allow sentence trees to be given for actions. |
90 | * (+) Allow scenarios to specify a minimum number of events to generate. |
91 | 91 | description to be spread over multiple source files, but there is no |
92 | 92 | facility to reference one source file from another in Samovar, so how |
93 | 93 | 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. | |
94 | 120 | |
95 | 121 | chairs |
96 | 122 | ------ |
31 | 31 | self.state.add(term) |
32 | 32 | |
33 | 33 | 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 | |
39 | 44 | 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 | |
40 | 49 | |
41 | 50 | def generate_move(self): |
42 | 51 | candidates = self.get_candidate_rules() |