1: def adm(l, m=[], n=0)
2: nr_attacks = 0
3: n.m "STS: #{l.name} / #{m.name}";
4: k = l.last
5: n.m "#{con}: starting attack against #{k.name}"
6: k.attackers(con, n) do |a|
7: catch :next_attacker do
8:
9: nr_attacks += 1
10: n.m "#{con}: found #{nr_attacks.st} attacker #{a.name} against CON's #{k.name}: #{a.name}"
11:
12: if m.include?(a) then
13:
14: n.m "#{con}: can't repeat attack #{a.name}"
15: next
16: end
17: n.m "#{pro}: starting defense against attack #{k.name} <- #{a.name}"
18:
19: l.each { |d|
20: if d.attacks? a then
21: n.m "#{pro}: defense of #{k.name} <- #{a.name} succeeds with #{d.name}"
22: throw :next_attacker
23: end
24: }
25:
26: a.attackers(pro, n) do |d|
27:
28: n.m "#{pro}: trying defense #{k.name} <- #{a.name} <- #{d.name}"
29: if l.any? { |x| x.attacks?(d) } then
30: n.m "#{pro}: conflicting #{d.name}"
31: next
32: end
33: if result = adm( l+[d], m+[a], n+1 ) then
34: n.m "#{pro}: defense #{k.name} <- #{a.name} <- #{d.name} succeeds"
35: l = result
36: throw :next_attacker
37: else
38: n.m "#{pro}: defense #{k.name} <- #{a.name} <- #{d.name} fails"
39: n.m "#{pro}: trying next defender #{k.name} <- #{a.name}"
40: end
41: end
42: n.m "#{pro}: defense #{k.name} <- #{a.name} fails, returning nil"
43: return nil
44:
45: end
46: n.m "#{con}: trying next attacker of #{k.name}"
47: end
48: if nr_attacks.zero? then
49: n.m "#{con}: no attackers, hence attack on #{k.name} fails"
50: else
51: n.m "#{con}: no more attackers, hence attack on #{k.name} fails"
52: end
53: n.m "STS: #{k.name} is a member of the admissible set #{l.name}";
54: n.m "STS: #{k.name}'s conclusion, viz. #{k.conclusion.html}, is admissible";
55: l
56: end