A save state/password generator for the original Metroid.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

metroidgen.py 22KB

5 lat temu
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714
  1. # This uses http://games.technoplaza.net/mpg/password.txt as a basis for its password algorithm
  2. import random
  3. class MetroidState:
  4. def __init__(self):
  5. self.alphabet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz?-"
  6. self.itemsCollected = {
  7. "Maru Mari": False,
  8. "Bombs": False,
  9. "Long Beam": False,
  10. "Ice Beam": False,
  11. "Wave Beam": False,
  12. "High Jump Boots": False,
  13. "Varia": False,
  14. "Screw Attack": False
  15. }
  16. self.samusHas = {
  17. "Maru Mari": False,
  18. "Bombs": False,
  19. "Long Beam": False,
  20. "Ice Beam": False,
  21. "Wave Beam": False,
  22. "High Jump Boots": False,
  23. "Varia": False,
  24. "Screw Attack": False
  25. }
  26. self.missileTanks = {
  27. 1: False,
  28. 2: False,
  29. 3: False,
  30. 4: False,
  31. 5: False,
  32. 6: False,
  33. 7: False,
  34. 8: False,
  35. 9: False,
  36. 10: False,
  37. 11: False,
  38. 12: False,
  39. 13: False,
  40. 14: False,
  41. 15: False,
  42. 16: False,
  43. 17: False,
  44. 18: False,
  45. 19: False,
  46. 20: False,
  47. 21: False
  48. }
  49. self.energyTanks = {
  50. 1: False,
  51. 2: False,
  52. 3: False,
  53. 4: False,
  54. 5: False,
  55. 6: False,
  56. 7: False,
  57. 8: False
  58. }
  59. self.zebetitesDestroyed = {
  60. 1: False,
  61. 2: False,
  62. 3: False,
  63. 4: False,
  64. 5: False
  65. }
  66. self.doors = {
  67. "Brinstar": {
  68. 1: False,
  69. 2: False,
  70. 3: False,
  71. 4: False,
  72. 5: False
  73. }, "Norfair": {
  74. 1: False,
  75. 2: False,
  76. 3: False,
  77. 4: False
  78. }, "Kraid": {
  79. 1: False,
  80. 2: False,
  81. 3: False,
  82. 4: False,
  83. 5: False
  84. }, "Ridley": {
  85. 1: False,
  86. 2: False
  87. }, "Tourian": {
  88. 1: False,
  89. 2: False,
  90. 3: False
  91. }
  92. }
  93. self.kraidKilled = False
  94. self.ridleyKilled = False
  95. self.motherBrainKilled = False
  96. self.kraidStatue = False
  97. self.ridleyStatue = False
  98. self.swimsuit = False
  99. self.missileCount = 0
  100. self.gameAge = 0
  101. self.locations = ["Brinstar", "Norfair", "Kraid's Lair", "Ridley's Lair", "Tourian"]
  102. self.startLocation = 0
  103. self.bitfield = []
  104. self.initializeBitfield()
  105. def initializeBitfield(self):
  106. self.bitfield = []
  107. for _ in range(128):
  108. self.bitfield.append(0)
  109. def toggleItem(self, itm):
  110. if itm in self.itemsCollected.keys():
  111. self.itemsCollected[itm] = not self.itemsCollected[itm]
  112. self.samusHas[itm] = not self.samusHas[itm]
  113. else:
  114. print("Couldn't find item: {}".format(str(itm)))
  115. def toggleMissileTank(self, num):
  116. try:
  117. num = int(num)
  118. except:
  119. print("{} is not a number".format(num))
  120. return
  121. if num in self.missileTanks.keys():
  122. self.missileTanks[num] = not self.missileTanks[num]
  123. else:
  124. print("Couldn't find missile tank: {}".format(num))
  125. def toggleEnergyTank(self, num):
  126. try:
  127. num = int(num)
  128. except:
  129. print("{} is not a number".format(num))
  130. return
  131. if num in self.energyTanks.keys():
  132. self.energyTanks[num] = not self.energyTanks[num]
  133. else:
  134. print("Couldn't find energy tank: {}".format(num))
  135. def toggleZebetite(self, num):
  136. try:
  137. num = int(num)
  138. except:
  139. print("{} is not a number".format(num))
  140. return
  141. if num in self.zebetitesDestroyed.keys():
  142. self.zebetitesDestroyed[num] = not self.zebetitesDestroyed[num]
  143. else:
  144. print("Couldn't find Zebetite: {}".format(num))
  145. def toggleKraid(self):
  146. self.kraidKilled = not self.kraidKilled
  147. self.kraidStatue = self.kraidKilled
  148. def toggleKraidStatue(self):
  149. self.kraidStatue = not self.kraidStatue
  150. if self.kraidKilled and not self.kraidStatue:
  151. print("WARNING: Kraid has been killed but his statue has not been raised.")
  152. def toggleRidley(self):
  153. self.ridleyKilled = not self.ridleyKilled
  154. self.ridleyStatue = self.ridleyKilled
  155. def toggleRidleyStatue(self):
  156. self.ridleyStatue = not self.ridleyStatue
  157. if self.ridleyKilled and not self.ridleyStatue:
  158. print("WARNING: Ridley has been killed but his statue has not been raised.")
  159. def toggleMotherBrain(self):
  160. self.motherBrainKilled = not self.motherBrainKilled
  161. def toggleDoor(self, area, door):
  162. try:
  163. area = str(area)
  164. door = int(door)
  165. except:
  166. print("Area must be string, door must be a positive integer")
  167. return
  168. if area in self.doors.keys() and int(door) in self.doors[area].keys():
  169. self.doors[area][door] = not self.doors[area][door]
  170. else:
  171. print("Couldn't find door {} in area {}".format(door, area))
  172. def toggleSwimsuit(self):
  173. self.swimsuit = not self.swimsuit
  174. def newLocation(self, loc):
  175. try:
  176. loc = str(loc)
  177. except:
  178. print("Location must be a string")
  179. return
  180. if loc in self.locations:
  181. self.startLocation = self.locations.index(loc)
  182. else:
  183. print("Couldn't find location: {}".format(loc))
  184. def collectedItems(self):
  185. o = []
  186. for k,v in self.itemsCollected.items():
  187. if v == True:
  188. o.append(k)
  189. if len(o) == 0:
  190. return "None"
  191. else:
  192. return ", ".join(o)
  193. def collectedMissiles(self):
  194. o = []
  195. for k, v in self.missileTanks.items():
  196. if v == True:
  197. o.append(k)
  198. if len(o) == 0:
  199. return "None"
  200. else:
  201. return ", ".join([str(b) for b in o])
  202. def collectedEtanks(self):
  203. o = []
  204. for k, v in self.energyTanks.items():
  205. if v == True:
  206. o.append(k)
  207. if len(o) == 0:
  208. return "None"
  209. else:
  210. return ", ".join([str(b) for b in o])
  211. def killedZebetites(self):
  212. o = []
  213. for k, v in self.zebetitesDestroyed.items():
  214. if v == True:
  215. o.append(k)
  216. if len(o) == 0:
  217. return "None"
  218. else:
  219. return ", ".join([str(b) for b in o])
  220. def killedBosses(self):
  221. o = []
  222. if self.kraidKilled:
  223. o.append("Kraid")
  224. if self.ridleyKilled:
  225. o.append("Ridley")
  226. if self.motherBrainKilled:
  227. o.append("Mother Brain")
  228. if len(o) == 0:
  229. return "None"
  230. else:
  231. return ", ".join(o)
  232. def raisedStatues(self):
  233. o = []
  234. if self.kraidStatue:
  235. o.append("Kraid")
  236. if self.ridleyStatue:
  237. o.append("Ridley")
  238. if len(o) == 0:
  239. return "None"
  240. else:
  241. return ", ".join(o)
  242. def inBailey(self):
  243. if self.swimsuit:
  244. return "Yes"
  245. else:
  246. return "No"
  247. def openedDoors(self):
  248. d = {"Brinstar": 0, "Norfair": 0, "Kraid": 0, "Ridley": 0, "Tourian": 0}
  249. o = []
  250. for k,v in self.doors["Brinstar"].items():
  251. if v == True:
  252. d["Brinstar"] = d["Brinstar"] + 1
  253. for k,v in self.doors["Norfair"].items():
  254. if v == True:
  255. d["Norfair"] = d["Norfair"] + 1
  256. for k,v in self.doors["Kraid"].items():
  257. if v == True:
  258. d["Kraid"] = d["Kraid"] + 1
  259. for k,v in self.doors["Ridley"].items():
  260. if v == True:
  261. d["Ridley"] = d["Ridley"] + 1
  262. for k,v in self.doors["Tourian"].items():
  263. if v == True:
  264. d["Tourian"] = d["Tourian"] + 1
  265. for k, v in d.items():
  266. o.append("{} {}".format(k, v))
  267. return ", ".join(o)
  268. def getBits(self):
  269. o = []
  270. word = []
  271. for i in range(128):
  272. word.append(str(self.bitfield[i]))
  273. if len(word) == 8:
  274. o.append("".join(word))
  275. word = []
  276. o1 = " ".join(o[:8])
  277. o2 = " ".join(o[8:])
  278. return o1 + "\n" + o2
  279. def toString(self):
  280. ic = "Items Collected: {}".format(self.collectedItems())
  281. mt = "Missile Tanks Collected: {}".format(self.collectedMissiles())
  282. et = "Energy Tanks Collected: {}".format(self.collectedEtanks())
  283. zb = "Zebetites Killed: {}".format(self.killedZebetites())
  284. kb = "Bosses Killed: {}".format(self.killedBosses())
  285. rs = "Statues Raised: {}".format(self.raisedStatues())
  286. sw = "Swimsuit?: {}".format(self.inBailey())
  287. sl = "Start Location: {}".format(self.locations[self.startLocation])
  288. dr = "Unlocked Doors: {}".format(self.openedDoors())
  289. ms = "Missiles: {}".format(self.missileCount)
  290. bf = "Bitfield:\n{}".format(self.getBits())
  291. return "\n".join([ic, mt, et, zb, kb, rs, sw, sl, dr, ms, bf])
  292. def randomize(self):
  293. # Items
  294. if random.randint(0,1) == 1:
  295. self.toggleItem("Maru Mari")
  296. if random.randint(0,1) == 1:
  297. self.toggleItem("Bombs")
  298. if random.randint(0,1) == 1:
  299. self.toggleItem("Varia")
  300. if random.randint(0,1) == 1:
  301. self.toggleItem("High Jump Boots")
  302. if random.randint(0,1) == 1:
  303. self.toggleItem("Screw Attack")
  304. if random.randint(0,1) == 1:
  305. self.toggleItem("Long Beam")
  306. beam = random.randint(0,2)
  307. if beam == 1:
  308. self.toggleItem("Ice Beam")
  309. elif beam == 2:
  310. self.toggleItem("Wave Beam")
  311. # Missile Tanks
  312. for i in range(21):
  313. if random.randint(0,1) == 1:
  314. self.toggleMissileTank(i+1)
  315. # Energy Tanks
  316. for i in range(8):
  317. if random.randint(0,1) == 1:
  318. self.toggleEnergyTank(i+1)
  319. # Zebetites
  320. for i in range(5):
  321. if random.randint(0,1) == 1:
  322. self.toggleZebetite(i+1)
  323. # Bosses killed
  324. if random.randint(0,1) == 1:
  325. self.toggleKraid()
  326. if random.randint(0,1) == 1:
  327. self.toggleRidley()
  328. if random.randint(0,1) == 1:
  329. self.toggleMotherBrain()
  330. # Statues raised
  331. if not self.kraidKilled and random.randint(0,1) == 1:
  332. self.toggleKraidStatue()
  333. if not self.ridleyKilled and random.randint(0,1) == 1:
  334. self.toggleRidleyStatue()
  335. # Doors
  336. # Brinstar 5, Norfair 4, Kraid 5, Ridley 2, Tourian 3
  337. for i in range(5):
  338. if random.randint(0,1) == 1:
  339. self.doors["Brinstar"][i+1] = True
  340. for i in range(4):
  341. if random.randint(0,1) == 1:
  342. self.doors["Norfair"][i+1] = True
  343. for i in range(5):
  344. if random.randint(0,1) == 1:
  345. self.doors["Kraid"][i+1] = True
  346. for i in range(2):
  347. if random.randint(0,1) == 1:
  348. self.doors["Ridley"][i+1] = True
  349. for i in range(3):
  350. if random.randint(0,1) == 1:
  351. self.doors["Tourian"][i+1] = True
  352. # Swimsuit
  353. if random.randint(0,2) == 2:
  354. self.toggleSwimsuit()
  355. # Start Location
  356. self.startLocation = random.randint(0,4)
  357. self.missileCount = random.randint(0,255)
  358. def createBitfield(self):
  359. self.initializeBitfield()
  360. # Doing this in order, which is dumb and tedious but accurate.
  361. if self.itemsCollected["Maru Mari"]:
  362. self.bitfield[0] = 1
  363. if self.missileTanks[1]:
  364. self.bitfield[1] = 1
  365. if self.doors["Brinstar"][1]:
  366. self.bitfield[2] = 1
  367. if self.doors["Brinstar"][2]:
  368. self.bitfield[3] = 1
  369. if self.energyTanks[1]:
  370. self.bitfield[4] = 1
  371. if self.doors["Brinstar"][3]:
  372. self.bitfield[5] = 1
  373. if self.itemsCollected["Bombs"]:
  374. self.bitfield[6] = 1
  375. if self.doors["Brinstar"][4]:
  376. self.bitfield[7] = 1
  377. if self.missileTanks[2]:
  378. self.bitfield[8] = 1
  379. if self.energyTanks[2]:
  380. self.bitfield[9] = 1
  381. if self.doors["Brinstar"][5]:
  382. self.bitfield[10] = 1
  383. if self.itemsCollected["Varia"]:
  384. self.bitfield[11] = 1
  385. if self.energyTanks[3]:
  386. self.bitfield[12] = 1
  387. if self.missileTanks[3]:
  388. self.bitfield[13] = 1
  389. if self.missileTanks[4]:
  390. self.bitfield[14] = 1
  391. if self.doors["Norfair"][1]:
  392. self.bitfield[15] = 1
  393. if self.missileTanks[5]:
  394. self.bitfield[16] = 1
  395. if self.missileTanks[6]:
  396. self.bitfield[17] = 1
  397. if self.missileTanks[7]:
  398. self.bitfield[18] = 1
  399. if self.missileTanks[8]:
  400. self.bitfield[19] = 1
  401. if self.missileTanks[9]:
  402. self.bitfield[20] = 1
  403. if self.missileTanks[10]:
  404. self.bitfield[21] = 1
  405. if self.missileTanks[11]:
  406. self.bitfield[22] = 1
  407. if self.doors["Norfair"][2]:
  408. self.bitfield[23] = 1
  409. if self.itemsCollected["High Jump Boots"]:
  410. self.bitfield[24] = 1
  411. if self.doors["Norfair"][3]:
  412. self.bitfield[25] = 1
  413. if self.itemsCollected["Screw Attack"]:
  414. self.bitfield[26] = 1
  415. if self.missileTanks[12]:
  416. self.bitfield[27] = 1
  417. if self.missileTanks[13]:
  418. self.bitfield[28] = 1
  419. if self.doors["Norfair"][4]:
  420. self.bitfield[29] = 1
  421. if self.energyTanks[4]:
  422. self.bitfield[30] = 1
  423. if self.missileTanks[14]:
  424. self.bitfield[31] = 1
  425. if self.doors["Kraid"][1]:
  426. self.bitfield[32] = 1
  427. if self.missileTanks[15]:
  428. self.bitfield[33] = 1
  429. if self.missileTanks[16]:
  430. self.bitfield[34] = 1
  431. if self.doors["Kraid"][2]:
  432. self.bitfield[35] = 1
  433. if self.energyTanks[5]:
  434. self.bitfield[36] = 1
  435. if self.doors["Kraid"][3]:
  436. self.bitfield[37] = 1
  437. if self.doors["Kraid"][4]:
  438. self.bitfield[38] = 1
  439. if self.missileTanks[17]:
  440. self.bitfield[39] = 1
  441. if self.missileTanks[18]:
  442. self.bitfield[40] = 1
  443. if self.doors["Kraid"][5]:
  444. self.bitfield[41] = 1
  445. if self.energyTanks[6]:
  446. self.bitfield[42] = 1
  447. if self.missileTanks[19]:
  448. self.bitfield[43] = 1
  449. if self.doors["Ridley"][1]:
  450. self.bitfield[44] = 1
  451. if self.energyTanks[7]:
  452. self.bitfield[45] = 1
  453. if self.missileTanks[20]:
  454. self.bitfield[46] = 1
  455. if self.doors["Ridley"][2]:
  456. self.bitfield[47] = 1
  457. if self.energyTanks[8]:
  458. self.bitfield[48] = 1
  459. if self.missileTanks[21]:
  460. self.bitfield[49] = 1
  461. if self.doors["Tourian"][1]:
  462. self.bitfield[50] = 1
  463. if self.doors["Tourian"][2]:
  464. self.bitfield[51] = 1
  465. if self.doors["Tourian"][3]:
  466. self.bitfield[52] = 1
  467. if self.zebetitesDestroyed[1]:
  468. self.bitfield[53] = 1
  469. if self.zebetitesDestroyed[2]:
  470. self.bitfield[54] = 1
  471. if self.zebetitesDestroyed[3]:
  472. self.bitfield[55] = 1
  473. if self.zebetitesDestroyed[4]:
  474. self.bitfield[56] = 1
  475. if self.zebetitesDestroyed[5]:
  476. self.bitfield[57] = 1
  477. if self.motherBrainKilled:
  478. self.bitfield[58] = 1
  479. # 59-63 unknown
  480. # if self.:
  481. # self.bitfield[59] = 1
  482. # if self.:
  483. # self.bitfield[60] = 1
  484. # if self.:
  485. # self.bitfield[61] = 1
  486. # if self.:
  487. # self.bitfield[62] = 1
  488. # if self.:
  489. # self.bitfield[63] = 1
  490. # not 64, 65, or 66 = Brinstar
  491. # 64 = Norfair
  492. # 65 and not 66 = Kraid's Lair
  493. # 66 and not 65 = Ridley's Lair
  494. # 65 and 66 = Tourian
  495. if self.startLocation == 1:
  496. self.bitfield[64] = 1
  497. if self.startLocation == 2 or self.startLocation == 4:
  498. self.bitfield[65] = 1
  499. if self.startLocation == 3 or self.startLocation == 4:
  500. self.bitfield[66] = 1
  501. # 67 is the reset bit, I want all passwords to be valid
  502. # if self.:
  503. # self.bitfield[67] = 1
  504. # 68-70 are unknown
  505. # if self.:
  506. # self.bitfield[68] = 1
  507. # if self.:
  508. # self.bitfield[69] = 1
  509. # if self.:
  510. # self.bitfield[70] = 1
  511. if self.swimsuit:
  512. self.bitfield[71] = 1
  513. if self.samusHas["Bombs"]:
  514. self.bitfield[72] = 1
  515. if self.samusHas["High Jump Boots"]:
  516. self.bitfield[73] = 1
  517. if self.samusHas["Long Beam"]:
  518. self.bitfield[74] = 1
  519. if self.samusHas["Screw Attack"]:
  520. self.bitfield[75] = 1
  521. if self.samusHas["Maru Mari"]:
  522. self.bitfield[76] = 1
  523. if self.samusHas["Varia"]:
  524. self.bitfield[77] = 1
  525. if self.samusHas["Wave Beam"]:
  526. self.bitfield[78] = 1
  527. if self.samusHas["Ice Beam"]:
  528. self.bitfield[79] = 1
  529. # Missile count
  530. # +2^n from 0 to 7
  531. binMissiles = bin(self.missileCount).replace('0b','')[::-1]
  532. while len(binMissiles) < 8:
  533. binMissiles += "0"
  534. if int(binMissiles[0]) == 1:
  535. self.bitfield[80] = 1
  536. if int(binMissiles[1]) == 1:
  537. self.bitfield[81] = 1
  538. if int(binMissiles[2]) == 1:
  539. self.bitfield[82] = 1
  540. if int(binMissiles[3]) == 1:
  541. self.bitfield[83] = 1
  542. if int(binMissiles[4]) == 1:
  543. self.bitfield[84] = 1
  544. if int(binMissiles[5]) == 1:
  545. self.bitfield[85] = 1
  546. if int(binMissiles[6]) == 1:
  547. self.bitfield[86] = 1
  548. if int(binMissiles[7]) == 1:
  549. self.bitfield[87] = 1
  550. # 88-119 are game age, leaving at 0
  551. # if self.:
  552. # self.bitfield[88] = 1
  553. # if self.:
  554. # self.bitfield[89] = 1
  555. # if self.:
  556. # self.bitfield[90] = 1
  557. # if self.:
  558. # self.bitfield[91] = 1
  559. # if self.:
  560. # self.bitfield[92] = 1
  561. # if self.:
  562. # self.bitfield[93] = 1
  563. # if self.:
  564. # self.bitfield[94] = 1
  565. # if self.:
  566. # self.bitfield[95] = 1
  567. # if self.:
  568. # self.bitfield[96] = 1
  569. # if self.:
  570. # self.bitfield[97] = 1
  571. # if self.:
  572. # self.bitfield[98] = 1
  573. # if self.:
  574. # self.bitfield[99] = 1
  575. # if self.:
  576. # self.bitfield[100] = 1
  577. # if self.:
  578. # self.bitfield[101] = 1
  579. # if self.:
  580. # self.bitfield[102] = 1
  581. # if self.:
  582. # self.bitfield[103] = 1
  583. # if self.:
  584. # self.bitfield[104] = 1
  585. # if self.:
  586. # self.bitfield[105] = 1
  587. # if self.:
  588. # self.bitfield[106] = 1
  589. # if self.:
  590. # self.bitfield[107] = 1
  591. # if self.:
  592. # self.bitfield[108] = 1
  593. # if self.:
  594. # self.bitfield[109] = 1
  595. # if self.:
  596. # self.bitfield[110] = 1
  597. # if self.:
  598. # self.bitfield[111] = 1
  599. # if self.:
  600. # self.bitfield[112] = 1
  601. # if self.:
  602. # self.bitfield[113] = 1
  603. # if self.:
  604. # self.bitfield[114] = 1
  605. # if self.:
  606. # self.bitfield[115] = 1
  607. # if self.:
  608. # self.bitfield[116] = 1
  609. # if self.:
  610. # self.bitfield[117] = 1
  611. # if self.:
  612. # self.bitfield[118] = 1
  613. # if self.:
  614. # self.bitfield[119] = 1
  615. # 120-123 are unknown
  616. # if self.:
  617. # self.bitfield[120] = 1
  618. # if self.:
  619. # self.bitfield[121] = 1
  620. # if self.:
  621. # self.bitfield[122] = 1
  622. # if self.:
  623. # self.bitfield[123] = 1
  624. if self.ridleyKilled:
  625. self.bitfield[124] = 1
  626. if self.ridleyStatue:
  627. self.bitfield[125] = 1
  628. if self.kraidKilled:
  629. self.bitfield[126] = 1
  630. if self.kraidStatue:
  631. self.bitfield[127] = 1
  632. def generatePassword(self):
  633. # not gonna do the bit-shifting yet
  634. # shiftbit = random.randint(0,7)
  635. bitfield = self.bitfield
  636. # for _ in range(shiftbit):
  637. # [bitfield[127]] + bitfield[:127]
  638. # binShift = bin(shiftbit).replace('0b','')
  639. # while len(binShift) < 8:
  640. # binShift = "0" + binShift
  641. # for bit in binShift:
  642. # bitfield.append(int(bit))
  643. bitfield = bitfield + [0,0,0,0,0,0,0,0]
  644. # checking = []
  645. # for i in range(16):
  646. # checking.append(int("".join([str(x) for x in bitfield[i:i+8]]), 2))
  647. decChecksum = sum(bitfield)
  648. binChecksum = bin(decChecksum).replace('0b','')
  649. checksum = binChecksum[-8:]
  650. while len(checksum) < 8:
  651. checksum = checksum + "0"
  652. print(checksum)
  653. for bit in checksum:
  654. bitfield.append(int(bit))
  655. print("Full Bitfield: {}".format("".join([str(x) for x in bitfield])))
  656. print(len(bitfield))
  657. letters = []
  658. letter = []
  659. for bit in bitfield:
  660. letter.append(str(bit))
  661. if len(letter) == 6:
  662. print(letter)
  663. letters.append(self.alphabet[int("".join(letter),2)])
  664. letter = []
  665. print(letters)
  666. words = []
  667. word = []
  668. print(letters)
  669. print(len(letters))
  670. for lt in letters:
  671. word.append(lt)
  672. if len(word) == 6:
  673. words.append("".join(word))
  674. word = []
  675. words.append("".join(word))
  676. return " ".join(words)
  677. def main():
  678. gs = MetroidState()
  679. gs.randomize()
  680. gs.createBitfield()
  681. print(gs.toString())
  682. print(gs.generatePassword())
  683. if __name__ == "__main__":
  684. main()