Blazephlozard

Untitled

Jul 12th, 2017
171
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local nome = {"Grass_Energy","Fire_Energy","Water_Energy",
  2. "Lightning_Energy","Fighting_Energy","Psychic_Energy","Double_Colorless_Energy",
  3. "Bulbasaur_LV13","Ivysaur_LV20","Venusaur_LV64(CP!_Promo)","Venusaur_LV67",
  4. "Caterpie_LV13","Metapod_LV21","Butterfree_LV28","Weedle_LV12","Kakuna_LV23",
  5. "Beedrill_LV32","Ekans_LV10","Arbok_LV27","Nidoran_Female_LV13","Nidorina_LV24",
  6. "Nidoqueen_LV43","Nidoran_Male_LV20","Nidorino_LV25","Nidoking_LV48","Zubat_LV10",
  7. "Golbat_LV29","Oddish_LV8","Gloom_LV22","Vileplume_LV35","Paras_LV8",
  8. "Parasect_LV28","Venonat_LV12","Venomoth_LV28","Bellsprout_LV11","Weepinbell_LV28",
  9. "Victreebell_LV42","Grimer_LV17","Muk_LV34","Exeggcute_LV14","Exeggutor_LV35",
  10. "Koffing_LV13","Weezing_LV27","Tangela_LV8_(GB)","Tangela_LV12","Scyther_LV25",
  11. "Pinsir_LV24","Charmander_LV10","CharmelEon_LV32","Charizard_LV76","Vulpix_LV11",
  12. "Ninetails_LV32","Ninetails_LV35_(GB)","Growlithe_LV18","Arcanine_LV34_(Promo)",
  13. "Arcanine_LV45","Ponyta_LV10","Rapidash_LV33","Magmar_LV24","Magmar_LV31_(Fossil)",
  14. "Flareon_LV22_(GB)","Flareon_LV28_(Jungle)","Moltres_LV35",
  15. "Legendary_Moltres_LV37","Squirtle_LV8","Wartortle_LV22","Blastoise_LV52",
  16. "Psyduck_LV15","Golduck_LV27","Poliwag_LV13","Poliwhirl_LV28","Poliwrath_LV48",
  17. "Tentacool_LV10","Tentacruel_LV21","Seel_LV12","Dewgong_LV42","Shellder_LV8",
  18. "Cloyster_LV25","Krabby_LV20","Kingler_LV27","Horsea_LV19","Seadra_LV23",
  19. "Goldeen_LV12","Seaking_LV28","Staryu_LV15","Starmie_LV28","Magikarp_LV8",
  20. "Gyarados_LV41","Lapras_LV31","Vaporeon_LV29_(GB)","Vaporeon_LV42_(Jungle)",
  21. "Omanyte_LV19","Omastar_LV32","Articuno_LV35","Legendary_Articuno_LV37",
  22. "Pikachu_LV12","Pikachu_LV14_(Jungle)","Pikachu_LV16_(promo)",
  23. "Pikachu_LV16_(promo2)","Flying_Pikachu_LV12","Surfing_Pikachu_LV13",
  24. "Surfing_Pikachu_LV13_(2)","Raichu_LV40","Raichu_LV45_(Fossil)","Magnemite_LV13",
  25. "Magnemite_LV15_(GB)","Magneton_LV28","Magneton_LV35_(Fossil)","Voltorb_LV10",
  26. "Electrode_LV35_(GB)","Electrode_LV42_(Jungle)","Electabuzz_LV20_(Promo)",
  27. "Electabuzz_LV35","Jolteon_LV24_(GB)","Jolteon_LV29","Zapdos_LV40",
  28. "Zapdos_LV64_(Fossil)","Legendary_Zapdos_LV68","Sandshrew_LV12","Sandslash_LV33",
  29. "Diglett_LV8","Dugtrio_LV36","Mankey_LV7","Primeape_LV35","Machop_LV20",
  30. "Machoke_LV40","Machamp_LV67","Geodude_LV16","Graveler_LV29","Golem_LV36",
  31. "Onix_LV12","Cubone_LV13","Marowak_LV26_(Jungle)","Marowak_LV32_(GB)",
  32. "Hitmonlee_LV30","Hitmonchan_LV33","Rhyhorn_LV18","Rhydon_LV48","Kabuto_LV9",
  33. "Kabutops_LV30","Aerodactlyl_LV28","Abra_LV10","Kadabra_LV38","Alakazam_LV42",
  34. "Slowpoke_LV9_(Promo)","Slowpoke_LV18_(Fossil)","Slowbro_LV26","Gastly_LV8",
  35. "Gastly_LV17_(Fossil)","Haunter_LV17_(Fossil)","Haunter_LV22","Gengar_LV38",
  36. "Drowzee_LV12","Hypno_LV36","Mr.Mime_LV28","Jynx_LV23","Mewtwo_LV53",
  37. "Mewtwo_LV60_(Promo)","Mewtwo_LV60_(Promo_2)","Mew_LV8_(Promo)",
  38. "Mew_LV15_(CP!_Promo)","Mew_LV23","Pidgey_LV8","Pidgeotto_LV36",
  39. "Pidgeot_LV38_(GB)","Pidgeot_LV40_(Jungle)","Rattata_LV9","Raticate_LV41",
  40. "Spearow_LV13","Fearow_LV27","Clefairy_LV14","Clefable_LV34",
  41. "Jigglypuff_LV12_(Promo)","Jigglypuff_LV13_(GB)","Jigglypuff_LV14_(Jungle)",
  42. "Wigglytuff_LV36","Meowth_LV14_(GB)","Meowth_LV15_(Jungle)","Persian_LV25",
  43. "Farfetch'd_LV20","Doduo_LV10","Dodrio_LV28","Lickitung_LV26","Chansey_LV55",
  44. "Kangaskhan_LV40","Tauros_LV32","Ditto_LV19","Eevee_LV12","Porygon_LV12",
  45. "Snorlax_LV20","Dratini_LV10","Dragonair_LV33","Legendary_Dragonite_LV41",
  46. "Dragonite_LV45","Professor_Oak","Imposter_Professor_Oak","Bill","Mr.Fuji",
  47. "Lass","Imakuni?","Pokemon_Trader","Pokemon_Breeder","Clefairy_Doll",
  48. "Mysterious_Fossil","Energy_Retrieval","Super_Energy_Retrieval","Energy_Search",
  49. "Energy_Removal","Super_Energy_Removal","Switch","Pokemon_Center","Pokeball",
  50. "Scoop_Up","Computer_Search","Pokedex","Pluspower","Defender","Item_Finder",
  51. "Gust_of_Wind","Devolution_Spray","Potion","Super_Potion","Full_Heal","Revive",
  52. "Maintenance","Pokemon_Flute","Gambler","Recycle","","","","","","","","","","",
  53. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  54. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  55. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  56. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  57. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  58. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  59. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  60. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  61. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  62. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  63. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  64. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  65. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  66. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  67. "","","","","","","","","","","","","","","","","","","","","","","","","","","",
  68. "","","","","","","","","","","","","","","","","",}
  69.  
  70. --Copied from Aroymart's code. Hope it's right.
  71. local isBasic =     { false, false, false, false, false, false, false, true, false, false, false, true, false, false, true, false, false, true, false, true, false, false, true, false, false, true, false, true, false, false, true, false, true, false, true, false, false, true, false, true, false, true, false, true, true, true, true, true, false, false, true, false, false, true, false, false, true, false, true, true, false, false, true, true, true, false, false, true, false, true, false, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, false, false, false, true, true, true, true, true, true, true, true, true, false, false, true, true, false, false, true, false, false, true, true, false, false, true, true, true, true, false, true, false, true, false, true, false, false, true, false, false, true, true, false, false, true, true, true, false, false, false, false, true, false, false, true, true, false, true, true, false, false, false, true, false, true, true, true, true, true, true, true, true, true, false, false, false, true, false, true, false, true, false, true, true, true, false, true, true, false, true, true, false, true, true, true, true, true, true, true, true, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }
  72. --Same array, except basic Pokemon I really don't want to see (Lickitung, Mr. Mime, Lapras, etc.) are false.          Weedle                                 Nidoran F                                                          Paras                                         Grimer                                 Tangela     Scyther                                             Growlithe                                    Flareon       Moltres (I want to see the Legendary one)                        Tentacool    Seel (eh)                                                                                  Lapras (ew)                       Articuno    Pikachu                                                                                               Electabuzz                Zapdos                         Diglett                   Machop (eh)         Geodude             Onix                      Hitmons     Rhyhorn (eh)                      Abra                                                                    Drowzee      Mime  Jynx  Mewtwo (hoping for 2 Porygon on Rick this time. Mewtwo is no good)          Spearow                   Jigglypuffs              Meowths                               Lickitung, Chansey, Kangaskhan      Porygon, Snorlax, Dratini
  73. local isGoodBasic = { false, false, false, false, false, false, false, true, false, false, false, true, false, false, true, false, false, true, false, false,false, false, true, false, false, true, false, true, false, false, true, false, true, false, true, false, false, true, false, true, false, true, false, true, true, false,true, true, false, false, true, false, false, true, false, false, true, false, true, true, false, false, false,true, true, false, false, true, false, true, false, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, true, false, false,false, false, false, false, false,true, true, true, true, true, true, true, true, false, false, true, true, false, false, true, false, false, false,false,false, false, false,false,true, true, false, true, false, true, false, false,false, false, true, false, false, false,true, false, false, false,false,true, false, false, false, false, true, false, false, true, true, false, true, true, false, false, false, true, false, false,false,false,false,false,true, true, true, true, false, false, false, true, false, true, false, true, false, true, true, true, false, true, true, false, true, true, false, false,false,false,true, true, true, true, false,true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false }
  74.  
  75.  
  76. --Run this before decks are shuffled, but after the screen with the opponent's name/deck name.
  77.  
  78.  
  79. memory.usememorydomain("System Bus")
  80.  
  81. local DeckLocBegin=0xC300
  82. local MyDeckLocBegin=0xC200
  83. local DeckIDBegin=0xC480
  84. local MyDeckIDBegin=0xC400
  85. local ShuffledDeckBegin=0xC37E
  86. local MyShuffledDeckBegin=0xC27E
  87.  
  88. local RNG1 = memory.readbyte(0xCACA)
  89. local RNG2 = memory.readbyte(0xCACB)
  90. local RNG3 = memory.readbyte(0xCACC)
  91.  
  92. local initRNG1 = RNG1
  93. local initRNG2 = RNG2
  94. local initRNG3 = RNG3
  95.  
  96. local myDeck = {}
  97. local oppDeck = {}
  98.  
  99. for i=0,59 do
  100.     myDeck[i] = i
  101.     oppDeck[i] = i
  102. end
  103.  
  104. function reset()
  105.     --Go back to the start, but advance RNG once (simulate checking the next frame)
  106.     RNG1 = initRNG1
  107.     RNG2 = initRNG2
  108.     RNG3 = initRNG3
  109.     advanceRNG()
  110.     initRNG1 = RNG1
  111.     initRNG2 = RNG2
  112.     initRNG3 = RNG3
  113.    
  114.     for i=0,59 do
  115.         myDeck[i] = i
  116.         oppDeck[i] = i
  117.     end
  118. end
  119.  
  120. function advanceRNG()
  121.     --Recreation of the code that advances RNG
  122.     local temp = RNG2
  123.     temp = bit.rol(temp,2)
  124.     if (bit.check(temp,8)) then temp = bit.set(temp,0) end
  125.     temp = bit.clear(temp,8)
  126.     if (bit.check(temp,9)) then temp = bit.set(temp,1) end
  127.     temp = bit.clear(temp,9)
  128.     temp = bit.bxor(temp,RNG1)
  129.     local carry = bit.check(temp,0)
  130.    
  131.     RNG2 = bit.bxor(RNG2,RNG1)
  132.    
  133.     temp = RNG3
  134.     temp = bit.bxor(temp,RNG1)
  135.     RNG1 = temp
  136.    
  137.     RNG1 = bit.rol(RNG1,1)
  138.     if (carry) then RNG1 = bit.set(RNG1,0) end
  139.     carry = bit.check(RNG1,8)
  140.     RNG1 = bit.clear(RNG1,8)
  141.    
  142.     RNG2 = bit.rol(RNG2,1)
  143.     if (carry) then RNG2 = bit.set(RNG2,0) end
  144.     RNG2 = bit.clear(RNG2,8)
  145.    
  146.     RNG3 = RNG3 + 1
  147.     if (RNG3 == 256) then RNG3 = 0 end
  148.    
  149.     return (bit.bxor(RNG2,RNG1))
  150. end
  151.  
  152. function randomSlot()
  153.     --Get a random deck slot 0-59
  154.     --This is done by multiplying the RNG value by 60, and taking the left 8 bits
  155.     local rng = advanceRNG()
  156.     local temp = rng * 60
  157.     for i=0,7 do
  158.         if (bit.check(temp,i+8)) then temp = bit.set(temp,i) else temp = bit.clear(temp,i) end
  159.         temp = bit.clear(temp,i+8)
  160.     end
  161.     return temp
  162. end
  163.  
  164. function shuffleDeck(deck)
  165.     --Do 60 location swaps
  166.     for curLoc=0,59 do
  167.         local newLoc = randomSlot()
  168.         local temp = deck[curLoc]
  169.         deck[curLoc] = deck[newLoc]
  170.         deck[newLoc] = temp
  171.     end
  172. end
  173.  
  174. --This is a recursive function (when it finds no basics) that checks all possibilities of reshuffles for good frames
  175. function checkForBasics(frames, myReshuffles, theirReshuffles)
  176.     local num = 0
  177.     local good = true
  178.     for h=0,6 do
  179.         local loc = memory.readbyte(DeckIDBegin+oppDeck[h])
  180.         if (isBasic[loc]) then
  181.             num = num + 1
  182.             if (not isGoodBasic[loc] or num > 1) then
  183.                 good = false
  184.                 break
  185.             end
  186.         end
  187.     end
  188.     --No basics found; time to check both splitting possibilities (one where I reshuffle as well; may as well be thorough!)
  189.     if (num == 0) then
  190.         local tempRNG1 = RNG1
  191.         local tempRNG2 = RNG2
  192.         local tempRNG3 = RNG3
  193.         local tempMyDeck = {}
  194.         local tempOppDeck = {}
  195.         for i=0,59 do
  196.             tempMyDeck[i] = myDeck[i]
  197.             tempOppDeck[i] = oppDeck[i]
  198.         end
  199.         for i=0,59 do
  200.             myDeck[i] = i
  201.             oppDeck[i] = i
  202.         end
  203.         shuffleDeck(myDeck)
  204.         shuffleDeck(myDeck)
  205.         shuffleDeck(oppDeck)
  206.         shuffleDeck(oppDeck)
  207.         checkForBasics(frames, myReshuffles+1, theirReshuffles+1)
  208.         RNG1 = tempRNG1
  209.         RNG2 = tempRNG2
  210.         RNG3 = tempRNG3
  211.         for i=0,59 do
  212.              myDeck[i] = tempMyDeck[i]
  213.              oppDeck[i] = tempOppDeck[i]
  214.         end
  215.         for i=0,59 do
  216.             oppDeck[i] = i
  217.         end
  218.         shuffleDeck(oppDeck)
  219.         shuffleDeck(oppDeck)
  220.         checkForBasics(frames, myReshuffles, theirReshuffles+1)
  221.     elseif (good) then
  222.         printFrame(frames,myReshuffles,theirReshuffles)
  223.     end
  224. end
  225.  
  226. function printFrame(frames,myReshuffles,theirReshuffles)
  227.     --When we've found a good frame, let's check the coin flip.
  228.     --I'm not going to use the flip as a reason to not accept a frame, since it's often manipulatable with shuffling
  229.     --A "1" here should mean tails
  230.    
  231.     --NOTE: Turn 1 card is inaccurate for the 2/3 prize Water Club duels. Who cares, go check yourself
  232.     local flipRNG = advanceRNG() % 2
  233.     local coinFlip
  234.     --If they reshuffled more times than you, you cannot manipulate the coinflip
  235.     if (flipRNG == 1) then
  236.         if (theirReshuffles > myReshuffles) then return end
  237.         coinFlip = "Tails"
  238.     else coinFlip = "Heads" end
  239.    
  240.     local flipRNG = advanceRNG() % 2
  241.     local coinFlip2
  242.     --If they reshuffled more times than you, you cannot manipulate the coinflip
  243.     if (flipRNG == 1) then
  244.         coinFlip2 = "Tails"
  245.     else coinFlip2 = "Heads" end
  246.  
  247.     file = io.open("frames.txt","a")
  248.    
  249.     file:write("Frame " .. tostring(frames) .. ", " .. tostring(myReshuffles) .. " player reshuffles, " .. tostring(theirReshuffles) .. " opponent reshuffles\n")
  250.     file:write("Coin flips: " .. tostring(coinFlip) .. ", " .. tostring(coinFlip2) .. "\n")
  251.    
  252.     local handIDs = {}
  253.     file:write("Your hand: ")
  254.     for i=0,6 do
  255.         local loc = memory.readbyte(MyDeckIDBegin+myDeck[i])
  256.         handIDs[i] = myDeck[i]+1
  257.         file:write(tostring(myDeck[i]+1) .. ": " .. nome[loc] .. ", ")
  258.     end
  259.     file:write("Turn 1 draw: " .. tostring(myDeck[11]+1) .. ": " .. nome[memory.readbyte(MyDeckIDBegin+myDeck[11])] .. "\n")
  260.     handIDs[7] = myDeck[11]+1
  261.     for i=0,7 do
  262.         file:write(tostring(handIDs[i]) .. " ")
  263.     end
  264.     file:write("\n")
  265.    
  266.     --In 4-prize duels, I only care about the Basic in their hand.
  267.     file:write("Their basic: ")
  268.     for i=0,6 do
  269.         local loc = memory.readbyte(DeckIDBegin+oppDeck[i])
  270.         --file:write(nome[loc] .. ", ")
  271.         if (isBasic[loc]) then
  272.             print("Frame " .. tostring(frames) .. ", " .. tostring(coinFlip) .. ", " .. nome[loc])
  273.             file:write(nome[loc])
  274.            
  275.         end
  276.     end
  277.     file:write("\n")
  278.    
  279.     file:write("=====\n")
  280.     file:flush()
  281.     file:close()
  282. end
  283.  
  284. --delete contents of frames.txt
  285. file = io.open("frames.txt","w")
  286. file:close()
  287.  
  288. --Run the main program for 240 frames. I'm probably not going to wait 4 seconds for a frame, but eh
  289. for counter=0,119 do
  290.     shuffleDeck(myDeck)
  291.     shuffleDeck(myDeck)
  292.     shuffleDeck(oppDeck)
  293.     shuffleDeck(oppDeck)
  294.    
  295.     --Check for Basic Pokemon on their side, do double reshuffle if they don't have any
  296.     --Technically, if they have no Basics, we could influence RNG by reshuffling as well... So check that as well
  297.     --If they have more than 1 Basic, or a "bad" Basic, the frame is skipped
  298.    
  299.     checkForBasics(counter, 0, 0)
  300.    
  301.     reset()
  302. end
  303.  
  304. print("Completed")
  305.  
  306. --shuffleDeck(myDeck)
  307. --shuffleDeck(myDeck)
  308. --shuffleDeck(oppDeck)
  309. --shuffleDeck(oppDeck)
  310. --for i=0,6 do
  311.     --print(tostring(nome[memory.readbyte(MyDeckIDBegin+myDeck[i])]))
  312.     --print(tostring(nome[memory.readbyte(DeckIDBegin+oppDeck[i])]))
  313. --end
RAW Paste Data