ceml 0.5.0 → 0.5.1
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.
- data/VERSION +1 -1
- data/ceml.gemspec +1 -1
- data/lib/ceml/casting_criterion.rb +9 -4
- data/lib/ceml/driver.rb +1 -4
- data/lib/ceml/incident.rb +3 -0
- data/lib/ceml/tt/instructions.treetop +10 -2
- data/test/helper.rb +6 -1
- data/test/test_incident.rb +72 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.5.
|
1
|
+
0.5.1
|
data/ceml.gemspec
CHANGED
@@ -2,7 +2,7 @@ require 'geokit'
|
|
2
2
|
require "forwardable"
|
3
3
|
|
4
4
|
module CEML
|
5
|
-
class Candidate < Struct.new :uid, :tags, :matchables, :lat, :lng
|
5
|
+
class Candidate < Struct.new :uid, :tags, :matchables, :lat, :lng, :initial_state
|
6
6
|
include Geokit::Mappable
|
7
7
|
attr_reader :criteria
|
8
8
|
|
@@ -37,13 +37,18 @@ module CEML
|
|
37
37
|
|
38
38
|
# this method will miss possible castings and does not handle ranges at all
|
39
39
|
def cast
|
40
|
-
|
40
|
+
[].tap do |casting|
|
41
41
|
criteria.each do |c|
|
42
42
|
return nil unless folks = hash[c].dup
|
43
|
-
folks -= casting
|
43
|
+
folks -= casting
|
44
44
|
return nil unless folks.size >= c.min_match
|
45
45
|
c.role_counts.each do |role, minct|
|
46
|
-
folks.shift(minct).each
|
46
|
+
folks.shift(minct).each do |guy|
|
47
|
+
guy.initial_state ||= {}
|
48
|
+
guy.initial_state[:id] = guy.uid
|
49
|
+
guy.initial_state[:roles] = role.to_sym
|
50
|
+
casting << guy
|
51
|
+
end
|
47
52
|
end
|
48
53
|
end
|
49
54
|
end
|
data/lib/ceml/driver.rb
CHANGED
@@ -42,16 +42,13 @@ module CEML
|
|
42
42
|
run incident_id
|
43
43
|
end
|
44
44
|
|
45
|
-
# yields a thing with #each and #<<
|
46
45
|
def ping script, candidate
|
47
46
|
LOCATIONS[script] ||= []
|
48
47
|
script.post candidate, LOCATIONS[script]
|
49
48
|
LOCATIONS[script].delete_if do |loc|
|
50
49
|
next unless loc.cast
|
51
50
|
iid = start(script)
|
52
|
-
loc.cast.each
|
53
|
-
post iid, :id => k, :roles => v
|
54
|
-
end
|
51
|
+
loc.cast.each{ |guy| post iid, guy.initial_state }
|
55
52
|
end
|
56
53
|
end
|
57
54
|
end
|
data/lib/ceml/incident.rb
CHANGED
@@ -42,6 +42,8 @@ module CEML
|
|
42
42
|
instrs = script.instructions_for(roles)
|
43
43
|
instrs.each do |inst|
|
44
44
|
case inst.cmd
|
45
|
+
when :register
|
46
|
+
bytecode << [:answered_q, inst]
|
45
47
|
when :ask
|
46
48
|
bytecode << [:ask_q, inst]
|
47
49
|
bytecode << [:answered_q, inst]
|
@@ -63,6 +65,7 @@ module CEML
|
|
63
65
|
end
|
64
66
|
|
65
67
|
def expand(role, var)
|
68
|
+
return (this[:qs_answers]||{})[var] if role =~ /^his|her$/
|
66
69
|
role = nil if role == 'otherguy'
|
67
70
|
role = role.to_sym if role
|
68
71
|
@players.each do |p|
|
@@ -3,7 +3,7 @@ grammar Instructions
|
|
3
3
|
include Lexer
|
4
4
|
|
5
5
|
rule instruction_stmt
|
6
|
-
(ask_stmt / tell_stmt / assign_stmt) {
|
6
|
+
(ask_stmt / tell_stmt / assign_stmt / register_stmt) {
|
7
7
|
|
8
8
|
INTERPOLATE_REGEX = /\|(\w+)\.?(\w+)?\|/
|
9
9
|
|
@@ -17,15 +17,23 @@ grammar Instructions
|
|
17
17
|
|
18
18
|
def role; id.text_value.to_sym; end
|
19
19
|
def text; super.text_value; end
|
20
|
-
def var
|
20
|
+
def var
|
21
|
+
return varname.text_value if cmd == :register
|
22
|
+
(!defined?(:about) || about.empty?) ? nil : about.varname.text_value;
|
23
|
+
end
|
21
24
|
def key; var || text; end
|
22
25
|
def cmd;
|
23
26
|
text_value =~ /^ask/ and return :ask
|
24
27
|
text_value =~ /^(tell|assign)/ and return :tell
|
28
|
+
text_value =~ /^register/ and return :register
|
25
29
|
end
|
26
30
|
}
|
27
31
|
end
|
28
32
|
|
33
|
+
rule register_stmt
|
34
|
+
'register' ws id ws varname:id
|
35
|
+
end
|
36
|
+
|
29
37
|
rule tell_stmt
|
30
38
|
'tell' ws id ':' ws? text
|
31
39
|
end
|
data/test/helper.rb
CHANGED
@@ -12,6 +12,8 @@ class Test::Unit::TestCase
|
|
12
12
|
@iid = script && DRIVER.start(script)
|
13
13
|
yield
|
14
14
|
CEML::Driver::JUST_SAID.clear
|
15
|
+
CEML::Driver::PLAYERS.clear
|
16
|
+
CEML::Driver::INCIDENTS.clear
|
15
17
|
end
|
16
18
|
|
17
19
|
def ping s, candidate
|
@@ -19,7 +21,10 @@ class Test::Unit::TestCase
|
|
19
21
|
end
|
20
22
|
|
21
23
|
def says id, str
|
22
|
-
|
24
|
+
iid = CEML::Driver::INCIDENTS.keys.find do |iid|
|
25
|
+
CEML::Driver::PLAYERS[iid].find{ |p| p[:id] == id }
|
26
|
+
end
|
27
|
+
DRIVER.post iid, :id => id, :received => str
|
23
28
|
end
|
24
29
|
|
25
30
|
def player id, *roles
|
data/test/test_incident.rb
CHANGED
@@ -8,8 +8,80 @@ ask organizer re target: Describe their appearance and location
|
|
8
8
|
tell agents: Look for |otherguy.target| and compliment them briefly, then move on.
|
9
9
|
XXX
|
10
10
|
|
11
|
+
JANE_SCRIPT = <<XXX
|
12
|
+
|
13
|
+
await 1 new signup
|
14
|
+
register signup first_name
|
15
|
+
ask signup re shoeless:
|
16
|
+
Hello |his.first_name|. You are Level Zero. Lowly level zero.
|
17
|
+
To advance to Level 1, please remove a shoe. Keep it off,
|
18
|
+
and text back "shoeless".
|
19
|
+
tell signup:
|
20
|
+
O ho! Well done |his.first_name|. Now the other players
|
21
|
+
know you're in the game, too. But you're still a sad Level 1.
|
22
|
+
ask signup re game:
|
23
|
+
To advance to Level 2, answer this question. What was your
|
24
|
+
favorite game when you were 10 years old? Tell me now.
|
25
|
+
tell signup:
|
26
|
+
Ah yes. |his.game| WAS an amazing game. You should try to play
|
27
|
+
it again--sometime this week, perhaps?
|
28
|
+
In the meantime you are but a mere Level 2. Let's see if we can do
|
29
|
+
something about that. (You still have your shoe off, right?)
|
30
|
+
ask signup re friend:
|
31
|
+
While you're texting... Pick someone in your address book you
|
32
|
+
haven't talked to in a while. Send them an SMS
|
33
|
+
just to say hello. Then tell me their first name.
|
34
|
+
tell signup:
|
35
|
+
That was awfully nice of you to message |his.friend|
|
36
|
+
Welcome to the amazing Level 3. You'll like it here. Stay awhile.
|
37
|
+
tell signup:
|
38
|
+
Just kidding. Level 4 is way better than this. To get to
|
39
|
+
Level 4, wait for an appropriate moment in Jane's talk
|
40
|
+
and shout an encouraging "Amen!" Yes. Out loud.
|
41
|
+
ask signup re amen:
|
42
|
+
If you're not the spiritual type, a forceful "YEAH!" will do.
|
43
|
+
When you've accomplished your mission, text me "amen".
|
44
|
+
tell signup:
|
45
|
+
Wow. I didn't think you had it in you. No one has ever gotten to
|
46
|
+
Level 4 before. This is VERY exciting.
|
47
|
+
tell signup:
|
48
|
+
If you get to Level 5, I'll give you a secret password. Tell it to
|
49
|
+
Jane, and you'll get some very fancy loot.
|
50
|
+
ask signup re ovation:
|
51
|
+
All you have to do is wait until the end of Jane's talk--and try to
|
52
|
+
spark a standing ovation. Good luck! Text ovation afterward for your
|
53
|
+
password.
|
54
|
+
tell signup:
|
55
|
+
You did it! You are Level 5. You are AMAZING. The conquering hero of
|
56
|
+
the entire audience! Now I can give you your password.
|
57
|
+
tell signup:
|
58
|
+
Ask Jane to sign a copy of her book to Mr. Gamey McGameful. Of course,
|
59
|
+
this will only work if she saw you standing in that ovation. You were
|
60
|
+
standing, right?
|
61
|
+
XXX
|
62
|
+
|
11
63
|
class TestIncident < Test::Unit::TestCase
|
12
64
|
|
65
|
+
def test_jane
|
66
|
+
s = CEML.parse(:script, JANE_SCRIPT)
|
67
|
+
play do
|
68
|
+
c = CEML::Candidate.new('fred', ['new'], {})
|
69
|
+
c.initial_state = { :received => 'freddy' }
|
70
|
+
ping s, c
|
71
|
+
asked 'fred', /Hello freddy. You are Level Zero./
|
72
|
+
says 'fred', "shoeless"
|
73
|
+
asked 'fred', /favorite game/
|
74
|
+
says 'fred', "monopoly"
|
75
|
+
asked 'fred', /Pick someone in your address/
|
76
|
+
says 'fred', 'jim'
|
77
|
+
asked 'fred', /forceful/
|
78
|
+
says 'fred', 'okay'
|
79
|
+
asked 'fred', /standing ovation/
|
80
|
+
says 'fred', 'did it'
|
81
|
+
told 'fred', /Gamey/
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
13
85
|
def test_signup_1
|
14
86
|
s = CEML.parse(:script, "await 1 new signup\ntell signup: thanks")
|
15
87
|
play do
|