Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <string.h>
- #include <algorithm>
- const enum Requires
- {
- REQUIRE_GOLDEN,
- REQUIRE_CLOCKS
- };
- const enum Verbosity
- {
- QUIET,
- VERBOSE
- };
- const enum Eras
- {
- NOWHERE,
- STONE,
- MEDIEVAL,
- PIRATE,
- THIRTIES,
- SPACE
- };
- struct Level
- {
- char* LevelName;
- char LevelNameFiller[31];
- int Era;
- int Clocks;
- int GoldenCarrots;
- int RequireCount;
- bool RequireClocks;
- bool RequireSpellJump;
- bool RequireSpellMusic;
- bool RequireSpellFan;
- bool RequireSpellPassword;
- bool ObtainSpellJump;
- bool ObtainSpellMusic;
- bool ObtainSpellFan;
- bool ObtainSpellPassword;
- Level(char* _n, int _e, int _c, int _gc, int _r, bool _rc,
- bool _rsj, bool _rsm, bool _rsf, bool _rsp,
- bool _gsj, bool _gsm, bool _gsf, bool _gsp )
- : LevelName(_n), Era (_e), Clocks(_c), GoldenCarrots(_gc), RequireCount(_r), RequireClocks(_rc),
- RequireSpellJump(_rsj), RequireSpellMusic(_rsm), RequireSpellFan(_rsf), RequireSpellPassword(_rsp),
- ObtainSpellJump(_gsj), ObtainSpellMusic(_gsm), ObtainSpellFan(_gsf), ObtainSpellPassword(_gsp){};
- };
- struct Route
- {
- Level* routeOrder[27];
- int routeSize;
- int Clocks;
- int GoldenCarrots;
- int TotalRate;
- bool SpellJump;
- bool SpellMusic;
- bool SpellFan;
- bool SpellPassword;
- //add level to route
- void AddLevel(Level* _l)
- {
- routeOrder[routeSize++] = _l;
- Clocks += _l->Clocks;
- GoldenCarrots += _l->GoldenCarrots;
- SpellJump = _l->ObtainSpellJump ? true : SpellJump;
- SpellMusic = _l->ObtainSpellMusic ? true : SpellMusic;
- SpellFan = _l->ObtainSpellFan ? true : SpellFan;
- SpellPassword = _l->ObtainSpellPassword ? true : SpellPassword;
- }
- //check if level can be added to route
- bool CheckLevelPossible(Level* _l)
- {
- //check level not already done
- for(int i=0; i<routeSize; ++i)
- {
- if(routeOrder[i] == _l) return false;
- }
- //check required amount of clocks/GCs
- if(Clocks < _l->RequireCount && _l->RequireClocks == REQUIRE_CLOCKS) return false;
- if(GoldenCarrots < _l->RequireCount && _l->RequireClocks == REQUIRE_GOLDEN) return false;
- //check required spells
- if(!SpellJump && _l->RequireSpellJump) return false;
- if(!SpellMusic && _l->RequireSpellMusic) return false;
- if(!SpellFan && _l->RequireSpellFan) return false;
- if(!SpellPassword && _l->RequireSpellPassword) return false;
- return true;
- }
- //Returns a number, weighing the 'distance' between two levels.
- //Levels in the same era return less, further away eras return higher numbers.
- int CalcRoutePreference(Level* _level1, Level* _level2)
- {
- int val = 5;
- //get era distance between two levels
- int EraDiff = _level1->Era - _level2->Era;
- {
- if(EraDiff > 3) EraDiff -= 6;
- if(EraDiff < -3) EraDiff += 6;
- if(EraDiff < 0) EraDiff *= -1;
- }
- //if second level is in a different era, add value
- if(EraDiff != 0)
- {
- val += 10 + EraDiff;
- }
- return val;
- }
- };
- //first visit The Greatest Escape: 5/6 clocks, 13/15 GCs
- //
- //first visit What's Cookin Doc:
- //clocks: 9: prison, prison>key, forest hidden area, merlin's house, spinning tower cage, lava section, lava section, lava section, bossfight
- //gcs: mainland: 8: prison guard, prison>key, overworld guard, above water, above water, water cage, waterfall, overworld knight
- //gcs: forest: 7: daffy hood, tree, tree, tree, forest near river, merlin's house, jump on witch hazel
- //castle: 7: spinning tower, cannonball puzzle, castle walls, lava section, lava section knight, lava section knight, lava section endpoint knight
- //...and two others
- //
- //total: 9 clocks 24 GCs
- //
- //second visit What's Cookin Doc:
- //
- //first 99 carrots by The Greatest Escape 1
- Level levels[] = {
- // Name Era Cl, GC, Req.,Req. what, req.jump/music/fan/passwrd, get jump/music/fan/passwrd
- Level("Nowhere" , NOWHERE , 1 , 10, 0 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //0
- Level("Wabbit on the Run" , STONE , 9 , 22, 1 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //1
- Level("Guess Who Needs a Kick Start" , STONE , 1 , 5 , 5 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //2
- Level("Wabbit or Duck Season" , STONE , 1 , 0 , 50 , REQUIRE_GOLDEN, false, false, false, false, false, false, false, false), //3
- Level("Magic Hare Blower" , STONE , 14, 31, 80 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //4
- Level("Hey, What's Up, Doc?" , PIRATE , 9 , 17, 5 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //5
- Level("Follow the Red Pirate Road 1" , PIRATE , 3 , 3 , 11 , REQUIRE_CLOCKS, true , false, false, false, false, false, false, false), //6
- Level("Follow the Red Pirate Road 2" , PIRATE , 1 , 6 , 11 , REQUIRE_CLOCKS, true , false, false, true , false, false, false, false), //7
- Level("When Sam met Bunny" , PIRATE , 1 , 2 , 35 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //8
- Level("Mine or Mine?" , PIRATE , 10, 41, 100, REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //9
- Level("The Big Bank Withdrawal" , THIRTIES, 6 , 15, 15 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //10
- Level("The Greatest Escape 1" , THIRTIES, 5 , 13, 25 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //11
- Level("The Greatest Escape 2" , THIRTIES, 1 , 2 , 25 , REQUIRE_CLOCKS, true , false, false, false, false, false, false, false), //12
- Level("Objects in the mirror..." , THIRTIES, 4 , 15, 50 , REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //13
- Level("La Corrida" , THIRTIES, 1 , 5 , 150, REQUIRE_GOLDEN, false, false, false, false, false, false, false, false), //14
- Level("The Carrot Factory" , THIRTIES, 8 , 15, 90, REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //15
- Level("What's Cookin', doc? 1" , MEDIEVAL, 9 , 24, 30, REQUIRE_CLOCKS, false, false, false, false, true , false, false, false), //16
- Level("What's Cookin', doc? 2" , MEDIEVAL, 4 , 12, 30, REQUIRE_CLOCKS, false, true , false, false, true , false, false, false), //17
- Level("What's Cookin', doc? 3" , MEDIEVAL, 2 , 1 , 30, REQUIRE_CLOCKS, false, false, true , false, true , false, false, false), //18
- Level("Witch Way to Albuquerque?" , MEDIEVAL, 1 , 8 , 65, REQUIRE_CLOCKS, false, false, false, false, false, true , false, false), //19
- Level("The Carrot-Henge Mystery" , MEDIEVAL, 8 , 20, 73, REQUIRE_CLOCKS, false, false, false, false, false, false, true , true ), //20
- Level("Downhill Duck" , MEDIEVAL, 1 , 0 , 250, REQUIRE_GOLDEN, false, false, false, false, false, false, false, false), //21
- Level("The Planet X File" , SPACE , 14, 26, 40, REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //22
- Level("Vort X Room" , SPACE , 4 , 0 , 60, REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //23
- Level("The Conquest of Planet X" , SPACE , 1 , 14, 70, REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //24
- Level("Train Your Brain" , SPACE , 5 , 21, 117, REQUIRE_CLOCKS, false, false, false, false, false, false, false, false), //25
- Level("END" , NOWHERE , 0 , 5, 124, REQUIRE_CLOCKS, true , true , true , true , false, false, false, false) //26
- };
- /*
- LEVEL IDS:
- 0 - Nowhere
- 1 - Wabbit on the Run
- 2 - Guess Who Needs a Kick Start
- 3 - Wabbit or Duck Season
- 4 - Magic Hare Blower
- 5 - Hey, What's Up, Doc?
- 6 - Follow the Red Pirate Road 1
- 7 - Follow the Red Pirate Road 2
- 8 - When Sam met Bunny
- 9 - Mine or Mine?
- 10 - The Big Bank Withdrawal
- 11 - The Greatest Escape 1
- 12 - The Greatest Escape 2
- 13 - Objects in the mirror...
- 14 - La Corrida
- 15 - The Carrot Factory
- 16 - What's Cookin', doc? 1
- 17 - What's Cookin', doc? 2
- 18 - What's Cookin', doc? 3
- 19 - Witch Way to Albuquerque?
- 20 - The Carrot-Henge Mystery
- 21 - Downhill Duck
- 22 - The Planet X File
- 23 - Vort X Room
- 24 - The Conquest of Planet X
- 25 - Train Your Brain
- 26 - END
- */
- //Array used for random numbers
- int Random27Array[27] =
- {
- 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26
- };
- void SetArray(int _Array[27])
- {
- for(int i=0; i<27; ++i)
- {
- _Array[i] = i;
- }
- }
- void RandomizeArray(int _Array[27])
- {
- std::random_shuffle(_Array, _Array + 27);
- }
- int GlobalEraDiffRates[27][27]; //precalculated
- //Calculate a route that finishes the game using a random seed.
- int CalculateRandomRoute(int seed, bool verbose = false)
- {
- srand(seed);
- SetArray(Random27Array);
- RandomizeArray(Random27Array);
- Route r = Route();
- r.AddLevel(&levels[0]);
- if(verbose) printf("ROUTE: 00 %s (%d, %d) (rating: %d)\n", r.routeOrder[r.routeSize-1]->LevelName, r.Clocks, r.GoldenCarrots, 0);
- int EraDiffRates[27];
- int lastID = 0;
- while(r.routeSize < 27)
- {
- memset(EraDiffRates, -1, sizeof(EraDiffRates));
- for(int i=0; i<27; ++i)
- {
- if(r.CheckLevelPossible(&levels[i]))
- {
- EraDiffRates[i] = GlobalEraDiffRates[lastID][i];
- }
- }
- int LowestRate = -1;
- int id = -1;
- if(r.routeSize <= 5)
- {
- //the first 6 stages have to be in order
- //(done to speed up route calculations)
- if(r.routeSize == 1)
- {
- id = 1;
- }
- else if(r.routeSize == 2)
- {
- id = 2;
- }
- else if(r.routeSize == 3)
- {
- id = 5;
- }
- else if(r.routeSize == 4)
- {
- id = 10;
- }
- else if(r.routeSize == 5)
- {
- id = 11;
- }
- }
- else
- {
- for(int i=0; i<27; ++i)
- {
- if(EraDiffRates[Random27Array[i]] > 0)
- {
- id = Random27Array[i];
- break;
- }
- }
- if(id == -1)
- {
- printf("ERROR: Route not possible.\n");
- return 999;
- }
- }
- LowestRate = EraDiffRates[id];
- r.AddLevel(&levels[id]);
- r.TotalRate += LowestRate;
- if(LowestRate > 5)
- {
- if(verbose)
- printf("\n");
- }
- if(verbose)
- printf("ROUTE: %.2d %s (%d, %d) (rating: %d)\n", id, r.routeOrder[r.routeSize-1]->LevelName, r.Clocks, r.GoldenCarrots, LowestRate);
- lastID = id;
- }
- if(verbose)
- printf("ROUTE: Total rate: %d", r.TotalRate);
- return r.TotalRate;
- }
- //Calculate route using a preset array as a route order.
- int CalculatePresetRoute(int _r[27], bool verbose = false)
- {
- Route r = Route();
- for(int i = 0; i < 27; ++i)
- {
- if(r.CheckLevelPossible(&levels[_r[i]]) == false)
- {
- if(verbose)
- printf("ERROR: Route not possible. ");
- return -1;
- }
- r.AddLevel(&levels[_r[i]]);
- int rating = 0;
- if(i > 0)
- {
- rating = r.CalcRoutePreference(r.routeOrder[r.routeSize-2], &levels[_r[i]]);
- r.TotalRate += rating;
- }
- if(rating > 5)
- {
- if(verbose) printf("\n");
- }
- if(verbose) printf("ROUTE: %.2d %s (%d, %d) (rating: %d)\n", _r[i], r.routeOrder[r.routeSize-1]->LevelName, r.Clocks, r.GoldenCarrots, rating);
- }
- if(verbose) printf("ROUTE: Total rate: %d", r.TotalRate);
- return r.TotalRate;
- }
- /*
- LEVEL IDS:
- 0 - Nowhere
- 1 - Wabbit on the Run
- 2 - Guess Who Needs a Kick Start
- 3 - Wabbit or Duck Season
- 4 - Magic Hare Blower
- 5 - Hey, What's Up, Doc?
- 6 - Follow the Red Pirate Road 1
- 7 - Follow the Red Pirate Road 2
- 8 - When Sam met Bunny
- 9 - Mine or Mine?
- 10 - The Big Bank Withdrawal
- 11 - The Greatest Escape 1
- 12 - The Greatest Escape 2
- 13 - Objects in the mirror...
- 14 - La Corrida
- 15 - The Carrot Factory
- 16 - What's Cookin', doc? 1
- 17 - What's Cookin', doc? 2
- 18 - What's Cookin', doc? 3
- 19 - Witch Way to Albuquerque?
- 20 - The Carrot-Henge Mystery
- 21 - Downhill Duck
- 22 - The Planet X File
- 23 - Vort X Room
- 24 - The Conquest of Planet X
- 25 - Train Your Brain
- 26 - END
- */
- //Array used for calculating a preset route
- int PresetRouteArray[27] =
- {
- 0, 1, 2, 5, 10, 11, 16, 6, 8, 22, 12, 13, 14, 23, 19, 17, 20, 18, 3, 4, 15, 9, 7, 21, 24, 25, 26
- };
- //Amount of random tries
- long long iterations = 99999;
- int main()
- {
- {
- //Precalculate all combinations of level transition/'distance' values
- Route t;
- for(int x=0; x<27; ++x)
- {
- for(int y=0; y<27; ++y)
- {
- GlobalEraDiffRates[x][y] = t.CalcRoutePreference(&levels[y],&levels[x]);
- }
- }
- }
- /*
- int lowest = 999;
- int topseed = 0;
- //Find fastest route after [iterations] amount of random tries
- for(int i=0; i<iterations; ++i)
- {
- int l = CalculateRandomRoute(i);
- if(l <= lowest && l > 0)
- {
- lowest = l;
- topseed = i;
- printf("Route seed %d gets rate %d\n", i, l);
- }
- }
- printf("Done.\n\n\n");
- //Display fastest found route
- CalculateRandomRoute(topseed, VERBOSE);
- //*/
- //First random seed to return fastest route on my rig
- //Fastest route found so far should have a length of 304
- //CalculateRandomRoute(139490435, VERBOSE);
- //Calculate and display preset route
- CalculatePresetRoute(PresetRouteArray, VERBOSE);
- getchar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement