Last active
March 1, 2026 19:26
-
-
Save DamianDominoDavis/8bc988d5d418ace4b5bb8fc90de10d3b 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
| // configuration | |
| boolean[location,monster] chase_after = { | |
| $location[dreadsylvanian woods]: $monsters[cold bugbear, hot bugbear, sleaze bugbear, spooky bugbear, stench bugbear], | |
| $location[dreadsylvanian village]: $monsters[cold ghost, hot ghost, sleaze ghost, spooky ghost, stench ghost], | |
| $location[dreadsylvanian castle]: $monsters[cold skeleton, hot skeleton, sleaze skeleton, spooky skeleton, stench skeleton] | |
| }; | |
| boolean[location,monster] flee_from = { | |
| $location[dreadsylvanian woods]: $monsters[cold werewolf, hot werewolf, sleaze werewolf, spooky werewolf, stench werewolf], | |
| $location[dreadsylvanian village]: $monsters[cold zombie, hot zombie, sleaze zombie, spooky zombie, stench zombie], | |
| $location[dreadsylvanian castle]: $monsters[cold vampire, hot vampire, sleaze vampire, spooky vampire, stench vampire] | |
| }; | |
| location focus = $location[dreadsylvanian village]; // must be in chase_after, or none | |
| // do not edit below this line | |
| if (focus != $location[none] && !(chase_after contains focus)) | |
| abort("Please select a valid location for focus. `none` is fine too."); | |
| record prediction { | |
| int time; | |
| location scene; | |
| monster victim; | |
| }; | |
| prediction[int] parse_predictions() { | |
| prediction[int] predictions; | |
| foreach _,str in get_property("crystalBallPredictions").split_string("\\|") { | |
| int time = str.group_string("(.*):.*:.*")[0,1].to_int(); | |
| location scene = str.group_string(".*:(.*):.*")[0,1].to_location(); | |
| monster victim = str.group_string(".*:.*:(.*)")[0,1].to_monster(); | |
| predictions[count(predictions)] = new prediction(time, scene, victim); | |
| } | |
| return predictions; | |
| } | |
| location select(boolean[location] locs) { | |
| switch (count(locs)) { | |
| case 0: return $location[none]; | |
| case 1: foreach loc in locs return loc; | |
| default: | |
| int r = random(count(locs)); | |
| foreach loc in locs | |
| if (r-- == 0) | |
| return loc; | |
| } | |
| return $location[none]; | |
| } | |
| location choose_prediction_location() { | |
| prediction[int] predictions = parse_predictions(); | |
| boolean[location] locs; | |
| location decision; | |
| foreach _,p in predictions | |
| if (chase_after contains p.scene && chase_after[p.scene] contains p.victim) { | |
| if (p.scene == focus) | |
| return focus; | |
| locs[p.scene] = true; | |
| } | |
| decision = select(locs); | |
| if (decision != $location[none]) | |
| return decision; | |
| locs = {}; | |
| foreach loc in chase_after | |
| locs[loc] = true; | |
| foreach _,p in predictions | |
| if (locs contains p.scene && flee_from contains p.scene && flee_from[p.scene] contains p.victim) | |
| remove locs[p.scene]; | |
| if (locs contains focus) | |
| return focus; | |
| return select(locs); | |
| } | |
| void main() { | |
| print("Crystal Ball says: go to " + choose_prediction_location()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment