Skip to content

Instantly share code, notes, and snippets.

@badp
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badp/11375630 to your computer and use it in GitHub Desktop.
Save badp/11375630 to your computer and use it in GitHub Desktop.
Calculate partial product ordering over dictionaries of tuples assuming bigger numbers are better than smaller numbers, and strings are better than others if they have more of each character ("FFF" > "FF" but "FFF" ≯ "FA")
# Name (Def Def% MDef Mdef% Slots Links, Rate, Flags)
ff7_armor = {
"Bronze Bangle": (8, 0, 0, 0, 0, 0, 0, ""),
"Iron Bangle": (10, 0, 2, 0, 1, 0, 1, ""),
"Titan Bangle": (14, 2, 4, 0, 2, 0, 1, ""),
"Mythril Armlet": (18, 3, 8, 0, 2, 1, 1, ""),
"Carbon Bangle": (27, 3, 14, 0, 3, 1, 1, ""),
"Silver Armlet": (34, 4, 22, 0, 3, 1, 1, ""),
"Gold Armlet": (46, 4, 28, 0, 4, 2, 1, ""),
"Diamond Bangle": (57, 6, 37, 0, 5, 2, 1, ""),
"Crystal Bangle": (70, 8, 45, 1, 6, 3, 1, ""),
"Platinum Bangle": (20, 0, 12, 0, 2, 0, 2, ""),
"Rune Armlet": (43, 5, 24, 0, 4, 0, 2, ""),
"Edincoat": (50, 0, 33, 0, 7, 0, 1, "M"),
"Wizard Bracelet": (6, 3, 85, 3, 8, 4, 1, "MM"),
"Adaman Bangle": (93, 0, 23, 0, 2, 1, 1, ""),
"Gigas Armlet": (59, 0, 0, 0, 5, 2, 0, "SSS"),
"Imperial Guard": (82, 0, 74, 0, 6, 3, 1, ""),
"Aegis Armlet": (55, 15, 86, 50, 4, 2, 1, ""),
"Fourth Bracelet": (74, 3, 100, 3, 5, 2, 1, "MM"),
"Warrior Bangle": (96, 0, 21, 0, 4, 2, 0, "SS"),
"Shinra Beta": (30, 0, 0, 0, 4, 2, 1, ""),
"Shinra Alpha": (77, 0, 34, 0, 6, 3, 1, ""),
"Four Slots": (12, 0, 10, 0, 4, 0, 1, ""),
"Fire Armlet": (72, 8, 52, 3, 4, 2, 1, "FFF"),
"Aurora Armlet": (76, 8, 54, 3, 4, 2, 1, "III"),
"Bolt Armlet": (74, 8, 55, 3, 4, 2, 1, "LLL"),
"Dragon Armlet": (58, 3, 47, 2, 6, 3, 1, "FIL"),
"Minerva Band (1)": (60, 8, 57, 0, 6, 3, 1, "FFIILL"),
"Escort Guard (2)": (62, 5, 55, 0, 6, 3, 1, "LLWWPPEE"),
"Mystile": (65, 50, 72, 60, 6, 3, 1, ""),
"Ziedrich": (100, 15, 98, 18, 0, 0, 0, "SSMMFILEPWH"),
"Precious Watch": (0, 0, 0, 0, 8, 0, 1, ""),
"Chocobracelet": (35, 10, 38, 10, 4, 0, 1, "D"),
}
# Flags: M'agic Not pictured: Gravity (Ziedrich only)
# S'trength Wind (Ziedrich only)
# F'ire Damage (Ziedrich only)
# I'ce Luck (chocobracelet only)
# L'ightning
# W'ater
# P'oison
# H'oly
# D'exterity
# In all versions of FF7 but the latest PC port,
# the Magic Defense stat on armor is purely cosmetic.
# Leave that stat behind.
ff7_armor_pre_2012 = { item: ff7_armor[item][0:2] + ff7_armor[item][3:] for item in ff7_armor}
ff7_weapons = {
# Name (Atk Atk% Magic Sockets Links Rate Flags)
"Buster Sword": (18, 96, 2, 2, 1, 1, "1"),
"Mythril Saber": (23, 98, 4, 3, 1, 1, "1"),
"Hardedge": (32, 98, 6, 4, 1, 1, "1"),
"Butterfly Edge": (39, 100, 8, 4, 2, 1, "1"),
"Enhance Sword": (43, 107, 16, 8, 4, 1, "1"),
"Organics": (62, 103, 15, 6, 2, 1, "1"),
"Crystal Sword": (76, 105, 19, 6, 3, 1, "1"),
"Force Stealer": (36, 100, 7, 3, 0, 2, "1"),
"Rune Blade": (40, 108, 9, 4, 0, 2, "1"),
"Murasame": (51, 100, 12, 5, 2, 1, "1"),
"Nail Bat": (70, 100, 0, 0, 0, 0, "1!"),
"Yoshiyuki": (56, 100, 9, 2, 0, 1, "1£"),
"Apocalypse": (88, 110, 43, 3, 0, 3, "1S"),
"Heaven's Cloud": (93, 100, 31, 6, 0, 1, "1"),
"Ragnarok": (97, 105, 43, 6, 3, 1, "1SSS"),
"Ultima Weapon": (100, 110, 51, 8, 4, 0, "1SS$"),
"Gatling Gun": (14, 97, 0, 1, 0, 1, "2Rs"),
"Assault Gun": (17, 98, 1, 2, 1, 1, "2RS"),
"Cannon Ball": (23, 98, 2, 3, 1, 1, "2H"),
"Atomic Scissors": (32, 99, 4, 4, 1, 1, "2p"),
"Heavy Vulcan": (39, 100, 8, 4, 2, 1, "2Rs"),
"Chainsaw": (52, 100, 10, 4, 1, 1, "2c"),
"Microlaser": (63, 101, 13, 5, 2, 1, "2Rs"),
"A-M Cannon": (77, 103, 16, 6, 3, 1, "2Rs"),
"W Machine Gun": (30, 100, 3, 3, 0, 2, "2Rs"),
"Drill Arm": (37, 97, 0, 4, 0, 2, "2p!"),
"Solid Bazooka": (61, 100, 15, 8, 4, 1, "2Rs"),
"Rocket Punch": (62, 110, 0, 0, 0, 0, "2h!!"),
"Enemy Launcher": (35, 100, 7, 5, 1, 1, "2Rs"),
"Pile Banger": (90, 80, 0, 6, 3, 0, "2p!"),
"Max Ray": (97, 98, 30, 6, 3, 1, "2Rs"),
"Missing Score": (98, 108, 49, 8, 4, 0, "2Rs%"),
"Leather Glove": (13, 99, 0, 1, 0, 1, "3!!h"),
"Metal Knuckle": (18, 102, 1, 2, 1, 1, "3!!h"),
"Mythril Claw": (24, 106, 3, 3, 1, 1, "3!!p"),
"Grand Glove": (31, 110, 6, 4, 1, 1, "3!!h"),
"Tiger Fang": (38, 110, 8, 4, 2, 1, "3!!p"),
"Diamond Knuckle": (51, 112, 10, 5, 2, 1, "3!!h"),
"Dragon Claw": (62, 114, 13, 6, 2, 1, "3!!p"),
"Crystal Glove": (75, 115, 16, 6, 3, 1, "3!!h"),
"Motor Drive": (27, 106, 6, 3, 0, 2, "3h"),
"Platinum Fist": (30, 108, 7, 4, 0, 2, "3h"),
"Kaiser Knucle": (44, 110, 13, 8, 1, 1, "3!h"),
"Work Glove": (68, 114, 0, 0, 0, 0, "3!!!!h"),
"Powersoul": (28, 106, 7, 4, 0, 2, "3&h"),
"Master Fist": (38, 108, 0, 6, 0, 1, "3&&h"),
"God's Hand": (86, 255, 34, 4, 2, 1, "3!!h"),
"Premium Heart": (99, 112, 32, 4, 0, 0, "3/h"),
"Guard Stick": (12, 99, 2, 2, 0, 0, "4VS"),
"Mythril Rod": (16, 100, 3, 2, 1, 1, "4"),
"Full Metal Staff": (22, 100, 4, 3, 1, 1, "4"),
"Striking Staff": (32, 100, 7, 4, 1, 1, "4!"),
"Prism Staff": (40, 105, 10, 4, 2, 1, "4"),
"Aurora Rod": (51, 110, 14, 5, 2, 1, "4"),
"Wizard Staff": (28, 100, 6, 3, 0, 2, "4"),
"Wizer Staff": (33, 100, 7, 4, 0, 2, "4"),
"Fairy tale": (37, 103, 8, 7, 0, 1, "4"),
"Umbrella": (58, 118, 10, 0, 0, 0, "4VVV!"),
"Princess Guard": (52, 111, 22, 7, 3, 1, "4VVSS£"),
"Mythril Clip": (24, 100, 6, 3, 1, 1, "5h"),
"Diamond Pin": (33, 102, 8, 4, 1, 1, "5h"),
"Silver Barrette": (40, 110, 10, 4, 2, 1, "5h"),
"Gold Barrette": (50, 104, 13, 5, 2, 1, "5h"),
"Adaman Clip": (60, 106, 15, 6, 2, 1, "5h"),
"Crystal Comb": (76, 108, 20, 6, 3, 1, "5h"),
"Magic Comb": (37, 100, 4, 3, 0, 2, "5h"),
"Plus Barrette": (39, 104, 12, 4, 0, 2, "5h"),
"Centclip": (58, 108, 22, 8, 0, 1, "5h"),
"Hairpin": (57, 120, 15, 0, 0, 0, "5Rs"),
"Seraph Comb": (68, 110, 14, 4, 0, 1, "5h"),
"Behemoth Horn": (91, 75, 26, 6, 0, 1, "5hVS"),
"Spring Gun Clip": (87, 100, 55, 6, 3, 1, "5h"),
"Limited Moon": (93, 114, 31, 8, 4, 0, "5h$"),
"4-point Shuriken": (23, 100, 6, 3, 1, 1, "6"),
"Boomerang": (30, 101, 7, 4, 1, 1, "6"),
"Pinwheel": (37, 104, 9, 4, 2, 1, "6"),
"Razor Ring": (49, 105, 12, 5, 2, 1, "6"),
"Hawkeye": (61, 107, 14, 5, 2, 1, "6"),
"Crystal Cross": (74, 110, 18, 6, 3, 1, "6"),
"Wind Slash": (30, 103, 7, 3, 0, 2, "6"),
"Twin Viper": (36, 108, 8, 4, 1, 2, "6"),
"Spiral Shuriken": (68, 110, 18, 8, 1, 1, "6!"),
"Superball": (68, 120, 10, 0, 0, 0, "6!!"),
"Magic Shuriken": (64, 113, 0, 3, 0, 1, "6!D"),
"Rising Sun": (68, 108, 16, 4, 2, 2, "6"),
"Oritsuru": (90, 116, 38, 8, 2, 1, "6"),
"Conformer": (96, 112, 42, 8, 4, 0, "6("),
"Yellow M-phone": (36, 100, 8, 4, 1, 0, "7"),
"Green M-phone": (41, 100, 9, 4, 2, 1, "7"),
"Blue M-phone": (48, 100, 10, 5, 1, 1, "7"),
"Red M-phone": (60, 100, 15, 5, 2, 1, "7"),
"Crystal M-phone": (74, 100, 20, 6, 3, 1, "7"),
"White M-phone": (35, 102, 8, 3, 0, 2, "7"),
"Black M-phone": (31, 104, 10, 4, 0, 2, "7"),
"Silver M-phone": (28, 106, 14, 8, 1, 1, "7"),
"Trumpet Shell": (68, 118, 2, 0, 0, 0, "7!!"),
"Gold M-phone": (58, 103, 28, 8, 4, 1, "7"),
"Battle Trumpet": (95, 95, 0, 6, 3, 1, "7!"),
"Starlight Phone": (88, 102, 31, 8, 4, 1, "7V"),
"HP Shout": (95, 110, 44, 8, 4, 0, "7$"),
"Quicksilver": (36, 110, 10, 4, 1, 1, "8"),
"Shotgun": (48, 112, 12, 4, 2, 1, "8"),
"Shortbarrel": (51, 118, 14, 4, 1, 1, "8"),
"Lariat": (64, 120, 16, 4, 1, 1, "8"),
"Winchester": (73, 120, 18, 6, 3, 1, "8"),
"Peacemaker": (38, 118, 8, 3, 1, 2, "8"),
"Buntline": (48, 124, 18, 4, 2, 2, "8"),
"Long Barrel R": (66, 255, 14, 8, 4, 1, "8"),
"Silver Rifle": (62, 120, 0, 0, 0, 0, "8"),
"Sniper CR": (42, 255, 7, 4, 2, 1, "8"),
"Supershot ST": (97, 120, 52, 6, 3, 0, "8"),
"Outsider": (80, 120, 48, 8, 2, 1, "8"),
"Death Penalty": (99, 115, 34, 8, 4, 0, "8"),
"Spear": (44, 97, 8, 4, 2, 1, "9p"),
"Slash Lance": (56, 98, 10, 5, 1, 1, "9p"),
"Trident": (60, 105, 12, 6, 0, 1, "9p"),
"Mast Ax": (64, 99, 15, 6, 2, 1, "9p"),
"Partisan": (78, 100, 17, 6, 3, 1, "9p"),
"Viper Halberd": (58, 102, 13, 4, 0, 2, "9p"),
"Javelin": (62, 104, 12, 5, 2, 2, "9p"),
"Grow Lance": (78, 102, 31, 6, 3, 1, "9p"),
"Mop": (68, 118, 3, 0, 0, 0, "9h!"),
"Dragoon Lance": (66, 100, 7, 8, 0, 1, "9p"),
"Scimitar": (86, 102, 20, 2, 1, 3, "9c"),
"Flayer": (100, 100, 20, 6, 0, 1, "9"), #? element?
"Spirit Lance": (92, 112, 43, 4, 2, 1, "9pS"),
"Venus Gospel": (97, 103, 42, 8, 4, 0, "9p)"),
# and the Masamune doesn't really count.
}
# Flags: 1 Cloud ! Critical s Shoot
# 2 Barret S Sprit h Hit
# 3 Tifa R Ranged p Punch
# 4 Aeris V Vitality c Cut
# 5 Red XIII D Dexterity
# 6 Yuffie
# 7 Cait Sith Flags that are not useful for sorting
# 8 Vincent are omitted (e.g. all of Yuffie's are Rs.)
# 9 Cid
#
# Special buffs: £ Damage multiplied by 1 + number of allies KO'd
# $ Damage increases with health
# % Damage increases with AP
# & Damage 2x if critical + 4x if Death'd
# && More damage boosts like &
# / Damage increases with limit
# ( Damage increases with enemy level
# ) Damage increases with mana
ff6_all = "1234567890ABC"
ff6_fem = "179"
# Given how we do string comparison, we must define weaknesses
# as set of lack of weaknesses
ff6_none = "WwC1Iss"
ff6_sap = ff6_none.replace("1", "")
ff6_water = ff6_none.replace("W", "")
ff6_wind = ff6_none.replace("W", "")
ff6_imp = ff6_none.replace("I", "")
ff6_slow = ff6_none.replace("s", "", 1) # keep the second 's' for the Cursed shield
# -7 Magic, Speed, Stamina, Strength.
# Weak to Fire, Ice, Lightning, Poison, Earth, Water.
# Inflicts Confuse, Berserk, Silence, Seizure, Doom upon user.
ff6_cursed = ff6_water.replace("C", "").replace("s", "")
# This is kinda overkill since it's Gau-only but oh well
ff6_dueling_mask = ("S" * 6) + ("s" * 6) + ("§" * 6) + ("M" * 6) + \
("H" * 2) + "FILWwEHP"
# ...and there's only ever one of this
ff6_paladin = ("FILH" * 3) + ("PwEW" * 2)
ff6_bustier = ("H" * 2) + "S§" + ("s" * 2) + ("M" * 4) + ("FILw" * 2) + "EWPH"
ff6_armor = {
# Name (Def MDef Ev MEv Type, Chars Strengths, Weaknesses)
"Cursed Shield": (0, 0, 0, 0, "S", ff6_all, "", ff6_cursed),
"Force Shield": (0, 70, 0, 50, "S", ff6_all, "FILwEW$", ff6_none),
"Buckler": (16, 10, 10, 0, "S", ff6_all, "", ff6_none),
"Mythril Shield": (27, 18, 10, 0, "S", ff6_all, "", ff6_none),
"Flame Shield": (41, 28, 20, 10, "S", ff6_all, "FFFII%", ff6_water),
"Ice Shield": (42, 28, 20, 10, "S", ff6_all, "IIIFF&", ff6_wind),
"Thunder Shield": (43, 28, 20, 10, "S", ff6_all, "LLLWWFI/", ff6_none),
"Aegis Shield": (46, 52, 20, 40, "S", ff6_all, "", ff6_none),
"Genji Shield": (54, 50, 20, 20, "S", ff6_all, "", ff6_none),
"Paladin's Shield": (59, 59, 40, 40, "S", ff6_all, ff6_paladin, ff6_none),
"Tortoise Shield": (66, 66, 30, 30, "S", ff6_all, "WWW)", ff6_imp),
"Heavy Shield": (22, 14, 10, 0, "S", "125370", "", ff6_none),
"Golden Shield": (34, 23, 10, 0, "S", "15370A", "", ff6_none),
"Diamond Shield": (40, 27, 10, 0, "S", "15370", "", ff6_none),
"Crystal Shield": (50, 34, 10, 0, "S", "15370", "", ff6_none),
"Leather Cap": (11, 7, 0, 0, "H", ff6_all, "", ff6_none),
"Plumed Hat": (14, 9, 0, 0, "H", ff6_all, "", ff6_none),
"Magus Hat": (15, 16, 0, 0, "H", "17A89C", "MMMMM", ff6_none),
"Bandana": (16, 10, 0, 0, "H", "126BA", "", ff6_none),
"Twist Headband": (16, 10, 0, 0, "H", "2643BA", "s§§SSS", ff6_none),
"Green Beret": (19, 13, 10, 0, "H", ff6_all, "H", ff6_none),
"Priest's Miter": (19, 21, 0, 10, "H", ff6_all, "m", ff6_none),
"Tiger Mask": (21, 13, 0, 0, "H", "6B", "ss§SSS", ff6_none),
"Beret": (21, 21, 0, 0, "H", "9", "MMM=", ff6_none),
"Hypno Crown": (23, 23, 0, 0, "H", "9", "MMMMSS?", ff6_none),
"Red Cap": (24, 17, 0, 0, "H", ff6_all, "HHsss§§SSSS", ff6_none),
"Circlet": (25, 19, 0, 0, "H", ff6_all, "MMMMs§§§SS", ff6_none),
"Black Cowl": (26, 17, 0, 0, "H", "264BAC", "", ff6_none),
"Royal Crown": (28, 23, 0, 0, "H", "56", "Ms§S", ff6_none),
"Cat-Ear Hood": (33, 33, 10, 10, "H", "9", "MMMMssFILEwH^", ff6_none),
"Thornlet": (38, 0, 0, 0, "H", ff6_all, "", ff6_sap),
"Dueling Mask": (40, 40, 10, 10, "H", "B", ff6_dueling_mask, ff6_none),
"Saucer": (42, 42, 0, 0, "H", ff6_all, "WWW)", ff6_imp),
"Hairband": (12, 8, 0, 0, "H", ff6_fem, "", ff6_none),
"Tiara": (22, 20, 0, 0, "H", ff6_fem, "MM", ff6_none),
"Mystery Veil": (24, 25, 0, 10, "H", ff6_fem, "MMMs", ff6_none),
"Oath Veil": (32, 31, 0, 0, "H", ff6_fem, "", ff6_none),
"Iron Helm": (18, 12, 0, 0, "H", "1253B70", "", ff6_none),
"Mythril Helm": (20, 13, 0, 0, "H", "12543B70C", "", ff6_none),
"Golden Helmet": (22, 15, 0, 0, "H", "15370", "", ff6_none),
"Diamond Helm": (27, 18, 0, 0, "H", "15370A", "", ff6_none),
"Crystal Helm": (29, 19, 0, 0, "H", "1570", "", ff6_none),
"Genji Helmet": (36, 38, 0, 0, "H", ff6_all, "", ff6_none),
"Leather Armor": (28, 19, 0, 0, "A", "123457890ABC", "", ff6_none),
"Kempo Gi": (34, 23, 0, 0, "A", "264B", "", ff6_none),
"Mythril Vest": (45, 30, 0, 0, "A", ff6_all, "", ff6_none),
"Ninja Gear": (47, 32, 0, 0, "A", "264B0C", "ss", ff6_none),
"Mirage Vest": (48, 36, 0, 10, "A", ff6_all, "ssssssB", ff6_none),
"Power Sash": (52, 35, 0, 0, "A", "2643B", "s§§§§§SSSSSS", ff6_none),
"Gaia Gear": (53, 43, 0, 0, "A", "124B70A9C", "EEE", ff6_none),
"Diamond Vest": (65, 44, 0, 0, "A", "12345670ABC", "", ff6_none),
"Black Garb": (68, 46, 0, 0, "A", "264B0C", "", ff6_none),
"Red Jacket": (78, 55, 0, 0, "A", ff6_all, "Mss§§§§SSSSSFFF", ff6_none),
"Reed Cloak": (100, 100, 0, 0, "A", ff6_all, "WWW)", ff6_imp),
"Snow Scarf": (128, 90, 10, 10, "A", "BA", "IIIF", ff6_none),
"Cotton Robe": (32, 21, 0, 0, "A", "189C", "", ff6_none),
"Silk Robe": (39, 29, 0, 0, "A", "17A89C", "M", ff6_none),
"Luminous Robe": (60, 43, 0, 0, "A", "89C", "M", ff6_none),
"Magus Robe": (68, 50, 0, 10, "A", "89C", "MMMMM", ff6_none),
"White Dress": (47, 35, 0, 0, "A", "179", "MMMMM", ff6_none),
"Regal Gown": (70, 64, 0, 0, "A", "9", "MMMss§§S", ff6_none),
"Minerva Bustier": (88, 70, 0, 10, "A", "17", ff6_bustier, ff6_none),
"Tabby Suit": (54, 36, 0, 0, "A", "89", "SSss§§MMPP", ff6_none),
"Chocobo Suit": (56, 38, 0, 0, "A", "89", "SSSssssss§§PP", ff6_none),
"Moogle Suit": (58, 52, 0, 0, "A", "89", "MMMMMPP", ff6_none),
"Nutkin Suit": (86, 57, 0, 0, "A", "89", "sssssssMMM", ff6_none),
"Behemoth Suit": (94, 73, 0, 0, "A", "89", "Ss§M" * 6, ff6_none),
"Iron Armor": (40, 27, 0, 0, "A", "125370", "", ff6_slow),
"Mythril Mail": (51, 34, 0, 0, "A", "125370", "", ff6_none),
"Golden Armor": (55, 37, 0, 0, "A", "12370A", "", ff6_none),
"Force Armor": (69, 68, 0, 30, "A", "125370", "FILwE", ff6_none),
"Diamond Armor": (70, 47, 0, 0, "A", "15370", "", ff6_none),
"Crystal Mail": (72, 49, 0, 0, "A", "125370", "", ff6_none),
"Genji Armor": (90, 80, 0, 0, "A", "1254370", "SSSSSsssMMM§§", ff6_none),
}
# Chars: 1 Terra 5 Edgar 9 Relm C Gogo
# 2 Locke 6 Sabin 0 Setzer
# 3 Cyan 7 Celes A Mog Umaro's equip
# 4 Shadow 8 Strago B Gau is fixed
#
# Type: S Shield H Helmet A Armor
#
# Flags: F Fire I Ice L Lightning W Water
# w Wind E Earth H Holy P Poison
# M +Magic S +Strength s +Speed § +Stamina
# m +Mana H +health B Blink
#
# Weaks: 1 Sap W Water w Wind C Cursed shield extravaganza
# s Speed I Only good on imps
#
# Special: £ Cursed (win 256 battles with it)
# $ Teach Shell at x5
# % Teach Fira at x5
# & Teach Blizzara at x5
# / Teach Thundara at x5
# ( Teach Ultima at x1
# ) Teach Imp at x1
# = Improves success rate of Sketch
# ? Improves success rate of Control
# ^ 2x gil
# In the SNES version of FF6, the Evade stat is useless.
# Copy the dictionary but leave that stat behind.
ff6_armor_snes = { item: ff6_armor[item][0:2] + ff6_armor[item][3:] for item in ff6_armor}
# SANITY: make sure we don't have more links than sockets
for armor in ff7_armor:
if ff7_armor[armor][4] < 2*ff7_armor[armor][5]:
raise Exception(armor)
for weapon in ff7_weapons:
if ff7_weapons[weapon][3] < 2*ff7_weapons[weapon][4]:
raise Exception(weapon)
from collections import Counter
def compare(x, y):
if type(x) != type(y):
raise TypeError()
elif type(x) == int:
if x < y: return -1
if x == y: return 0
if x > y: return 1
elif type(x) == str:
x = Counter(x)
y = Counter(y)
letters = set(x).union(set(y))
outcomes = [compare(x[l],y[l]) for l in letters]
elif type(x) in (tuple, list):
outcomes = [compare(x_, y_) for (x_, y_) in zip(x,y)]
else:
raise TypeError()
if None in outcomes:
return None
if 1 in outcomes and -1 in outcomes:
return None # not comparable
if 1 in outcomes:
return 1
if -1 in outcomes:
return -1
#equal
return 0
def build_graph(data):
keys = list(data)
output = set()
for (number, x) in enumerate(keys):
for y in keys[number + 1:]:
result = compare(data[x], data[y])
if result == None:
continue
if result < 0: # x < y
output.add((y,x))
if result > 0: # x > y
output.add((x,y))
return transitive_closure(output)
def transitive_closure(list_inequalities):
new_list = list_inequalities.copy()
for (x, y) in list_inequalities:
for (y_, z) in list_inequalities:
if y == y_ and (x, z) in new_list:
new_list.remove((x,z))
return new_list
def build_graphviz(list_inequalities):
dot = "digraph x { \n"
for big, small in list_inequalities:
dot += ' "%s" -> "%s"\n' % (big, small)
dot += "}"
return dot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment