Skip to content

Instantly share code, notes, and snippets.

@pomarec
Created August 10, 2012 09:15
Show Gist options
  • Save pomarec/3312808 to your computer and use it in GitHub Desktop.
Save pomarec/3312808 to your computer and use it in GitHub Desktop.
Elements
{
"Air": {
"strongerThan": [
"Plants",
"Ice",
"Radioactive"
],
"weakerThan": [
"Diamond",
"Metal",
"Wood"
]
},
"Diamond": {
"strongerThan": [
"Space",
"Air",
"Water"
],
"weakerThan": [
"Gas",
"Rock",
"Lightning"
]
},
"Earth": {
"strongerThan": [
"Fire",
"Ice",
"Plants"
],
"weakerThan": [
"Radioactive",
"Space",
"Shadow"
]
},
"Fire": {
"strongerThan": [
"Sand",
"Spirit",
"Wood"
],
"weakerThan": [
"Ice",
"Earth",
"Lightning"
]
},
"Gas": {
"strongerThan": [
"Wood",
"Space",
"Diamond"
],
"weakerThan": [
"Plants",
"Metal",
"Shadow"
]
},
"Ice": {
"strongerThan": [
"Radioactive",
"Fire",
"Shadow"
],
"weakerThan": [
"Poison",
"Air",
"Earth"
]
},
"Lightning": {
"strongerThan": [
"Shadow",
"Diamond",
"Fire"
],
"weakerThan": [
"Space",
"Rock",
"Spirit"
]
},
"Magnetic": {
"strongerThan": [
"Poison",
"Sand",
"Plants"
],
"weakerThan": [
"Radioactive",
"Rock",
"Spirit"
]
},
"Metal": {
"strongerThan": [
"Air",
"Gas",
"Poison"
],
"weakerThan": [
"Space",
"Water",
"Shadow"
]
},
"Plants": {
"strongerThan": [
"Spirit",
"Gas",
"Space"
],
"weakerThan": [
"Magnetic",
"Air",
"Earth"
]
},
"Poison": {
"strongerThan": [
"Rock",
"Wood",
"Ice"
],
"weakerThan": [
"Metal",
"Magnetic",
"Spirit"
]
},
"Radioactive": {
"strongerThan": [
"Water",
"Magnetic",
"Earth"
],
"weakerThan": [
"Air",
"Sand",
"Ice"
]
},
"Rock": {
"strongerThan": [
"Diamond",
"Magnetic",
"Lightning"
],
"weakerThan": [
"Poison",
"Water",
"Sand"
]
},
"Sand": {
"strongerThan": [
"Rock",
"Radioactive",
"Spirit"
],
"weakerThan": [
"Fire",
"Magnetic",
"Water"
]
},
"Shadow": {
"strongerThan": [
"Gas",
"Metal",
"Earth"
],
"weakerThan": [
"Wood",
"Ice",
"Lightning"
]
},
"Space": {
"strongerThan": [
"Metal",
"Earth",
"Lightning"
],
"weakerThan": [
"Plants",
"Diamond",
"Gas"
]
},
"Spirit": {
"strongerThan": [
"Magnetic",
"Poison",
"Lightning"
],
"weakerThan": [
"Plants",
"Fire",
"Sand"
]
},
"Water": {
"strongerThan": [
"Sand",
"Metal",
"Rock"
],
"weakerThan": [
"Diamond",
"Radioactive",
"Wood"
]
},
"Wood": {
"strongerThan": [
"Air",
"Water",
"Shadow"
],
"weakerThan": [
"Fire",
"Gas",
"Poison"
]
}
}
import random, yaml, json
print "WARNING : you may need to run it multiple times to have a result"
elems = ["Water", "Fire", "Air", "Earth", "Poison", "Plants", "Sand", "Rock", "Spirit", "Ice", "Lightning", "Space", "Radioactive", "Magnetic", "Gas", "Shadow", "Metal", "Wood", "Diamond"]
available = list(elems)
relations = dict((e, { "strongerThan" : [], "weakerThan" : []}) for e in elems)
counts = dict((e, 0) for e in elems)
# Generate
for e in elems:
el = list(available)
el = filter(lambda ee: ee != e and e not in relations[ee]["strongerThan"], el)
random.shuffle(el)
for i in range(3):
a = el.pop()
relations[e]["strongerThan"].append(a)
counts[a] += 1
if counts[a] >= 3:
available.remove(a)
# Compute weaker
for e, l in relations.iteritems():
for i in l["strongerThan"]:
relations[i]["weakerThan"].append(e)
# Print result
res = ""
res += "| Element | Fort contre | Faible contre |\n"
res += "|:-----------|------------|------------|\n"
for k,v in relations.iteritems():
res += "| %s |" % k
res += ", ".join(v["strongerThan"])
res += " | "
res += ", ".join(v["weakerThan"])
res += " |\n"
print res
#print yaml.dump(relations)
print yaml.dump(counts)
json.dump(relations, open("elems.json", "a"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment