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