Created
November 9, 2025 20:51
-
-
Save mickelsonm/4fe71af72c00c8cfaecf524d903d8101 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Evaluate a single atomic condition | |
| int evaluate_condition(mapping cond, mapping target) { | |
| string name, op; | |
| mixed val, target_val; | |
| name = cond["name"]; | |
| val = cond["value"]; | |
| op = cond["operation"] || "="; | |
| target_val = target[name]; | |
| switch(op) { | |
| case "=": | |
| case "equals": return target_val == val; | |
| case "!=": | |
| case "not equals": return target_val != val; | |
| case ">=": return target_val >= val; | |
| case "<=": return target_val <= val; | |
| case ">": return target_val > val; | |
| case "<": return target_val < val; | |
| default: return 0; | |
| } | |
| } | |
| int evaluate(mapping eval, mapping target) { | |
| string logic; | |
| mixed *conds; | |
| int i, result; | |
| logic = eval["logic"] || eval["operation"] || "AND"; | |
| conds = eval["conditions"]; | |
| if (!conds || sizeof(conds) == 0) return 0; | |
| switch(logic) { | |
| case "AND": | |
| result = 1; | |
| for (i = 0; i < sizeof(conds); i++) { | |
| if (pointerp(conds[i])) { | |
| // Nested AND block | |
| if (!evaluate((["logic":"AND","conditions":conds[i]]), target)) { | |
| result = 0; | |
| break; | |
| } | |
| } else if (mappingp(conds[i])) { | |
| if (member(conds[i], "conditions")) { | |
| // Nested group | |
| if (!evaluate(conds[i], target)) { | |
| result = 0; | |
| break; | |
| } | |
| } else if (!evaluate_condition(conds[i], target)) { | |
| // Atomic condition | |
| result = 0; | |
| break; | |
| } | |
| } | |
| } | |
| break; | |
| case "OR": | |
| result = 0; | |
| for (i = 0; i < sizeof(conds); i++) { | |
| if (pointerp(conds[i])) { | |
| if (evaluate((["logic":"AND","conditions":conds[i]]), target)) { | |
| result = 1; | |
| break; | |
| } | |
| } else if (mappingp(conds[i])) { | |
| if (member(conds[i], "conditions")) { | |
| if (evaluate(conds[i], target)) { | |
| result = 1; | |
| break; | |
| } | |
| } else if (evaluate_condition(conds[i], target)) { | |
| result = 1; | |
| break; | |
| } | |
| } | |
| } | |
| break; | |
| default: | |
| result = 0; | |
| break; | |
| } | |
| return result; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment