1 | svoid nlLogic_battleItOut(L<RuleWithParams> battleSpace, LS facts) {
|
2 | new Matches mm; |
3 | new MultiMap<S> trumps; |
4 | |
5 | // get conflict clusters |
6 | new Clusters<S> conflictClusters; |
7 | new Set<S> _ruleIDs; |
8 | for (RuleWithParams r : battleSpace) {
|
9 | addIfNotNull(_ruleIDs, r.rule.globalID); |
10 | for (S option : unnull(r.rule.options)) |
11 | if (match_vbar("conflicts with *|trumps *", option, mm)) {
|
12 | S r1 = r.rule.globalID, r2 = mm.unq(0); |
13 | treeSetClusters_add(conflictClusters, r1, r2); |
14 | if (match("trumps *", option))
|
15 | trumps.put(r1, r2); |
16 | } |
17 | } |
18 | |
19 | for (S s : facts) {
|
20 | bool trump = match("rule * trumps rule *", s, mm);
|
21 | if (trump || match("rule * conflicts with rule *", s, mm)) {
|
22 | S r1 = mm.unq(0), r2 = mm.unq(1); |
23 | if (_ruleIDs.contains(r1) && _ruleIDs.contains(r2)) {
|
24 | treeSetClusters_add(conflictClusters, r1, r2); |
25 | if (trump) |
26 | trumps.put(r1, r2); |
27 | } |
28 | } |
29 | } |
30 | |
31 | if (nempty(conflictClusters)) |
32 | print("Have conflict clusters: " + sfu(conflictClusters));
|
33 | |
34 | // Detect winners |
35 | final new HashSet<S> toRemove; |
36 | for (Collection<S> ruleIDs : uniquifyList_identity(values(conflictClusters))) {
|
37 | ruleIDs = new LinkedHashSet(ruleIDs); |
38 | for (S id : cloneList(ruleIDs)) {
|
39 | LS losers = trumps.get(id); |
40 | removeAll(ruleIDs, losers); |
41 | toRemove.addAll(losers); |
42 | } |
43 | S winner = random(ruleIDs); |
44 | L<S> removing = listWithout(ruleIDs, winner); |
45 | print("Winner: " + winner + ", removing: " + removing);
|
46 | toRemove.addAll(removing); |
47 | } |
48 | |
49 | // Remove losers |
50 | if (nempty(toRemove)) {
|
51 | for (ListIterator<RuleWithParams> i = listIterator(battleSpace); i.hasNext(); ) |
52 | if (toRemove.contains(i.next().rule.globalID)) |
53 | i.remove(); |
54 | print("Rules narrowed down to: " + collect(collect(battleSpace, 'rule), 'globalID));
|
55 | } |
56 | } |
download show line numbers debug dex old transpilations
Travelled to 13 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1017835 |
| Snippet name: | nlLogic_battleItOut |
| Eternal ID of this version: | #1017835/4 |
| Text MD5: | d6bcaaeb44d85361f4842139a18701e2 |
| Author: | stefan |
| Category: | javax / a.i. |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2018-08-21 13:55:59 |
| Source code size: | 1908 bytes / 56 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 640 / 654 |
| Version history: | 3 change(s) |
| Referenced in: | [show references] |