Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nome = {"Grass_Energy","Fire_Energy","Water_Energy",
- "Lightning_Energy","Fighting_Energy","Psychic_Energy","Double_Colorless_Energy",
- "Bulbasaur_LV13","Ivysaur_LV20","Venusaur_LV64(CP!_Promo)","Venusaur_LV67",
- "Caterpie_LV13","Metapod_LV21","Butterfree_LV28","Weedle_LV12","Kakuna_LV23",
- "Beedrill_LV32","Ekans_LV10","Arbok_LV27","Nidoran_Female_LV13","Nidorina_LV24",
- "Nidoqueen_LV43","Nidoran_Male_LV20","Nidorino_LV25","Nidoking_LV48","Zubat_LV10",
- "Golbat_LV29","Oddish_LV8","Gloom_LV22","Vileplume_LV35","Paras_LV8",
- "Parasect_LV28","Venonat_LV12","Venomoth_LV28","Bellsprout_LV11","Weepinbell_LV28",
- "Victreebell_LV42","Grimer_LV17","Muk_LV34","Exeggcute_LV14","Exeggutor_LV35",
- "Koffing_LV13","Weezing_LV27","Tangela_LV8_(GB)","Tangela_LV12","Scyther_LV25",
- "Pinsir_LV24","Charmander_LV10","CharmelEon_LV32","Charizard_LV76","Vulpix_LV11",
- "Ninetails_LV32","Ninetails_LV35_(GB)","Growlithe_LV18","Arcanine_LV34_(Promo)",
- "Arcanine_LV45","Ponyta_LV10","Rapidash_LV33","Magmar_LV24","Magmar_LV31_(Fossil)",
- "Flareon_LV22_(GB)","Flareon_LV28_(Jungle)","Moltres_LV35",
- "Legendary_Moltres_LV37","Squirtle_LV8","Wartortle_LV22","Blastoise_LV52",
- "Psyduck_LV15","Golduck_LV27","Poliwag_LV13","Poliwhirl_LV28","Poliwrath_LV48",
- "Tentacool_LV10","Tentacruel_LV21","Seel_LV12","Dewgong_LV42","Shellder_LV8",
- "Cloyster_LV25","Krabby_LV20","Kingler_LV27","Horsea_LV19","Seadra_LV23",
- "Goldeen_LV12","Seaking_LV28","Staryu_LV15","Starmie_LV28","Magikarp_LV8",
- "Gyarados_LV41","Lapras_LV31","Vaporeon_LV29_(GB)","Vaporeon_LV42_(Jungle)",
- "Omanyte_LV19","Omastar_LV32","Articuno_LV35","Legendary_Articuno_LV37",
- "Pikachu_LV12","Pikachu_LV14_(Jungle)","Pikachu_LV16_(promo)",
- "Pikachu_LV16_(promo2)","Flying_Pikachu_LV12","Surfing_Pikachu_LV13",
- "Surfing_Pikachu_LV13_(2)","Raichu_LV40","Raichu_LV45_(Fossil)","Magnemite_LV13",
- "Magnemite_LV15_(GB)","Magneton_LV28","Magneton_LV35_(Fossil)","Voltorb_LV10",
- "Electrode_LV35_(GB)","Electrode_LV42_(Jungle)","Electabuzz_LV20_(Promo)",
- "Electabuzz_LV35","Jolteon_LV24_(GB)","Jolteon_LV29","Zapdos_LV40",
- "Zapdos_LV64_(Fossil)","Legendary_Zapdos_LV68","Sandshrew_LV12","Sandslash_LV33",
- "Diglett_LV8","Dugtrio_LV36","Mankey_LV7","Primeape_LV35","Machop_LV20",
- "Machoke_LV40","Machamp_LV67","Geodude_LV16","Graveler_LV29","Golem_LV36",
- "Onix_LV12","Cubone_LV13","Marowak_LV26_(Jungle)","Marowak_LV32_(GB)",
- "Hitmonlee_LV30","Hitmonchan_LV33","Rhyhorn_LV18","Rhydon_LV48","Kabuto_LV9",
- "Kabutops_LV30","Aerodactlyl_LV28","Abra_LV10","Kadabra_LV38","Alakazam_LV42",
- "Slowpoke_LV9_(Promo)","Slowpoke_LV18_(Fossil)","Slowbro_LV26","Gastly_LV8",
- "Gastly_LV17_(Fossil)","Haunter_LV17_(Fossil)","Haunter_LV22","Gengar_LV38",
- "Drowzee_LV12","Hypno_LV36","Mr.Mime_LV28","Jynx_LV23","Mewtwo_LV53",
- "Mewtwo_LV60_(Promo)","Mewtwo_LV60_(Promo_2)","Mew_LV8_(Promo)",
- "Mew_LV15_(CP!_Promo)","Mew_LV23","Pidgey_LV8","Pidgeotto_LV36",
- "Pidgeot_LV38_(GB)","Pidgeot_LV40_(Jungle)","Rattata_LV9","Raticate_LV41",
- "Spearow_LV13","Fearow_LV27","Clefairy_LV14","Clefable_LV34",
- "Jigglypuff_LV12_(Promo)","Jigglypuff_LV13_(GB)","Jigglypuff_LV14_(Jungle)",
- "Wigglytuff_LV36","Meowth_LV14_(GB)","Meowth_LV15_(Jungle)","Persian_LV25",
- "Farfetch'd_LV20","Doduo_LV10","Dodrio_LV28","Lickitung_LV26","Chansey_LV55",
- "Kangaskhan_LV40","Tauros_LV32","Ditto_LV19","Eevee_LV12","Porygon_LV12",
- "Snorlax_LV20","Dratini_LV10","Dragonair_LV33","Legendary_Dragonite_LV41",
- "Dragonite_LV45","Professor_Oak","Imposter_Professor_Oak","Bill","Mr.Fuji",
- "Lass","Imakuni?","Pokemon_Trader","Pokemon_Breeder","Clefairy_Doll",
- "Mysterious_Fossil","Energy_Retrieval","Super_Energy_Retrieval","Energy_Search",
- "Energy_Removal","Super_Energy_Removal","Switch","Pokemon_Center","Pokeball",
- "Scoop_Up","Computer_Search","Pokedex","Pluspower","Defender","Item_Finder",
- "Gust_of_Wind","Devolution_Spray","Potion","Super_Potion","Full_Heal","Revive",
- "Maintenance","Pokemon_Flute","Gambler","Recycle","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","","","","","","","","","","","",
- "","","","","","","","","","","","","","","","","",}
- --Copied from Aroymart's code. Hope it's right.
- 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 }
- --Same array, except basic Pokemon I really don't want to see (Lickitung, Mr. Mime, Lapras, etc.) are false. Weedle Nidoran F Paras Grimer KOffing 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
- 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, false,false, true, false, false,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, false,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,false,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 }
- --Run this before decks are shuffled, but after the screen with the opponent's name/deck name.
- memory.usememorydomain("System Bus")
- local DeckLocBegin=0xC300
- local MyDeckLocBegin=0xC200
- local DeckIDBegin=0xC480
- local MyDeckIDBegin=0xC400
- local ShuffledDeckBegin=0xC37E
- local MyShuffledDeckBegin=0xC27E
- local RNG1 = memory.readbyte(0xCACA)
- local RNG2 = memory.readbyte(0xCACB)
- local RNG3 = memory.readbyte(0xCACC)
- local initRNG1 = RNG1
- local initRNG2 = RNG2
- local initRNG3 = RNG3
- local myDeck = {}
- local oppDeck = {}
- for i=0,59 do
- myDeck[i] = i
- oppDeck[i] = i
- end
- function reset()
- --Go back to the start, but advance RNG once (simulate checking the next frame)
- RNG1 = initRNG1
- RNG2 = initRNG2
- RNG3 = initRNG3
- advanceRNG()
- initRNG1 = RNG1
- initRNG2 = RNG2
- initRNG3 = RNG3
- for i=0,59 do
- myDeck[i] = i
- oppDeck[i] = i
- end
- end
- function advanceRNG()
- --Recreation of the code that advances RNG
- local temp = RNG2
- temp = bit.rol(temp,2)
- if (bit.check(temp,8)) then temp = bit.set(temp,0) end
- temp = bit.clear(temp,8)
- if (bit.check(temp,9)) then temp = bit.set(temp,1) end
- temp = bit.clear(temp,9)
- temp = bit.bxor(temp,RNG1)
- local carry = bit.check(temp,0)
- RNG2 = bit.bxor(RNG2,RNG1)
- temp = RNG3
- temp = bit.bxor(temp,RNG1)
- RNG1 = temp
- RNG1 = bit.rol(RNG1,1)
- if (carry) then RNG1 = bit.set(RNG1,0) end
- carry = bit.check(RNG1,8)
- RNG1 = bit.clear(RNG1,8)
- RNG2 = bit.rol(RNG2,1)
- if (carry) then RNG2 = bit.set(RNG2,0) end
- RNG2 = bit.clear(RNG2,8)
- RNG3 = RNG3 + 1
- if (RNG3 == 256) then RNG3 = 0 end
- return (bit.bxor(RNG2,RNG1))
- end
- function randomSlot()
- --Get a random deck slot 0-59
- --This is done by multiplying the RNG value by 60, and taking the left 8 bits
- local rng = advanceRNG()
- local temp = rng * 60
- for i=0,7 do
- if (bit.check(temp,i+8)) then temp = bit.set(temp,i) else temp = bit.clear(temp,i) end
- temp = bit.clear(temp,i+8)
- end
- return temp
- end
- function shuffleDeck(deck)
- --Do 60 location swaps
- for curLoc=0,59 do
- local newLoc = randomSlot()
- local temp = deck[curLoc]
- deck[curLoc] = deck[newLoc]
- deck[newLoc] = temp
- end
- end
- --This is a recursive function (when it finds no basics) that checks all possibilities of reshuffles for good frames
- --CRITERIA TO KEEP A HAND: 2 Basics and 2 Energy in the hand, 4 Basics and 4 Energy within the top 13 cards (skipping the prizes)
- function checkForBasics(frames, myReshuffles, theirReshuffles)
- --First, before we check for cheating, check if they need to reshuffle for having no basics.
- local num = 0
- for h=0,6 do
- local loc = memory.readbyte(DeckIDBegin+oppDeck[h])
- if (isBasic[loc]) then
- num = num + 1
- break
- end
- end
- --No basics found; time to check both splitting possibilities (one where I reshuffle as well; may as well be thorough!)
- if (num == 0) then
- local tempRNG1 = RNG1
- local tempRNG2 = RNG2
- local tempRNG3 = RNG3
- local tempMyDeck = {}
- local tempOppDeck = {}
- for i=0,59 do
- tempMyDeck[i] = myDeck[i]
- tempOppDeck[i] = oppDeck[i]
- end
- for i=0,59 do
- myDeck[i] = i
- oppDeck[i] = i
- end
- shuffleDeck(myDeck)
- shuffleDeck(myDeck)
- shuffleDeck(oppDeck)
- shuffleDeck(oppDeck)
- checkForBasics(frames, myReshuffles+1, theirReshuffles+1)
- RNG1 = tempRNG1
- RNG2 = tempRNG2
- RNG3 = tempRNG3
- for i=0,59 do
- myDeck[i] = tempMyDeck[i]
- oppDeck[i] = tempOppDeck[i]
- end
- for i=0,59 do
- oppDeck[i] = i
- end
- shuffleDeck(oppDeck)
- shuffleDeck(oppDeck)
- checkForBasics(frames, myReshuffles, theirReshuffles+1)
- else
- --Time to simulate cheating. Once it's been simulated, then we'll see if the frame is even any good.
- --We'll also want to do it all over except with having me reshuffle, just in case.
- --And have me reshuffle twice too. Why not. Leader frames can be hard to find!
- local tempRNG1 = RNG1
- local tempRNG2 = RNG2
- local tempRNG3 = RNG3
- local tempMyDeck = {}
- local tempOppDeck = {}
- for i=0,59 do
- tempMyDeck[i] = myDeck[i]
- tempOppDeck[i] = oppDeck[i]
- end
- for i=0,59 do
- myDeck[i] = i
- end
- shuffleDeck(myDeck)
- shuffleDeck(myDeck)
- cheat(frames, myReshuffles+1,theirReshuffles)
- RNG1 = tempRNG1
- RNG2 = tempRNG2
- RNG3 = tempRNG3
- for i=0,59 do
- myDeck[i] = tempMyDeck[i]
- oppDeck[i] = tempOppDeck[i]
- end
- for i=0,59 do
- myDeck[i] = i
- end
- shuffleDeck(myDeck)
- shuffleDeck(myDeck)
- for i=0,59 do
- myDeck[i] = i
- end
- shuffleDeck(myDeck)
- shuffleDeck(myDeck)
- cheat(frames, myReshuffles+2,theirReshuffles)
- RNG1 = tempRNG1
- RNG2 = tempRNG2
- RNG3 = tempRNG3
- for i=0,59 do
- myDeck[i] = tempMyDeck[i]
- oppDeck[i] = tempOppDeck[i]
- end
- cheat(frames, myReshuffles,theirReshuffles)
- end
- end
- function cheat(frames, myReshuffles, theirReshuffles)
- local cheating = true
- local cheatReshuffles = 0
- --Something about "while cheating" makes me laugh
- while (cheating) do
- local handBasicCount = 0
- local handEnergyCount = 0
- local basicCount = 0
- local energyCount = 0
- for h=0,6 do
- local loc = memory.readbyte(DeckIDBegin+oppDeck[h])
- if (isBasic[loc]) then
- basicCount = basicCount + 1
- handBasicCount = handBasicCount + 1
- end
- if (loc <= 7) then
- energyCount = energyCount + 1
- handEnergyCount = handEnergyCount + 1
- end
- end
- for h=13,18 do
- local loc = memory.readbyte(DeckIDBegin+oppDeck[h])
- if (isBasic[loc]) then
- basicCount = basicCount + 1
- end
- if (loc <= 7) then
- energyCount = energyCount + 1
- end
- end
- if (basicCount < 4 or energyCount < 4 or handBasicCount < 2 or handEnergyCount < 2) then
- cheatReshuffles = cheatReshuffles + 1
- --Do some weird hand reversal thing only before the first reshuffle. Don't ask me, but it's a thing.
- if (cheatReshuffles == 1) then
- local temp = oppDeck[0]
- oppDeck[0] = oppDeck[6]
- oppDeck[6] = temp
- temp = oppDeck[1]
- oppDeck[1] = oppDeck[5]
- oppDeck[5] = temp
- temp = oppDeck[2]
- oppDeck[2] = oppDeck[4]
- oppDeck[4] = temp
- end
- shuffleDeck(oppDeck)
- else
- cheating = false
- --print("keeping " .. tostring(theirReshuffles) .. "with " .. basicCount .. energyCount)
- --for h=0,59 do
- --local loc = memory.readbyte(DeckIDBegin+oppDeck[h])
- --print(oppDeck[h] .. tostring(nome[loc]))
- --end
- end
- end
- --check if it's good hand
- local num = 0
- local good = true
- for h=0,6 do
- local loc = memory.readbyte(DeckIDBegin+oppDeck[h])
- if (isBasic[loc]) then
- num = num + 1
- if (not isGoodBasic[loc] or num > 2) then
- good = false
- break
- end
- end
- end
- --Check top draw for being a basic
- local loc = memory.readbyte(DeckIDBegin+oppDeck[13])
- if (isBasic[loc]) then
- good = false
- end
- if (good) then
- printFrame(frames,myReshuffles,theirReshuffles,cheatReshuffles)
- end
- end
- function printFrame(frames,myReshuffles,theirReshuffles,cheatReshuffles)
- --When we've found a good frame, let's check the coin flip.
- --A "1" here should mean tails
- --If the leader cheated their hand, I cannot possibly manipulate a tails to a heads
- local flipRNG = advanceRNG() % 2
- local coinFlip
- if (flipRNG == 1) then
- if (cheatReshuffles > 0) then return end
- coinFlip = "Tails"
- else coinFlip = "Heads" end
- local flipRNG = advanceRNG() % 2
- local coinFlip2
- --If they reshuffled more times than you, you cannot manipulate the coinflip
- if (flipRNG == 1) then
- coinFlip2 = "Tails"
- else coinFlip2 = "Heads" end
- print("Frame " .. tostring(frames) .. " found. Coin flip: " .. tostring(coinFlip))
- file = io.open("frames.txt","a")
- file:write("Frame " .. tostring(frames) .. ", " .. tostring(myReshuffles) .. " player reshuffles, " .. tostring(theirReshuffles) .. " opponent reshuffles, " .. tostring(cheatReshuffles) .. " cheat reshuffles\n")
- file:write("Coin flips: " .. tostring(coinFlip) .. ", " .. tostring(coinFlip2) .. "\n")
- local handIDs = {}
- file:write("Your hand: ")
- for i=0,6 do
- local loc = memory.readbyte(MyDeckIDBegin+myDeck[i])
- handIDs[i] = myDeck[i]+1
- file:write(tostring(myDeck[i]+1) .. ": " .. nome[loc] .. ", ")
- end
- file:write("\nYour prizes: ")
- for i=7,12 do
- local loc = memory.readbyte(MyDeckIDBegin+myDeck[i])
- file:write(tostring(myDeck[i]+1) .. ": " .. nome[loc] .. ", ")
- end
- file:write("Draws: " .. tostring(myDeck[13]+1) .. ": " .. nome[memory.readbyte(MyDeckIDBegin+myDeck[13])] .. ", ")
- file:write(tostring(myDeck[14]+1) .. ": " .. nome[memory.readbyte(MyDeckIDBegin+myDeck[14])] .. "\n")
- handIDs[7] = myDeck[13]+1
- handIDs[8] = myDeck[14]+1
- for i=0,8 do
- file:write(tostring(handIDs[i]) .. " ")
- end
- file:write("\n")
- file:write("Their hand: ")
- for i=0,6 do
- local loc = memory.readbyte(DeckIDBegin+oppDeck[i])
- file:write(nome[loc] .. ", ")
- end
- file:write("Turn 1 draw: " .. nome[memory.readbyte(DeckIDBegin+oppDeck[13])] .. "\n")
- file:write("=====\n")
- file:flush()
- file:close()
- end
- --delete contents of frames.txt
- file = io.open("frames.txt","w")
- file:close()
- --Run the main program for 240 frames. I'm probably not going to wait 2 seconds for a frame, but eh
- for counter=0,239 do
- shuffleDeck(myDeck)
- shuffleDeck(myDeck)
- shuffleDeck(oppDeck)
- shuffleDeck(oppDeck)
- --Check for Basic Pokemon on their side, do double reshuffle if they don't have any
- --Technically, if they have no Basics, we could influence RNG by reshuffling as well... So check that as well
- --If they have more than 1 Basic, or a "bad" Basic, the frame is skipped
- checkForBasics(counter, 0, 0)
- reset()
- end
- print("Completed")
- --shuffleDeck(myDeck)
- --shuffleDeck(myDeck)
- --shuffleDeck(oppDeck)
- --shuffleDeck(oppDeck)
- --for i=0,6 do
- --print(tostring(nome[memory.readbyte(MyDeckIDBegin+myDeck[i])]))
- --print(tostring(nome[memory.readbyte(DeckIDBegin+oppDeck[i])]))
- --end
Add Comment
Please, Sign In to add comment