-- ~40mins@60fps
package.path = "./main/?.lua;"
movement = loadfile('movement.lua')
m = movement()
local num = 6

press_b = {
    {'b', 60}
}

pokecenter_heal = {
    {'a', 15}, -- heal
    {'a', 60},
    {'a', 60},
    {'a', 60},
    {'a', 60},
    {'w', 500},
    {'b', 60},
    {'b', 60},
    {'b', 60}, -- end heal
}

use_move = {
    {'a', 15},
    {'a', 15},
    {'w', 540},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
    {'b', 100},
}

start6 = {
    -- saffron-2
    {'w', 180}, -- classic buffer wait
    {'d', 3}, -- leave saffron
    {'r', 6},
    {'d', 26},
    {'l', 18},
    --mapChange
    {'d', 8},
    {'w', 180},
    {'d', 9}, -- enter route whatever
    --mapChange
    {'w', 200},
    {'d', 4},
    {'l', 4},
    {'d', 5},
    {'l', 3},
    {'d', 7},
    {'r', 12},
    {'d', 10},
    {'l', 8},
    --mapChange
    {'d', 21}, -- enter vermillion
    {'r', 8},
    {'u', 3},
    {'r', 11},
    {'d', 10},
    {'l', 10},
    {'u', 4},
    {'l', 6},
    {'d', 6},
    {'l', 5},
    {'d', 2},
    {'l', 11},
    {'u', 4}, -- enter bike guys house
    --mapChange
    {'w', 180},
{'l', 4},
{'w', 51},
{'u', 7},
{'w', 59},
{'r', 3},
{'w', 55},
{'a', 16},
{'w', 148},
{'b', 32},
{'w', 92},
{'b', 27},
{'w', 77},
{'b', 21},
{'w', 91},
{'b', 22},
{'w', 208},
{'a', 31},
{'press_b', 24}, -- get voucher
-- we actually HAVE to get the bike because to get to
-- Koga, we can take 1 of 2 routes.  One route requires
-- a bike and is actually doable
-- the other has a bridge with 3 trainers that
-- move randomly, and is more or less unsolvable
-- so we can't go down it.
{'w', 60},
    {'l', 2}, -- leave the guys house
    {'w', 51},
    {'d', 5},
    {'w', 41},
    {'r', 3},
    {'w', 45},
    {'d', 4}, -- out to verm
    --mapChange
    {'w', 180},
{'d', 2},
{'w', 40},
{'r', 12},
{'u', 7},
{'w', 72},
{'r', 10},
{'d', 4},
{'w', 26},
{'r', 8},
{'u', 10},
{'l', 13},
{'w', 29},
{'d', 2},
{'w', 28},
{'l', 4},
{'w', 28},
--mapChange
{'u', 22}, -- out of verm to route
{'w', 35},
{'r', 6},
{'u', 9},
{'w', 33},
{'l', 10},
{'w', 21},
{'u', 8},
{'w', 24},
{'r', 9},
{'w', 30},
{'d', 3},
{'w', 33},
{'r', 4},
{'u', 3}, -- into path house
--mapChange
{'w', 180},
{'u', 2},
{'w', 37},
{'r', 3},
{'w', 29},
{'u', 3},
{'w', 38},
{'l', 3},
{'w', 180}, -- into underground pass
{'u', 58},
{'r', 4},
{'w', 180}, -- out of underground
{'d', 5},
{'l', 2},
{'d', 2}, -- out of building
{'w', 180},
{'l', 3},
--mapChange
{'u', 40},
{'l', 4}, -- cut tree
{'u', 1},
{'a', 17},
{'w', 96},
{'a', 21},
{'w', 147},
{'a', 17},
{'w', 82},
{'a', 11},
{'w', 285},
{'u', 4}, -- enter cerulean
{'w', 60},
{'l', 11},
{'w', 50},
{'l', 3},
{'w', 25},
{'u', 2}, -- go into bike shop
--mapChange
{'w', 180},
{'u', 2},
{'r', 3},
{'u', 4},
{'r', 1},
{'w', 30},
{'a', 12},
{'press_b', 20},
-- cerulean-1
{'w', 90},
{'d', 3}, -- go to saffron
{'l', 2},
{'d', 3},
{'l', 2},
{'d', 3},
--mapChange
{'w', 180},
{'r', 14},
{'d', 3},
{'w', 97},
{'a', 13},
{'w', 90},
{'a', 16},
{'w', 87},
{'a', 13},
{'w', 120},
{'b', 12},
{'w', 243},
{'d', 3},
{'w', 44},
{'r', 4},
{'w', 41},
--mapChange
{'d', 38},
{'l', 5},
{'d', 3},
--mapChange
{'w', 180},
--mapChange
{'d', 10}, -- enter saffron
{'w', 180},
{'l', 2},
{'d', 8},
{'r', 2},
{'d', 3},
{'l', 20},
{'d', 13},
--mapChange
{'l', 11}, -- into passway
{'w', 180},
{'l', 11}, 
{'w', 180}, -- go to celadon
{'l', 8},
{'w', 36},
{'u', 7},
{'w', 32},
--mapChange
{'l', 27},
{'d', 2},
{'w', 24},
{'l', 36},
{'w', 33},
{'d', 9},
{'w', 27},
--mapChange
{'l', 25},
{'w', 60},
{'a', 15}, -- fight snorlax
{'w', 94},
{'a', 9},
{'w', 597},
{'b', 17},
{'w', 108},
{'b', 16},
{'w', 434},
{'b', 16},
{'w', 254},
{'use_move', 1},
{'l', 6}, -- into passageway
{'w', 180},
{'l', 11}, --auto-equip bike
{'w', 180},
{'l', 4},
{'u', 1},
{'a', 15},
{'w', 180},
{'b', 15},
{'w', 426},
{'b', 16},
{'w', 359},
{'use_move', 2},
{'b', 60},
{'u', 2},
{'w', 90},
{'l', 2},
{'d', 1},
{'a', 15},
{'w', 180},
{'b', 15},
{'w', 430},
{'b', 17},
{'w', 460},
{'a', 21},
{'use_move', 3},
{'d', 2},
{'w', 30},
{'l', 2},
{'u', 1},
{'a', 15},
{'w', 154},
{'b', 15},
{'w', 440},
{'b', 14},
{'w', 420},
{'a', 13},
{'use_move', 2},
{'press_b', 2},
{'l', 1},
{'d', 1},
{'l', 1},
{'a', 15},
{'w', 162},
{'b', 14},
{'w', 429},
{'b', 18},
{'w', 460},
{'a', 14},
{'use_move', 1},
{'d', 5},
{'l', 4},
{'d', 1},
{'w', 400},
{'a', 15},
{'w', 169},
{'b', 10},
{'w', 429},
{'b', 13},
{'w', 500},
{'use_move', 1},
{'press_b', 5},
{'l', 1},
{'w', 150},
{'r', 4},
{'w', 360},
{'l', 3},
{'w', 169},
{'b', 112},
{'runL', 90},
{'w', 120},
{'r', 6},
{'w', 240},
{'d', 10},
{'rf', 400},
{'w', 120},
{'r', 15},
{'d', 17},
{'r', 8},
{'u', 3},
{'r', 14},
{'u', 4},
{'w', 180},
{'u', 6}, -- into pokecenter, off bike
{'pokecenter_heal', 1},
{'d', 6},
{'w', 180},
-- fuschia-1
{'w', 90},
{'l', 15},
{'d', 2},
{'l', 3},
{'u', 2}, -- into fushia gym
--mapChange
{'w', 240},
{'u', 4},
{'r', 6},
{'u', 1},
{'w', 30},
{'a', 15},
{'w', 160},
{'b', 34},
{'w', 171},
{'b', 41},
{'w', 134},
{'b', 23},
{'w', 506},
{'b', 27},
{'w', 460},
{'a', 15},
{'rf', 15},
{'use_move', 1},
{'u', 2},
{'w', 60},
{'r', 2},
{'u', 7},
{'w', 240},
{'b', 14},
{'w', 129},
{'b', 13},
{'w', 496},
{'b', 14},
{'w', 447},
{'a', 18},
{'rf', 15},
{'use_move',4}, 
{'press_b', 4},
{'w', 90},
{'u', 1},
{'l', 2},
{'u', 3},
{'u', 1},
{'u', 1},
{'u', 2},
{'r', 1},
{'w', 21},
{'a', 14},
{'w', 500},
{'b', 9},
{'w', 180},
{'b', 12},
{'w', 459},
{'b', 17},
{'w', 623},
{'a', 19},
{'use_move', 1},
{'a', 15},
{'rf', 15},
{'use_move', 1},
{'a', 15},
{'lf', 15},
{'use_move', 1},
{'w', 180},
{'r', 2},
{'w', 60},
{'u', 3},
{'l', 13},
{'d', 3},
{'r', 4},
{'d', 3},
{'r', 1},
{'a', 19},
{'w', 161},
{'b', 12},
{'w', 238},
{'b', 14},
{'w', 425},
{'b', 19},
{'w', 401},
{'a', 16},
{'w', 49},
{'r', 1},
{'use_move', 1},
{'a', 15},
{'lf', 15},
{'use_move', 1},
{'w', 60},
{'r', 2}, -- readjust direction
{'w', 60},
{'d', 3},
{'l', 2},
{'d', 1},
{'w', 40},
{'a', 14},
{'w', 92},
{'b', 18},
{'w', 127},
{'b', 11},
{'w', 432},
{'a', 15},
{'w', 440},
{'a', 15},
{'rf', 15},
{'use_move', 2},
{'press_b', 4},
{'l', 2},
{'d', 4},
{'r', 2},
{'d', 2},
{'r', 6},
{'d', 1},
{'w', 60},
{'a', 13},
{'w', 134},
{'b', 19},
{'w', 124},
{'b', 12},
{'w', 130},
{'b', 19},
{'w', 117},
{'b', 15},
{'w', 135},
{'b', 14},
{'w', 125},
{'b', 12},
{'w', 464},
{'b', 24},
{'w', 411},
{'a', 13}, -- fight koga
{'use_move', 4},
{'press_b', 7},
{'l', 7},
{'u', 7},
{'r', 3},
{'u', 3},
{'r', 4},
{'l', 6},
{'u', 3},
{'r', 14},
{'d', 17},
{'l', 8},
{'d', 5}, -- leave gym
--mapChange
{'w', 180},
-- fuschia-2
{'d', 3}, -- go to safari
{'l', 7},
{'u', 13},
{'r', 25},
{'u', 8},
{'r', 9},
{'d', 2},
{'r', 8},
{'u', 8},
{'l', 7},
{'d', 2},
{'l', 7},
{'u', 2},
{'w', 30},
{'a', 15},
{'w', 53},
{'a', 22},
{'w', 58},
{'a', 27},
{'w', 45},
{'a', 23},
{'w', 182},
{'u', 5},
{'l', 7},
{'u', 2},
--mapChange
{'w', 180},
{'u', 4},
{'w', 196},
{'b', 16},
{'w', 118},
{'b', 22},
{'w', 106},
{'b', 21},
{'w', 155},
{'a', 20},
{'w', 180},
{'b', 42},
{'w', 68},
{'b', 24},
{'w', 89},
{'b', 48},
{'w', 66},
{'b', 40},
{'w', 56},
{'b', 35},
--mapChange
{'w', 540}, -- enter the safari
{'u', 1},
{'w', 233},
{'r', 17},
{'u', 15},
{'w', 21}, 
--mapChange
{'r', 4},
{'w', 180},
{'w', 221},
{'r', 9},
{'d', 4},
{'r', 13},
{'w', 104},
{'s', 16},
{'w', 176},
{'d', 1},
{'w', 45},
{'a', 15},
{'w', 459},
{'u', 2},
{'w', 84},
{'a', 16},
{'w', 53},
{'a', 19},
{'w', 253},
{'b', 22},
{'w', 65},
{'b', 16},
{'w', 61},
{'b', 26},
{'w', 90},
{'w', 275},
{'r', 7},
{'w', 58},
{'u', 7},
{'w', 70},
{'l', 8},
{'w', 37},
{'d', 4},
{'w', 34},
{'l', 6},
{'w', 27},
{'u', 14},
{'u', 2},
{'r', 8},
{'d', 2},
{'d', 1},
{'r', 4},
{'r', 1},
{'u', 6},
{'l', 17},
{'d', 2},
{'l', 14},
{'w', 180},
--mapChange
{'w', 170},
{'l', 9},
{'w', 196},
{'b', 31},
{'w', 20},
{'l', 2},
{'w', 76},
{'s', 8},
{'w', 100},
{'a', 18},
{'w', 175},
{'a', 23},
{'w', 59},
{'a', 22},
{'w', 167},
{'b', 22},
{'w', 57},
{'b', 22},
{'w', 53},
{'b', 33},
{'w', 171},
{'l', 8},
{'w', 54},
{'u', 7},
{'w', 49},
{'r', 2},
{'w', 44},
{'u', 3},
{'w', 43},
{'l', 6},
{'w', 50},
{'d', 6},
{'w', 42},
{'l', 4},
{'w', 43},
{'u', 18},
{'w', 44},
{'r', 13},
{'w', 31},
{'u', 6},
{'w', 34},
{'l', 24},
{'w', 32},
{'d', 7},
{'w', 24},
{'r', 2},
{'w', 27},
{'d', 4},
{'w', 40},
{'l', 1},
{'w', 30},
{'d', 10},
{'w', 44},
{'d', 9},
{'w', 51},
{'l', 2},
{'w', 55},
{'d', 4},
--mapChange
{'w', 180},
{'d', 9},
{'l', 3},
{'w', 23},
{'a', 18}, -- get gold teeth
{'w', 191},
{'b', 28},
{'w', 48},
{'l', 2},
{'w', 24},
{'u', 4},
{'w', 24},
{'l', 17},
{'w', 32},
{'u', 3},
{'r', 2},
{'w', 21},
{'u', 4},
--mapChange
{'w', 180},
{'r', 3},
{'u', 4},
{'w', 60},
{'a', 20},
{'w', 109},
{'press_b', 20}, -- get strength HM
{'s', 13},
{'w', 60},
{'u', 3},
{'w', 64},
{'a', 20},
{'w', 60},
{'a', 18},
--mapChange
{'w', 293},
{'b', 14},
{'w', 148},
--mapChange
{'d', 5}, -- leave safari
{'w', 180},
-- fuschia-3
{'w', 90},
{'d', 3}, -- go to wardens house
{'l', 5},
{'d', 3},
{'r', 2},
{'d', 2},
{'w', 30},
{'a', 17},
{'w', 72},
{'a', 17},
{'w', 114},
{'a', 7},
{'w', 155},
{'a', 17},
{'w', 201},
{'d', 5},
{'w', 37},
{'r', 4},
{'w', 40},
{'d', 5},
{'w', 64},
{'a', 13},
{'w', 69},
{'a', 18},
{'w', 67},
{'a', 19},
{'w', 46},
{'a', 21},
{'w', 188},
{'d', 4},
{'r', 7},
{'d', 9},
{'u', 2},
{'r', 4},
{'u', 3}, -- enter wardens house
--mapChange
{'w', 187},
{'u', 3},
{'l', 3},
{'u', 2},
{'l', 1},
{'w', 52},
{'a', 20}, -- giff him his teeth
{'w', 89},
{'a', 27},
{'w', 197},
{'press_b', 10},
{'w', 180}, -- teach lapras strength
{'w', 178},
{'s', 15}, -- we're on pokedex from retiring at safari
{'w', 140},
{'d', 2},
{'w', 31},
{'a', 20},
{'w', 140},
{'r', 1},
{'w', 70},
{'a', 22},
{'w', 45},
{'a', 23},
{'w', 91},
{'a', 25},
{'w', 61},
{'a', 19},
{'w', 261},
{'l', 2}, -- readjust for unknown reason (opens on jolteon/charizard)
-- unexplained issue: when opening the pokemon menu
-- from the TM screen, in one scenario it opens on jolteon
-- and the other with the cursor on charizard
-- not sure why, the only difference between the two
-- is the current XP of Jolteon.  Levels are all the same
-- initial conditions are the same except for the Jolteon XP
{'d', 4},
{'w', 79},
{'a', 22},
{'w', 101},
{'a', 29},
{'w', 93},
{'a', 28},
{'w', 155},
{'a', 20},
{'w', 86},
{'a', 20},
{'w', 265},
{'d', 2},
{'w', 253},
{'a', 30},
{'w', 235},
{'a', 33},
{'w', 67},
{'a', 31},
{'w', 52},
{'a', 30},
{'w', 74},
{'a', 28},
{'w', 363},
{'press_b', 6}, -- done teaching lapras strength
{'w', 90},
{'s', 11}, -- teach gyarados surf
{'w', 149},
{'a', 15},
{'w', 148},
{'a', 19},
{'w', 36},
{'a', 16},
{'w', 157},
{'u', 1},
{'w', 34},
{'a', 17},
{'w', 68},
{'a', 14},
{'w', 180},
{'u', 1},
{'w', 56},
{'a', 15},
{'w', 76},
{'a', 28},
{'w', 76},
{'a', 22},
{'w', 81},
{'a', 18},
{'w', 84},
{'a', 17},
{'w', 299},
{'d', 1},
{'w', 221},
{'a', 21},
{'w', 302},
{'a', 28},
{'w', 66},
{'a', 25},
{'w', 68},
{'a', 40},
{'w', 59},
{'a', 33},
{'w', 344},
{'press_b', 5}, -- done teaching gyarados surf
{'w', 90},
{'d', 3}, -- go get the rare candy
{'r', 9},
{'u', 2},
{'l', 1},
{'w', 56},
{'a', 16},
{'w', 66},
{'a', 26},
{'w', 68},
{'a', 23},
{'w', 239},
{'b', 28},
{'w', 32},
{'b', 34},
{'w', 46},
{'b', 23},
{'w', 85},
{'l', 1},
{'w', 106},
{'l', 1},
{'w', 51},
{'u', 1},
{'w', 53},
{'a', 19},
{'w', 65},
{'a', 21},
{'w', 73},
{'a', 24},
{'w', 90}, -- rare candy acquired
{'d', 3}, -- leave warden's house
{'l', 6},
{'d', 3},
--mapChange
{'w', 180},
{'l', 4},
{'w', 41},
{'u', 8},
{'w', 29},
{'l', 28},
{'w', 29},
{'d', 12},
{'w', 23},
{'r', 8},
{'w', 21},
{'u', 4},
{'w', 23},
{'r', 16},
{'w', 50},
{'u', 4}, -- into pokecenter
--mapChange
{'w', 180},
{'u', 6},
{'w', 30}, 
{'pokecenter_heal', 1},
{'d', 7}, -- leave pokecenter
{'w', 180}, 
-- fuschia-4
}

b = {
    {'w', 90},
    {'d', 3}, -- go to wardens house
    {'l', 5},
    {'d', 3},
    {'r', 2},
    {'d', 2},
    {'w', 30},
    {'a', 17},
    {'w', 72},
    {'a', 17},
    {'w', 114},
    {'a', 7},
    {'w', 155},
    {'a', 17},
    {'w', 201},
    {'d', 5},
    {'w', 37},
    {'r', 4},
    {'w', 40},
    {'d', 5},
    {'w', 64},
    {'a', 13},
    {'w', 69},
    {'a', 18},
    {'w', 67},
    {'a', 19},
    {'w', 46},
    {'a', 21},
    {'w', 188},
    {'d', 4},
    {'r', 7},
    {'d', 9},
    {'u', 2},
    {'r', 4},
    {'u', 3}, -- enter wardens house
    --mapChange
    {'w', 187},
    {'u', 3},
    {'l', 3},
    {'u', 2},
    {'l', 1},
    {'w', 52},
    {'a', 20}, -- giff him his teeth
    {'w', 89},
    {'a', 27},
    {'w', 197},
    {'press_b', 10},
    {'w', 180}, -- teach lapras strength
    {'w', 178},
    {'s', 15}, -- we're on pokedex from retiring at safari
    {'w', 140},
    {'d', 2},
    {'w', 31},
    {'a', 20},
    {'w', 140},
    {'r', 1},
    {'w', 70},
    {'a', 22},
    {'w', 45},
    {'a', 23},
    {'w', 91},
    {'a', 25},
    {'w', 61},
    {'a', 19},
    {'w', 261},
    {'l', 2}, -- readjust for unknown reason (opens on jolteon/charizard)
    -- unexplained issue: when opening the pokemon menu
    -- from the TM screen, in one scenario it opens on jolteon
    -- and the other with the cursor on charizard
    -- not sure why, the only difference between the two
    -- is the current XP of Jolteon.  Levels are all the same
    -- initial conditions are the same except for the Jolteon XP
    {'d', 4},
    {'w', 79},
    {'a', 22},
    {'w', 101},
    {'a', 29},
    {'w', 93},
    {'a', 28},
    {'w', 155},
    {'a', 20},
    {'w', 86},
    {'a', 20},
    {'w', 265},
    {'d', 2},
    {'w', 253},
    {'a', 30},
    {'w', 235},
    {'a', 33},
    {'w', 67},
    {'a', 31},
    {'w', 52},
    {'a', 30},
    {'w', 74},
    {'a', 28},
    {'w', 363},
    {'press_b', 6}, -- done teaching lapras strength
    {'w', 90},
    {'s', 11}, -- teach gyarados surf
    {'w', 149},
    {'a', 15},
    {'w', 148},
    {'a', 19},
    {'w', 36},
    {'a', 16},
    {'w', 157},
    {'u', 1},
    {'w', 34},
    {'a', 17},
    {'w', 68},
    {'a', 14},
    {'w', 180},
    {'u', 1},
    {'w', 56},
    {'a', 15},
    {'w', 76},
    {'a', 28},
    {'w', 76},
    {'a', 22},
    {'w', 81},
    {'a', 18},
    {'w', 84},
    {'a', 17},
    {'w', 299},
    {'d', 1},
    {'w', 221},
    {'a', 21},
    {'w', 302},
    {'a', 28},
    {'w', 66},
    {'a', 25},
    {'w', 68},
    {'a', 40},
    {'w', 59},
    {'a', 33},
    {'w', 344},
    {'press_b', 5}, -- done teaching gyarados surf
    {'w', 90},
    {'d', 3}, -- go get the rare candy
    {'r', 9},
    {'u', 2},
    {'l', 1},
    {'w', 56},
    {'a', 16},
    {'w', 66},
    {'a', 26},
    {'w', 68},
    {'a', 23},
    {'w', 239},
    {'b', 28},
    {'w', 32},
    {'b', 34},
    {'w', 46},
    {'b', 23},
    {'w', 85},
    {'l', 1},
    {'w', 106},
    {'l', 1},
    {'w', 51},
    {'u', 1},
    {'w', 53},
    {'a', 19},
    {'w', 65},
    {'a', 21},
    {'w', 73},
    {'a', 24},
    {'w', 90}, -- rare candy acquired
    {'d', 3}, -- leave warden's house
    {'l', 6},
    {'d', 3},
    --mapChange
    {'w', 180},
    {'l', 4},
    {'w', 41},
    {'u', 8},
    {'w', 29},
    {'l', 28},
    {'w', 29},
    {'d', 12},
    {'w', 23},
    {'r', 8},
    {'w', 21},
    {'u', 4},
    {'w', 23},
    {'r', 16},
    {'w', 50},
    {'u', 4}, -- into pokecenter
    --mapChange
    {'w', 180},
    {'u', 6},
    {'w', 30}, 
    {'pokecenter_heal', 1},
    {'d', 7}, -- leave pokecenter
    {'w', 180}, 
    -- fuschia-4

}

m.executeOrders(start6)

local info = debug.getinfo(1, "S")
local folderName = info.what
local nextScript = num + 1 
savestate.save(string.format("./States/Gym%dFinished.State", num))
print(string.format("You beat Koga! Making savestate: '%s/States/Gym%dFinished.State'. To continue from here load the state and run %d.lua.", folderName, num, nextScript))