rachinations 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +3 -1
- data/README.md +184 -5
- data/lib/rachinations.rb +5 -4
- data/lib/rachinations/domain/diagrams/diagram.rb +35 -24
- data/lib/rachinations/domain/exceptions/bad_config.rb +1 -1
- data/lib/rachinations/domain/{exceptions → modules/common}/bad_options.rb +0 -0
- data/lib/rachinations/domain/modules/common/hash_init.rb +1 -0
- data/lib/rachinations/domain/modules/common/refiners/number_modifiers.rb +2 -1
- data/lib/rachinations/domain/modules/diagrams/verbose.rb +1 -1
- data/lib/rachinations/domain/nodes/gate.rb +23 -27
- data/lib/rachinations/domain/nodes/node.rb +4 -20
- data/lib/rachinations/domain/nodes/pool.rb +2 -3
- data/lib/rachinations/domain/nodes/resourceful_node.rb +4 -3
- data/lib/rachinations/domain/nodes/sink.rb +1 -1
- data/lib/rachinations/dsl/bad_dsl.rb +3 -0
- data/lib/rachinations/dsl/bootstrap.rb +10 -8
- data/lib/rachinations/dsl/diagram_shorthand_methods.rb +10 -5
- data/lib/rachinations/dsl/helpers/parser.rb +83 -49
- data/lib/rachinations/helpers/edge_helper.rb +105 -8
- data/lib/rachinations/utils/math_utils.rb +83 -0
- data/lib/rachinations/utils/string_utils.rb +8 -0
- data/lib/rachinations/version.rb +1 -1
- data/rachinations.gemspec +2 -1
- data/testing/spec/diagram_spec.rb +78 -17
- data/testing/spec/gate_spec.rb +223 -2
- data/testing/spec/non_deterministic_diagram_spec.rb +1 -1
- data/testing/spec/release1/dsl_spec.rb +100 -3
- data/testing/spec/release1/individual_cases_spec.rb +39 -0
- data/testing/spec/release1/monografia_spec.rb +69 -0
- metadata +24 -5
- data/lib/rachinations/utils/string_helper.rb +0 -7
@@ -153,7 +153,6 @@ describe Diagram do
|
|
153
153
|
|
154
154
|
end
|
155
155
|
|
156
|
-
|
157
156
|
it 'example using push_all, activators and triggers' do
|
158
157
|
|
159
158
|
d = diagram do
|
@@ -218,7 +217,6 @@ describe Diagram do
|
|
218
217
|
|
219
218
|
end
|
220
219
|
|
221
|
-
|
222
220
|
it "accepts declaring forward-referencing of non existing nodes" do
|
223
221
|
|
224
222
|
expect do
|
@@ -244,7 +242,7 @@ describe Diagram do
|
|
244
242
|
it 'runs diagrams using forward-referencing' do
|
245
243
|
|
246
244
|
d = diagram do
|
247
|
-
pool 'p2'
|
245
|
+
pool 'p2', :automatic, :push_any, initial_value: 7 # this will be triggered 10 times
|
248
246
|
edge from: 'p2', to: 'p3'
|
249
247
|
pool 'p3'
|
250
248
|
end
|
@@ -266,5 +264,104 @@ describe Diagram do
|
|
266
264
|
|
267
265
|
end
|
268
266
|
|
267
|
+
it 'runs until safeguard clauses have been met if run method is called with no params' do
|
268
|
+
|
269
|
+
expect {
|
270
|
+
|
271
|
+
d = diagram do
|
272
|
+
source 's1'
|
273
|
+
edge from: 's1', to: 'p1'
|
274
|
+
pool 'p1'
|
275
|
+
end
|
276
|
+
|
277
|
+
d.run
|
278
|
+
|
279
|
+
}.not_to raise_exception
|
280
|
+
end
|
281
|
+
|
282
|
+
it 'stops when a single stopping condition turns true' do
|
283
|
+
|
284
|
+
d = diagram 'win_lose' do
|
285
|
+
|
286
|
+
sink 'sink'
|
287
|
+
|
288
|
+
source 'green_shots', :automatic
|
289
|
+
edge from: 'green_shots', to: 'g1'
|
290
|
+
gate 'g1'
|
291
|
+
edge from: 'g1', to: 'green_points', label: 40.percent
|
292
|
+
# it feels a bit weird having to add a sink just to make labels add up to 1
|
293
|
+
edge from: 'g1', to: 'sink', label: 60.percent
|
294
|
+
pool 'green_points'
|
295
|
+
|
296
|
+
source 'red_shots', :automatic
|
297
|
+
edge from: 'red_shots', to: 'g2'
|
298
|
+
gate 'g2'
|
299
|
+
edge from: 'g2', to: 'red_points', label: 50.percent
|
300
|
+
# it feels a bit weird having to add a sink just to make labels add up to 1
|
301
|
+
edge from: 'g2', to: 'sink', label: 50.percent
|
302
|
+
pool 'red_points'
|
303
|
+
|
304
|
+
stop 'green wins', expr { green_points.resource_count >= 10 }
|
305
|
+
stop 'red wins', expr { red_points.resource_count >= 10 }
|
306
|
+
|
307
|
+
end
|
308
|
+
|
309
|
+
d.run
|
310
|
+
expect(d.green_points.resource_count == 10 || d.red_points.resource_count == 10).to be true
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
it 'probabilistic gates' do
|
315
|
+
|
316
|
+
d = diagram 'exemplo_3_monografia' do
|
317
|
+
source 's1'
|
318
|
+
gate 'g1', :probabilistic
|
319
|
+
pool 'p1'
|
320
|
+
pool 'p2'
|
321
|
+
pool 'p3'
|
322
|
+
sink 's2', :automatic, condition: expr{ p2.resource_count > 30 }
|
323
|
+
edge from: 's1', to: 'g1'
|
324
|
+
edge from: 'g1', to: 'p1'
|
325
|
+
edge 2,from:'g1', to:'p2'
|
326
|
+
edge from:'g1', to:'p3'
|
327
|
+
edge from:'p3', to:'s2'
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
d.run
|
332
|
+
|
333
|
+
# after a lot of turns, the sink will dominate other nodes
|
334
|
+
# using a range because in the last turn p3 may have received one resource and
|
335
|
+
# maybe the sink hasn't pulled it yet
|
336
|
+
expect(d.p3.resource_count).to be_within(1).of(0)
|
337
|
+
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'deterministic gates' do
|
341
|
+
|
342
|
+
# this example was taken from gate_spec.rb and adapted to use the DSL instead.
|
343
|
+
|
344
|
+
d = diagram do
|
345
|
+
source 's'
|
346
|
+
gate 'g', :deterministic
|
347
|
+
pool 'p1'
|
348
|
+
pool 'p2'
|
349
|
+
pool 'p3'
|
350
|
+
edge from: 's', to: 'g'
|
351
|
+
edge 2, from: 'g', to: 'p1'
|
352
|
+
edge from: 'g', to: 'p2'
|
353
|
+
edge from: 'g', to: 'p3'
|
354
|
+
end
|
355
|
+
|
356
|
+
d.run 12
|
357
|
+
|
358
|
+
expect(d.p1.resource_count).to eq(6)
|
359
|
+
expect(d.p2.resource_count).to eq(3)
|
360
|
+
expect(d.p3.resource_count).to eq(3)
|
361
|
+
|
362
|
+
|
363
|
+
end
|
364
|
+
|
269
365
|
end
|
366
|
+
|
270
367
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe 'Special diagram examples' do
|
4
|
+
|
5
|
+
it 'ticket #77' do
|
6
|
+
|
7
|
+
skip
|
8
|
+
|
9
|
+
p=diagram 'strongerpingpong', mode: :verbose do
|
10
|
+
|
11
|
+
pool 'left', :automatic, initial_value: 1
|
12
|
+
pool 'right', :automatic
|
13
|
+
|
14
|
+
source 'newleft', activation: :passive
|
15
|
+
source 'newright', activation: :passive
|
16
|
+
|
17
|
+
pool 'rightpoint', triggers: 'newright'
|
18
|
+
pool 'leftpoint', triggers: 'newleft'
|
19
|
+
|
20
|
+
gate 'lgame'
|
21
|
+
gate 'rgame'
|
22
|
+
|
23
|
+
edge from: 'left', to: 'lgame'
|
24
|
+
edge from: 'lgame', to: 'right', label: 3/7
|
25
|
+
edge from: 'lgame', to: 'rightpoint', label: 4/5
|
26
|
+
|
27
|
+
edge from: 'right', to: 'rgame'
|
28
|
+
edge from: 'rgame', to: 'left', label: 3/5
|
29
|
+
edge from: 'rgame', to: 'leftpoint', label: 2/5
|
30
|
+
|
31
|
+
edge from: 'newleft', to: 'left', label: 1
|
32
|
+
edge from: 'newright', to: 'right', label: 1
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
p.run 10
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe 'monografia spec' do
|
4
|
+
|
5
|
+
describe 'examples without dsl' do
|
6
|
+
|
7
|
+
end
|
8
|
+
|
9
|
+
describe 'examples with dsl' do
|
10
|
+
|
11
|
+
it 'example_3' do
|
12
|
+
|
13
|
+
diagram 'exemplo_3' do
|
14
|
+
|
15
|
+
source 's1'
|
16
|
+
gate 'g1', :probabilistic
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'full specification' do
|
24
|
+
|
25
|
+
context ' when creating diagram' do
|
26
|
+
|
27
|
+
it 'is created with no name or options' do
|
28
|
+
|
29
|
+
diagram do
|
30
|
+
pool
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'is created with name but no options' do
|
36
|
+
|
37
|
+
diagram 'my_diagram' do
|
38
|
+
pool 98
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'is created with all supported options' do
|
44
|
+
|
45
|
+
[:default, :silent, :verbose].each do |runmode|
|
46
|
+
|
47
|
+
diagram 'test', mode: runmode do
|
48
|
+
pool 89
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'complains if given option is invalid' do
|
56
|
+
|
57
|
+
expect {
|
58
|
+
diagram 'test', mode: :foo do
|
59
|
+
pool
|
60
|
+
end
|
61
|
+
}.to raise_error(BadDSL)
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rachinations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Felipe Almeida
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -136,8 +136,22 @@ dependencies:
|
|
136
136
|
- - '='
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: 1.0.0
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: fraction
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - '='
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: 0.3.2
|
146
|
+
type: :runtime
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - '='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 0.3.2
|
139
153
|
description: |-
|
140
|
-
This project provides a Ruby-based
|
154
|
+
This project provides a Ruby-based Diagram to enable game designers to
|
141
155
|
design and also test tentative game designs and/or prototypes
|
142
156
|
email:
|
143
157
|
- falmeida1988@gmail.com
|
@@ -161,11 +175,11 @@ files:
|
|
161
175
|
- lib/rachinations/domain/edge_collection.rb
|
162
176
|
- lib/rachinations/domain/edges/edge.rb
|
163
177
|
- lib/rachinations/domain/exceptions/bad_config.rb
|
164
|
-
- lib/rachinations/domain/exceptions/bad_options.rb
|
165
178
|
- lib/rachinations/domain/exceptions/no_elements_found.rb
|
166
179
|
- lib/rachinations/domain/exceptions/no_elements_matching_condition_error.rb
|
167
180
|
- lib/rachinations/domain/exceptions/no_elements_of_given_type.rb
|
168
181
|
- lib/rachinations/domain/exceptions/unsupported_type_error.rb
|
182
|
+
- lib/rachinations/domain/modules/common/bad_options.rb
|
169
183
|
- lib/rachinations/domain/modules/common/hash_init.rb
|
170
184
|
- lib/rachinations/domain/modules/common/invariant.rb
|
171
185
|
- lib/rachinations/domain/modules/common/refiners/number_modifiers.rb
|
@@ -193,7 +207,8 @@ files:
|
|
193
207
|
- lib/rachinations/extras/constant_hash.rb
|
194
208
|
- lib/rachinations/extras/fifo.rb
|
195
209
|
- lib/rachinations/helpers/edge_helper.rb
|
196
|
-
- lib/rachinations/utils/
|
210
|
+
- lib/rachinations/utils/math_utils.rb
|
211
|
+
- lib/rachinations/utils/string_utils.rb
|
197
212
|
- lib/rachinations/version.rb
|
198
213
|
- machinations_diagrams/apenas_bonito.xml
|
199
214
|
- machinations_diagrams/behavior_converter.xml
|
@@ -242,6 +257,8 @@ files:
|
|
242
257
|
- testing/spec/non_deterministic_diagram_spec.rb
|
243
258
|
- testing/spec/pool_spec.rb
|
244
259
|
- testing/spec/release1/dsl_spec.rb
|
260
|
+
- testing/spec/release1/individual_cases_spec.rb
|
261
|
+
- testing/spec/release1/monografia_spec.rb
|
245
262
|
- testing/spec/source_spec.rb
|
246
263
|
- testing/spec/spec_helper.rb
|
247
264
|
- testing/spec/xexeo_spec.rb
|
@@ -290,6 +307,8 @@ test_files:
|
|
290
307
|
- testing/spec/non_deterministic_diagram_spec.rb
|
291
308
|
- testing/spec/pool_spec.rb
|
292
309
|
- testing/spec/release1/dsl_spec.rb
|
310
|
+
- testing/spec/release1/individual_cases_spec.rb
|
311
|
+
- testing/spec/release1/monografia_spec.rb
|
293
312
|
- testing/spec/source_spec.rb
|
294
313
|
- testing/spec/spec_helper.rb
|
295
314
|
- testing/spec/xexeo_spec.rb
|