Warning: session_start(): open(/var/lib/php/sessions/sess_bm95gtnv59v5kpanif73sp1hv8, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
svoid nlLogic_battleItOut(L battleSpace) {
new Matches mm;
new Clusters conflictClusters;
new MultiMap trumps;
for (RuleWithParams r : battleSpace)
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);
}
if (nempty(conflictClusters))
print("Have conflict clusters: " + sfu(conflictClusters));
// Detect winners
final new HashSet toRemove;
for (Collection 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 removing = listWithout(ruleIDs, winner);
print("Winner: " + winner + ", removing: " + removing);
toRemove.addAll(removing);
}
// Remove losers
if (nempty(toRemove)) {
for (ListIterator i = listIterator(battleSpace); i.hasNext(); )
if (toRemove.contains(i.next().rule.globalID))
i.remove();
print("Rules narrowed down to: " + collect(collect(battleSpace, 'rule), 'globalID));
}
}