In the past, we've picked names out of a hat, but someone would often pick their own spouse and it was just an imperfect system. This year, I thought, huh, why don't I write some Hugo code to fix this?
(There is also a "KidsMas," where my nephews and nieces get one cousin to get a gift for- but their own siblings should be disallowed.)
I wrote a program to handle both cases. It uses Roodylib's object sorting code.
This file contains 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
property disallow | |
object available_jar | |
{} | |
object used_jar | |
{} | |
object unavailable_jar | |
{} | |
object jimmy "Jimmy" | |
{ | |
in available_jar | |
misc 0 | |
disallow mikey | |
} | |
object mikey "Mikey" | |
{ | |
nearby | |
misc 0 | |
disallow jimmy | |
} | |
object dan "Dan" | |
{ | |
nearby | |
misc 0 | |
disallow meaghan | |
} | |
object meaghan "Meaghan" | |
{ | |
nearby | |
misc 0 | |
disallow dan | |
} | |
object laura "Laura" | |
{ | |
nearby | |
misc 0 | |
disallow bob | |
} | |
object bob "Bob" | |
{ | |
nearby | |
misc 0 | |
disallow laura | |
} | |
object jon "Jon" | |
{ | |
nearby | |
misc 0 | |
} | |
object dave "Dave" | |
{ | |
nearby | |
misc 0 | |
disallow bridget | |
} | |
object bridget "Bridget" | |
{ | |
nearby | |
misc 0 | |
disallow dave | |
} | |
object anne "Anne" | |
{ | |
nearby | |
misc 0 | |
} | |
routine SiblingMas | |
{ | |
local x,i, done | |
while not done | |
{ | |
while child(used_jar) | |
move child(used_jar) to available_jar | |
done = OrderJars(jimmy,anne) | |
} | |
i = scripton | |
print "SiblingMas List!\n" | |
for (x = jimmy;x <= anne ;x++ ) | |
{ | |
print x.name; " has: "; x.misc | |
} | |
"" | |
"KidsMas List!\n" | |
while child(kids_jar) | |
{ | |
move child(kids_jar) to available_jar | |
} | |
for (i=jimmy;i<=anne;i++) | |
{ | |
remove i | |
} | |
done = false | |
while not done | |
{ | |
while child(used_jar) | |
move child(used_jar) to available_jar | |
done = OrderJars(declan,piet) | |
} | |
for (x = declan;x <= piet ;x++ ) | |
{ | |
print x.name; " has: "; x.misc | |
} | |
i = scriptoff | |
"\nPress a key to exit the program." | |
HiddenPause | |
quit | |
} | |
object kids_jar | |
{} | |
object declan "Declan" | |
{ | |
in kids_jar | |
disallow Braden Annelise | |
misc 0 | |
} | |
object braden "Braden" | |
{ | |
nearby | |
disallow Declan Annelise | |
misc 0 | |
} | |
object annelise "Annelise" | |
{ | |
nearby | |
disallow Declan braden | |
misc 0 | |
} | |
object william "William" | |
{ | |
nearby | |
disallow sam | |
misc 0 | |
} | |
object sam "Sam" | |
{ | |
nearby | |
disallow william | |
misc 0 | |
} | |
object elaina "Elaina" | |
{ | |
nearby | |
disallow Gillian | |
misc 0 | |
} | |
object gillian "Gillian" | |
{ | |
nearby | |
disallow elaina | |
misc 0 | |
} | |
object wash "Washington" | |
{ | |
nearby | |
disallow Dinah Piet | |
misc 0 | |
} | |
object dinah "Dinah" | |
{ | |
nearby | |
disallow wash piet | |
misc 0 | |
} | |
object piet "Piet" | |
{ | |
nearby | |
disallow wash dinah | |
misc 0 | |
} | |
routine OrderJars(start,end) | |
{ | |
local x, i, pick | |
for (x = start;x <= end ;x++ ) | |
{ | |
while child(unavailable_jar) | |
move child(unavailable_jar) to available_jar | |
if parent(x) ~= used_jar | |
move x to unavailable_jar | |
if x.disallow | |
{ | |
for (i =1;i<=x.#disallow ;i++ ) | |
{ | |
if parent(x.disallow #i) ~= used_jar | |
move x.disallow #i to unavailable_jar | |
} | |
} | |
if not child(available_jar) | |
return | |
pick = TakeRandom(available_jar) | |
x.misc = pick.name | |
move pick to used_jar | |
} | |
return true | |
} |
No comments:
Post a Comment