|
|
@@ -2,6 +2,7 @@ import random |
|
|
|
|
|
|
|
class MetroidState: |
|
|
|
def __init__(self): |
|
|
|
self.alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?-" |
|
|
|
self.itemsCollected = { |
|
|
|
"Maru Mari": False, |
|
|
|
"Bombs": False, |
|
|
@@ -99,6 +100,9 @@ class MetroidState: |
|
|
|
self.gameAge = 0 |
|
|
|
self.locations = ["Brinstar", "Norfair", "Kraid's Lair", "Ridley's Lair", "Tourian"] |
|
|
|
self.startLocation = 0 |
|
|
|
self.bitfield = [] |
|
|
|
for _ in range(128): |
|
|
|
self.bitfield.append(0) |
|
|
|
|
|
|
|
def toggleItem(self, itm): |
|
|
|
if itm in self.itemsCollected.keys(): |
|
|
@@ -257,6 +261,40 @@ class MetroidState: |
|
|
|
else: |
|
|
|
return "No" |
|
|
|
|
|
|
|
def openedDoors(self): |
|
|
|
d = {"Brinstar": 0, "Norfair": 0, "Kraid": 0, "Ridley": 0, "Tourian": 0} |
|
|
|
o = [] |
|
|
|
for k,v in self.doors["Brinstar"].items(): |
|
|
|
if v == True: |
|
|
|
d["Brinstar"] = d["Brinstar"] + 1 |
|
|
|
for k,v in self.doors["Norfair"].items(): |
|
|
|
if v == True: |
|
|
|
d["Norfair"] = d["Norfair"] + 1 |
|
|
|
for k,v in self.doors["Kraid"].items(): |
|
|
|
if v == True: |
|
|
|
d["Kraid"] = d["Kraid"] + 1 |
|
|
|
for k,v in self.doors["Ridley"].items(): |
|
|
|
if v == True: |
|
|
|
d["Ridley"] = d["Ridley"] + 1 |
|
|
|
for k,v in self.doors["Tourian"].items(): |
|
|
|
if v == True: |
|
|
|
d["Tourian"] = d["Tourian"] + 1 |
|
|
|
for k, v in d.items(): |
|
|
|
o.append("{} {}".format(k, v)) |
|
|
|
return ", ".join(o) |
|
|
|
|
|
|
|
def getBits(self): |
|
|
|
o = [] |
|
|
|
word = [] |
|
|
|
for i in range(128): |
|
|
|
word.append(str(self.bitfield[i])) |
|
|
|
if len(word) == 8: |
|
|
|
o.append("".join(word)) |
|
|
|
word = [] |
|
|
|
o1 = " ".join(o[:8]) |
|
|
|
o2 = " ".join(o[8:]) |
|
|
|
return o1 + "\n" + o2 |
|
|
|
|
|
|
|
def toString(self): |
|
|
|
ic = "Items Collected: {}".format(self.collectedItems()) |
|
|
|
mt = "Missile Tanks Collected: {}".format(self.collectedMissiles()) |
|
|
@@ -266,8 +304,10 @@ class MetroidState: |
|
|
|
rs = "Statues Raised: {}".format(self.raisedStatues()) |
|
|
|
sw = "Swimsuit?: {}".format(self.inBailey()) |
|
|
|
sl = "Start Location: {}".format(self.locations[self.startLocation]) |
|
|
|
dr = "" |
|
|
|
return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr]) |
|
|
|
dr = "Unlocked Doors: {}".format(self.openedDoors()) |
|
|
|
ms = "Missiles: {}".format(self.missileCount) |
|
|
|
bf = "Bitfield:\n{}".format(self.getBits()) |
|
|
|
return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr, ms, bf]) |
|
|
|
|
|
|
|
def randomize(self): |
|
|
|
# Items |
|
|
@@ -312,16 +352,359 @@ class MetroidState: |
|
|
|
self.toggleKraidStatue() |
|
|
|
if not self.ridleyKilled and random.randint(0,1) == 1: |
|
|
|
self.toggleRidleyStatue() |
|
|
|
# Doors |
|
|
|
# Brinstar 5, Norfair 4, Kraid 5, Ridley 2, Tourian 3 |
|
|
|
for i in range(5): |
|
|
|
if random.randint(0,1) == 1: |
|
|
|
self.doors["Brinstar"][i+1] = True |
|
|
|
for i in range(4): |
|
|
|
if random.randint(0,1) == 1: |
|
|
|
self.doors["Norfair"][i+1] = True |
|
|
|
for i in range(5): |
|
|
|
if random.randint(0,1) == 1: |
|
|
|
self.doors["Kraid"][i+1] = True |
|
|
|
for i in range(2): |
|
|
|
if random.randint(0,1) == 1: |
|
|
|
self.doors["Ridley"][i+1] = True |
|
|
|
for i in range(3): |
|
|
|
if random.randint(0,1) == 1: |
|
|
|
self.doors["Tourian"][i+1] = True |
|
|
|
# Swimsuit |
|
|
|
if random.randint(0,2) == 2: |
|
|
|
self.toggleSwimsuit() |
|
|
|
# Start Location |
|
|
|
self.startLocation = random.randint(0,4) |
|
|
|
self.missileCount = random.randint(0,255) |
|
|
|
self.createBitfield() |
|
|
|
|
|
|
|
def createBitfield(self): |
|
|
|
# Doing this in order, which is dumb and tedious but accurate. |
|
|
|
if self.itemsCollected["Maru Mari"]: |
|
|
|
self.bitfield[0] = 1 |
|
|
|
if self.missileTanks[1]: |
|
|
|
self.bitfield[1] = 1 |
|
|
|
if self.doors["Brinstar"][1]: |
|
|
|
self.bitfield[2] = 1 |
|
|
|
if self.doors["Brinstar"][2]: |
|
|
|
self.bitfield[3] = 1 |
|
|
|
if self.energyTanks[1]: |
|
|
|
self.bitfield[4] = 1 |
|
|
|
if self.doors["Brinstar"][3]: |
|
|
|
self.bitfield[5] = 1 |
|
|
|
if self.itemsCollected["Bombs"]: |
|
|
|
self.bitfield[6] = 1 |
|
|
|
if self.doors["Brinstar"][4]: |
|
|
|
self.bitfield[7] = 1 |
|
|
|
if self.missileTanks[2]: |
|
|
|
self.bitfield[8] = 1 |
|
|
|
if self.energyTanks[2]: |
|
|
|
self.bitfield[9] = 1 |
|
|
|
if self.doors["Brinstar"][5]: |
|
|
|
self.bitfield[10] = 1 |
|
|
|
if self.itemsCollected["Varia"]: |
|
|
|
self.bitfield[11] = 1 |
|
|
|
if self.energyTanks[3]: |
|
|
|
self.bitfield[12] = 1 |
|
|
|
if self.missileTanks[3]: |
|
|
|
self.bitfield[13] = 1 |
|
|
|
if self.missileTanks[4]: |
|
|
|
self.bitfield[14] = 1 |
|
|
|
if self.doors["Norfair"][1]: |
|
|
|
self.bitfield[15] = 1 |
|
|
|
if self.missileTanks[5]: |
|
|
|
self.bitfield[16] = 1 |
|
|
|
if self.missileTanks[6]: |
|
|
|
self.bitfield[17] = 1 |
|
|
|
if self.missileTanks[7]: |
|
|
|
self.bitfield[18] = 1 |
|
|
|
if self.missileTanks[8]: |
|
|
|
self.bitfield[19] = 1 |
|
|
|
if self.missileTanks[9]: |
|
|
|
self.bitfield[20] = 1 |
|
|
|
if self.missileTanks[10]: |
|
|
|
self.bitfield[21] = 1 |
|
|
|
if self.missileTanks[11]: |
|
|
|
self.bitfield[22] = 1 |
|
|
|
if self.doors["Norfair"][2]: |
|
|
|
self.bitfield[23] = 1 |
|
|
|
if self.itemsCollected["High Jump Boots"]: |
|
|
|
self.bitfield[24] = 1 |
|
|
|
if self.doors["Norfair"][3]: |
|
|
|
self.bitfield[25] = 1 |
|
|
|
if self.itemsCollected["Screw Attack"]: |
|
|
|
self.bitfield[26] = 1 |
|
|
|
if self.missileTanks[12]: |
|
|
|
self.bitfield[27] = 1 |
|
|
|
if self.missileTanks[13]: |
|
|
|
self.bitfield[28] = 1 |
|
|
|
if self.doors["Norfair"][4]: |
|
|
|
self.bitfield[29] = 1 |
|
|
|
if self.energyTanks[4]: |
|
|
|
self.bitfield[30] = 1 |
|
|
|
if self.missileTanks[14]: |
|
|
|
self.bitfield[31] = 1 |
|
|
|
if self.doors["Kraid"][1]: |
|
|
|
self.bitfield[32] = 1 |
|
|
|
if self.missileTanks[15]: |
|
|
|
self.bitfield[33] = 1 |
|
|
|
if self.missileTanks[16]: |
|
|
|
self.bitfield[34] = 1 |
|
|
|
if self.doors["Kraid"][2]: |
|
|
|
self.bitfield[35] = 1 |
|
|
|
if self.energyTanks[5]: |
|
|
|
self.bitfield[36] = 1 |
|
|
|
if self.doors["Kraid"][3]: |
|
|
|
self.bitfield[37] = 1 |
|
|
|
if self.doors["Kraid"][4]: |
|
|
|
self.bitfield[38] = 1 |
|
|
|
if self.missileTanks[17]: |
|
|
|
self.bitfield[39] = 1 |
|
|
|
if self.missileTanks[18]: |
|
|
|
self.bitfield[40] = 1 |
|
|
|
if self.doors["Kraid"][5]: |
|
|
|
self.bitfield[41] = 1 |
|
|
|
if self.energyTanks[6]: |
|
|
|
self.bitfield[42] = 1 |
|
|
|
if self.missileTanks[19]: |
|
|
|
self.bitfield[43] = 1 |
|
|
|
if self.doors["Ridley"][1]: |
|
|
|
self.bitfield[44] = 1 |
|
|
|
if self.energyTanks[7]: |
|
|
|
self.bitfield[45] = 1 |
|
|
|
if self.missileTanks[20]: |
|
|
|
self.bitfield[46] = 1 |
|
|
|
if self.doors["Ridley"][2]: |
|
|
|
self.bitfield[47] = 1 |
|
|
|
if self.energyTanks[8]: |
|
|
|
self.bitfield[48] = 1 |
|
|
|
if self.missileTanks[21]: |
|
|
|
self.bitfield[49] = 1 |
|
|
|
if self.doors["Tourian"][1]: |
|
|
|
self.bitfield[50] = 1 |
|
|
|
if self.doors["Tourian"][2]: |
|
|
|
self.bitfield[51] = 1 |
|
|
|
if self.doors["Tourian"][3]: |
|
|
|
self.bitfield[52] = 1 |
|
|
|
if self.zebetitesDestroyed[1]: |
|
|
|
self.bitfield[53] = 1 |
|
|
|
if self.zebetitesDestroyed[2]: |
|
|
|
self.bitfield[54] = 1 |
|
|
|
if self.zebetitesDestroyed[3]: |
|
|
|
self.bitfield[55] = 1 |
|
|
|
if self.zebetitesDestroyed[4]: |
|
|
|
self.bitfield[56] = 1 |
|
|
|
if self.zebetitesDestroyed[5]: |
|
|
|
self.bitfield[57] = 1 |
|
|
|
if self.motherBrainKilled: |
|
|
|
self.bitfield[58] = 1 |
|
|
|
# 59-63 unknown |
|
|
|
# if self.: |
|
|
|
# self.bitfield[59] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[60] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[61] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[62] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[63] = 1 |
|
|
|
# not 64, 65, or 66 = Brinstar |
|
|
|
# 64 = Norfair |
|
|
|
# 65 and not 66 = Kraid's Lair |
|
|
|
# 66 and not 65 = Ridley's Lair |
|
|
|
# 65 and 66 = Tourian |
|
|
|
if self.startLocation == 1: |
|
|
|
self.bitfield[64] = 1 |
|
|
|
if self.startLocation == 2 or self.startLocation == 4: |
|
|
|
self.bitfield[65] = 1 |
|
|
|
if self.startLocation == 3 or self.startLocation == 4: |
|
|
|
self.bitfield[66] = 1 |
|
|
|
# 67 is the reset bit, I want all passwords to be valid |
|
|
|
# if self.: |
|
|
|
# self.bitfield[67] = 1 |
|
|
|
# 68-70 are unknown |
|
|
|
# if self.: |
|
|
|
# self.bitfield[68] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[69] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[70] = 1 |
|
|
|
if self.swimsuit: |
|
|
|
self.bitfield[71] = 1 |
|
|
|
if self.samusHas["Bombs"]: |
|
|
|
self.bitfield[72] = 1 |
|
|
|
if self.samusHas["High Jump Boots"]: |
|
|
|
self.bitfield[73] = 1 |
|
|
|
if self.samusHas["Long Beam"]: |
|
|
|
self.bitfield[74] = 1 |
|
|
|
if self.samusHas["Screw Attack"]: |
|
|
|
self.bitfield[75] = 1 |
|
|
|
if self.samusHas["Maru Mari"]: |
|
|
|
self.bitfield[76] = 1 |
|
|
|
if self.samusHas["Varia"]: |
|
|
|
self.bitfield[77] = 1 |
|
|
|
if self.samusHas["Wave Beam"]: |
|
|
|
self.bitfield[78] = 1 |
|
|
|
if self.samusHas["Ice Beam"]: |
|
|
|
self.bitfield[79] = 1 |
|
|
|
# Missile count |
|
|
|
# +2^n from 0 to 7 |
|
|
|
binMissiles = bin(self.missileCount).replace('0b','')[::-1] |
|
|
|
while len(binMissiles) < 8: |
|
|
|
binMissiles += "0" |
|
|
|
if int(binMissiles[0]) == 1: |
|
|
|
self.bitfield[80] = 1 |
|
|
|
if int(binMissiles[1]) == 1: |
|
|
|
self.bitfield[81] = 1 |
|
|
|
if int(binMissiles[2]) == 1: |
|
|
|
self.bitfield[82] = 1 |
|
|
|
if int(binMissiles[3]) == 1: |
|
|
|
self.bitfield[83] = 1 |
|
|
|
if int(binMissiles[4]) == 1: |
|
|
|
self.bitfield[84] = 1 |
|
|
|
if int(binMissiles[5]) == 1: |
|
|
|
self.bitfield[85] = 1 |
|
|
|
if int(binMissiles[6]) == 1: |
|
|
|
self.bitfield[86] = 1 |
|
|
|
if int(binMissiles[7]) == 1: |
|
|
|
self.bitfield[87] = 1 |
|
|
|
# 88-119 are game age, leaving at 0 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[88] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[89] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[90] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[91] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[92] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[93] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[94] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[95] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[96] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[97] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[98] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[99] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[100] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[101] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[102] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[103] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[104] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[105] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[106] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[107] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[108] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[109] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[110] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[111] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[112] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[113] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[114] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[115] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[116] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[117] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[118] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[119] = 1 |
|
|
|
# 120-123 are unknown |
|
|
|
# if self.: |
|
|
|
# self.bitfield[120] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[121] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[122] = 1 |
|
|
|
# if self.: |
|
|
|
# self.bitfield[123] = 1 |
|
|
|
if self.ridleyKilled: |
|
|
|
self.bitfield[124] = 1 |
|
|
|
if self.ridleyStatue: |
|
|
|
self.bitfield[125] = 1 |
|
|
|
if self.kraidKilled: |
|
|
|
self.bitfield[126] = 1 |
|
|
|
if self.kraidStatue: |
|
|
|
self.bitfield[127] = 1 |
|
|
|
|
|
|
|
def generatePassword(self): |
|
|
|
# not gonna do the bit-shifting yet |
|
|
|
# shiftbit = random.randint(0,7) |
|
|
|
bitfield = self.bitfield |
|
|
|
# for _ in range(shiftbit): |
|
|
|
# [bitfield[127]] + bitfield[:127] |
|
|
|
# binShift = bin(shiftbit).replace('0b','') |
|
|
|
# while len(binShift) < 8: |
|
|
|
# binShift = "0" + binShift |
|
|
|
# for bit in binShift: |
|
|
|
# bitfield.append(int(bit)) |
|
|
|
bitfield = bitfield + [0,0,0,0,0,0,0,0] |
|
|
|
checking = [] |
|
|
|
for i in range(16): |
|
|
|
checking.append(int("".join([str(x) for x in bitfield[i:i+8]]), 2)) |
|
|
|
decChecksum = sum(checking) |
|
|
|
print(decChecksum) |
|
|
|
binChecksum = bin(decChecksum).replace('0b','') |
|
|
|
print(binChecksum) |
|
|
|
checksum = binChecksum[-8:] |
|
|
|
while len(checksum) < 8: |
|
|
|
checksum = checksum + "0" |
|
|
|
print(checksum) |
|
|
|
for bit in checksum: |
|
|
|
bitfield.append(int(bit)) |
|
|
|
print("Full Bitfield: {}".format("".join([str(x) for x in bitfield]))) |
|
|
|
print(len(bitfield)) |
|
|
|
letters = [] |
|
|
|
letter = [] |
|
|
|
for bit in bitfield: |
|
|
|
letter.append(str(bit)) |
|
|
|
if len(letter) == 6: |
|
|
|
print(letter) |
|
|
|
letters.append(self.alphabet[int("".join(letter),2)]) |
|
|
|
letter = [] |
|
|
|
print(letters) |
|
|
|
words = [] |
|
|
|
word = [] |
|
|
|
print(letters) |
|
|
|
print(len(letters)) |
|
|
|
for lt in letters: |
|
|
|
word.append(lt) |
|
|
|
if len(word) == 6: |
|
|
|
words.append("".join(word)) |
|
|
|
word = [] |
|
|
|
words.append("".join(word)) |
|
|
|
return " ".join(words) |
|
|
|
|
|
|
|
def main(): |
|
|
|
gs = MetroidState() |
|
|
|
gs.randomize() |
|
|
|
gs.createBitfield() |
|
|
|
print(gs.toString()) |
|
|
|
print(gs.generatePassword()) |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
main() |