svoid nlLogic_battleItOut(L<RuleWithParams> battleSpace, LS facts) { new Matches mm; new MultiMap<S> trumps; // get conflict clusters new Clusters<S> conflictClusters; new Set<S> _ruleIDs; for (RuleWithParams r : battleSpace) { addIfNotNull(_ruleIDs, r.rule.globalID); for (S option : unnull(r.rule.options)) if (match_vbar("conflicts with *|trumps *", option, mm)) { S r1 = r.rule.globalID, r2 = mm.unq(0); treeSetClusters_add(conflictClusters, r1, r2); if (match("trumps *", option)) trumps.put(r1, r2); } } for (S s : facts) { bool trump = match("rule * trumps rule *", s, mm); if (trump || match("rule * conflicts with rule *", s, mm)) { S r1 = mm.unq(0), r2 = mm.unq(1); if (_ruleIDs.contains(r1) && _ruleIDs.contains(r2)) { treeSetClusters_add(conflictClusters, r1, r2); if (trump) trumps.put(r1, r2); } } } if (nempty(conflictClusters)) print("Have conflict clusters: " + sfu(conflictClusters)); // Detect winners final new HashSet<S> toRemove; for (Collection<S> ruleIDs : uniquifyList_identity(values(conflictClusters))) { ruleIDs = new LinkedHashSet(ruleIDs); for (S id : cloneList(ruleIDs)) { LS losers = trumps.get(id); removeAll(ruleIDs, losers); toRemove.addAll(losers); } S winner = random(ruleIDs); L<S> removing = listWithout(ruleIDs, winner); print("Winner: " + winner + ", removing: " + removing); toRemove.addAll(removing); } // Remove losers if (nempty(toRemove)) { for (ListIterator<RuleWithParams> i = listIterator(battleSpace); i.hasNext(); ) if (toRemove.contains(i.next().rule.globalID)) i.remove(); print("Rules narrowed down to: " + collect(collect(battleSpace, 'rule), 'globalID)); } }
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: | 389 / 413 |
Version history: | 3 change(s) |
Referenced in: | #1006654 - Standard functions list 2 (LIVE, continuation of #761) |