Advertisement
Kirkq

DQ3Simulator v5

Mar 6th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 11.08 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. #include <stdio.h>
  4. #include <time.h>
  5. #include <math.h>
  6. #include <windows.h>
  7. #include <unistd.h>
  8. using namespace std;
  9.  
  10. #define FIELD 256
  11. #define ICE 256
  12. #define DESERT 384
  13. #define FOREST 460
  14. #define SWAMP 460
  15. #define MOUNTAIN 640
  16.  
  17. int ec;
  18.  
  19. //Add lamp of darkness later.
  20.  
  21. typedef enum PathType
  22. {
  23.     PATH_STANDARD = 0,
  24.     PATH_ALTERNATE = 1
  25. } PathType;
  26.  
  27.  
  28. #define ASSERT printf("ASSERT %d\n", __LINE__);cout << "To close type something and hit enter: ";cin >> dumpchar;exit(-1);
  29. //0 to 12288
  30. #define EC_ARRAY_SIZE (49)
  31. #define EC_SAMPLE_SIZE (32768)
  32. #define MAX_NUM_TILES (200)
  33.  
  34. #define ALIAHAN_ENCOUNTER (60 * 15 + 0)  //In frames
  35. #define MAGIC_BALL_ENCOUNTER (60 * 20 + 0)  //In frames
  36. #define ALIAHAN_ALT_PATH_STATIC_TIME (278)  //In frames
  37. #define MAGIC_BALL_ALT_PATH_STATIC_TIME (273)  //In frames
  38. #define OUTDOOR_STEP_TIME (16)  //In frames
  39. #define STEP_TIME (OUTDOOR_STEP_TIME)  //In frames
  40.  
  41. #define ALIAHAN_TEST
  42. //#define MAGIC_BALL_TEST
  43.  
  44. //#define DEBUG
  45.  
  46. static int SpreadArray[EC_ARRAY_SIZE] =
  47. {  9, 9, 42, 69, 105, 171, 208, 253, 317, 362,
  48. 456, 533, 613, 685, 780, 936, 1032, 1065, 1220, 1245,
  49. 1378, 1359, 1462, 1449, 1454, 1351, 1343, 1380, 1401, 1277,
  50. 1220, 1126, 996, 908, 793, 716, 615, 528, 443, 390,
  51. 279, 240, 167, 142, 106, 64, 46, 20, 5};
  52. int ECArray[EC_SAMPLE_SIZE];
  53. int dumpchar;
  54.  
  55. bool use_static_encounter_time = false;
  56. int static_encounter_time = 0;
  57. int static_encounter_tile_num = -2;
  58.  
  59. class Tile
  60. {
  61.     public:
  62.         int ec_decrement;
  63.         int encounter_time_loss;
  64.         int tile_num;
  65.         bool make_break_decision;
  66.         Tile();
  67. };
  68. Tile::Tile(void)
  69. {
  70.     ec_decrement = 0;
  71.     encounter_time_loss = 0;
  72.     tile_num = 0;
  73.     make_break_decision = false;
  74. }
  75. void initTile (Tile &Tile, int type, int enc)
  76. {
  77.     Tile.ec_decrement = type;
  78.     Tile.encounter_time_loss = enc;
  79. }
  80.  
  81. Tile TileArray[MAX_NUM_TILES];
  82. Tile TileArrayAlt[MAX_NUM_TILES];   //Tile break attaches to TileArrayAlt[0];
  83. int NumSteps = 0;
  84. int NumAltSteps = 0;
  85. int AltPathTime = 0;
  86.  
  87. void SetupAllTiles()
  88. {
  89.     for(int i = 0; i<MAX_NUM_TILES; i++)
  90.     {
  91.         TileArray[i].tile_num = i;
  92.         TileArrayAlt[i].tile_num = i;
  93.     }
  94.  
  95. #ifdef ALIAHAN_TEST
  96. //Aliahan to Reeve
  97.     //Sweetspot seems to be 12-13 tiles in with 15s encounters.
  98.     int k = 0;
  99.     //The first tile is the first enemy tile
  100.     //The last tile is the last enemy tile (one step from destination)
  101.  
  102.     //MAIN_PATH
  103.     for(int i = 0; i<21; i++)
  104.     {
  105.         initTile(TileArray[k++], FIELD, ALIAHAN_ENCOUNTER);
  106.     }
  107.     for(int i = 0; i<12; i++)
  108.     {
  109.         if(i == 8)
  110.         {
  111.             TileArray[k].make_break_decision = true;
  112.         }
  113.         initTile(TileArray[k++], FOREST, ALIAHAN_ENCOUNTER);
  114.     }
  115.     for(int i = 0; i<4; i++)
  116.     {
  117.         initTile(TileArray[k++], FIELD, ALIAHAN_ENCOUNTER);
  118.     }
  119.     NumSteps = k;
  120.  
  121.     //ALT_PATH
  122.     k = 0;
  123.     for(int i = 0; i<2; i++)
  124.     {
  125.         initTile(TileArrayAlt[k++], FOREST, ALIAHAN_ENCOUNTER);
  126.     }
  127.     NumAltSteps = k;
  128.     AltPathTime = ALIAHAN_ALT_PATH_STATIC_TIME;
  129. #endif
  130. #ifdef MAGIC_BALL_TEST
  131.     //Reeve to Magic Ball Cave
  132.     int k = 0;
  133.     //The first tile is the first enemy tile
  134.     //The last tile is the last enemy tile (one step from destination)
  135.  
  136.     //MAIN_PATH
  137.     for(int i = 0; i<21; i++)
  138.     {
  139.         initTile(TileArray[k++], FIELD, MAGIC_BALL_ENCOUNTER);
  140.     }
  141.     for(int i = 0; i<3; i++)
  142.     {
  143.         initTile(TileArray[k++], FOREST, MAGIC_BALL_ENCOUNTER);
  144.     }
  145.     for(int i = 0; i<1; i++)
  146.     {
  147.         initTile(TileArray[k++], MOUNTAIN, MAGIC_BALL_ENCOUNTER);
  148.     }
  149.     for(int i = 0; i<3; i++)
  150.     {
  151.         initTile(TileArray[k++], FOREST, MAGIC_BALL_ENCOUNTER);
  152.     }
  153.     //Right about here is where your "last encounter" can start.  Tile 28 is the last forest tile.
  154.     for(int i = 0; i<9; i++)
  155.     {
  156.         initTile(TileArray[k++], MOUNTAIN, MAGIC_BALL_ENCOUNTER);
  157.     }
  158.     for(int i = 0; i<3; i++)
  159.     {
  160.         initTile(TileArray[k++], FOREST, MAGIC_BALL_ENCOUNTER);
  161.     }
  162.     for(int i = 0; i<7; i++)
  163.     {
  164.         initTile(TileArray[k++], MOUNTAIN, MAGIC_BALL_ENCOUNTER);
  165.     }
  166.     for(int i = 0; i<2; i++)
  167.     {
  168.         if(i == 0)
  169.         {
  170.             TileArray[k].make_break_decision = true;
  171.         }
  172.         initTile(TileArray[k++], FIELD, MAGIC_BALL_ENCOUNTER);
  173.     }
  174.     for(int i = 0; i<3; i++)
  175.     {
  176.         initTile(TileArray[k++], DESERT, MAGIC_BALL_ENCOUNTER);
  177.     }
  178.     NumSteps = k;
  179.  
  180.     //ALT_PATH
  181.     k = 0;
  182.     for(int i = 0; i<1; i++)
  183.     {
  184.         initTile(TileArrayAlt[k++], FIELD, MAGIC_BALL_ENCOUNTER);
  185.     }
  186.     NumAltSteps = k;
  187.     AltPathTime = MAGIC_BALL_ALT_PATH_STATIC_TIME;
  188. #endif
  189.  
  190.  
  191. }
  192.  
  193. void InitArrays()
  194. {
  195.     int k;
  196.     for(int i = 0; i<EC_ARRAY_SIZE; i++)
  197.     {
  198.         for(int j = 0; j < SpreadArray[i]; j++)
  199.         {
  200.             if(k >= EC_SAMPLE_SIZE)
  201.             {
  202.                 ASSERT;
  203.             }
  204.             ECArray[k++] = i*256;
  205.         }
  206.     }
  207.     //Sanity checks
  208.     if(k != EC_SAMPLE_SIZE || ECArray[0] != 0 || ECArray[EC_SAMPLE_SIZE-1] != 12288)
  209.     {
  210.         ASSERT;
  211.     }
  212.  
  213. #ifdef DEBUG
  214.     for(int i = 0; i<100; i++)
  215.     {
  216.         printf("ECArray[i] = %d\n", ECArray[i]);
  217.     }
  218. #endif
  219. }
  220.  
  221. int GetRandomEC()
  222. {
  223.     int ret = ECArray[rand() % EC_SAMPLE_SIZE];
  224.  
  225.     return ret;
  226. }
  227.  
  228. int Simulate(void)
  229. {
  230.     int last_encounter_tile = -1;
  231.     int ec = GetRandomEC(); //Start
  232.     bool alt_path_taken = false;
  233.     bool printenable = false;
  234.     int time = 0;
  235.     int num_encounters = 0;
  236.    
  237.     //if(ec > 4000) //HACK TEST
  238.     //{
  239.     //    return 0;
  240.     //}
  241.  
  242. //
  243.     ////0 to 12288
  244.     //ec = 10500;
  245.     //printenable = true;
  246. //
  247.     //if(ec == 256 * 48)
  248.     //{
  249.         //printf("ec = %d\n", ec);
  250.         //printenable = true;
  251.     //}
  252.     if(printenable) printf("START ec %d time %d steps 0\n", ec, time);
  253.  
  254.  
  255.     for(int steps = 0; steps < NumSteps; steps++)//Main path steps.
  256.     {
  257.         ec -= TileArray[steps].ec_decrement;  //Take a step
  258.         time += STEP_TIME;
  259.         if(ec <= 0)   //See if we got into an encounter.
  260.         {
  261.             if(use_static_encounter_time)
  262.             {
  263.                 time+= static_encounter_time;
  264.             }
  265.             else
  266.             {
  267.                 time += TileArray[steps].encounter_time_loss;  //Battle time loss
  268.             }
  269.             ec = GetRandomEC();
  270.             last_encounter_tile = steps;   //This really should be converted to distance covered.
  271.             num_encounters++;
  272.         }
  273.         if(printenable) printf("ec %d time %d steps %d\n", ec, time, steps+1);
  274.         //See if we're going onto the alt path.
  275. #if 1
  276.         if(TileArray[steps].make_break_decision == true && alt_path_taken == false)
  277.         {
  278.             alt_path_taken = true;
  279.             if(last_encounter_tile <= static_encounter_tile_num)  //This is the break decision
  280.             {
  281.                 int alt_steps = 0;
  282.                 for(alt_steps = 0; alt_steps < NumAltSteps; alt_steps++)//Alt path steps forwards.
  283.                 {  
  284.                     ec -= TileArrayAlt[alt_steps].ec_decrement;  //Take a step
  285.                     time += STEP_TIME;
  286.                     if(ec <= 0)   //See if we got into an encounter.
  287.                     {
  288.                         if(use_static_encounter_time)
  289.                         {
  290.                             time+= static_encounter_time;
  291.                         }
  292.                         else
  293.                         {
  294.                             time += TileArrayAlt[alt_steps].encounter_time_loss;  //FIXME For now...
  295.                         }
  296.                         ec = GetRandomEC();
  297.                         if(printenable) printf("NEW ec %d\n", ec);
  298.                         num_encounters++;
  299.                         //FIXME Don't mark last encounter here yet.
  300.                         break;  //Start walking back.
  301.                     }
  302.                     if(printenable) printf("ec %d time %d alt_steps %d\n", ec, time, alt_steps+1);
  303.  
  304.                 }
  305.                 if(alt_steps == NumAltSteps)  //If we made it to the reset.
  306.                 {
  307.                     time += AltPathTime;
  308.                     ec = GetRandomEC();
  309.                     if(printenable) printf("NEW ec %d\n", ec);
  310.                 }
  311.                 alt_steps--;
  312.                 for(; alt_steps >= 0; alt_steps--)//Alt path steps backwards.   //FIXME There's an issue with an extra step here.
  313.                 {  
  314.                     ec -= TileArrayAlt[alt_steps].ec_decrement;  //Take a step
  315.                     time += STEP_TIME;
  316.                     if(ec <= 0)   //See if we got into an encounter.
  317.                     {
  318.                         if(use_static_encounter_time)
  319.                         {
  320.                             time+= static_encounter_time;
  321.                         }
  322.                         else
  323.                         {
  324.                             time += TileArrayAlt[alt_steps].encounter_time_loss;
  325.                         }
  326.                         ec = GetRandomEC();
  327.                         if(printenable) printf("NEW ec %d\n", ec);
  328.                         num_encounters++;
  329.                         //FIXME Don't mark last encounter here yet.
  330.                     }
  331.                     if(printenable) printf("ec %d time %d alt_steps %d\n", ec, time, alt_steps+1);
  332.                 }
  333.                 steps -= 1;
  334.             }
  335.            
  336.         }
  337. #endif
  338.     }
  339.  
  340.  
  341.  
  342.  
  343.     if(printenable) printf("Final Time %d num_encounters %d\n", time, num_encounters);
  344.     return time;
  345. }
  346.  
  347. int main ()
  348. {  
  349.     int this_time;
  350.     long long total_time = 0;
  351.     double average_time = 0;
  352.     int iterations = 10000000;
  353.     int count = 0;
  354.  
  355.     //int mintime = 60 * 100;
  356.     srand(time(NULL));
  357.     InitArrays();
  358.     SetupAllTiles();
  359.  
  360.     use_static_encounter_time = true;
  361.     static_encounter_time = 20 * 60;
  362.     static_encounter_tile_num = 36;
  363.  
  364.     for(static_encounter_time = 10*60; static_encounter_time <= 20*60; static_encounter_time+= 2*60)
  365.     {
  366.         for(static_encounter_tile_num = 0; static_encounter_tile_num <= 15; static_encounter_tile_num++)
  367.         {
  368.             count = 0;
  369.             total_time = 0;
  370.             this_time = 0;
  371.             average_time = 0;
  372.             while(count < iterations)
  373.             {
  374.                 for(int i=0; i<iterations; i++)
  375.                 {
  376.                     this_time = Simulate();
  377.                     if(this_time > 0)
  378.                     {
  379.                         total_time += this_time;
  380.                         count++;
  381.                     }
  382.                 }
  383.             }
  384.             average_time = double(total_time)/double(count);
  385.             //printf("average_num_frames = %.4f or %.4f seconds\n", average_time, average_time/60);
  386.             printf("enc time %d, tile_num %d, %.4f seconds\n", static_encounter_time/60, static_encounter_tile_num, average_time/60);
  387.  
  388.         }
  389.     }    
  390.  
  391.     /*for(int i=0; i<40; i++)
  392.     {
  393.         printf("%d\n",TileArray[i].ec_decrement);
  394.     }*/
  395.  
  396.     cout << "To close type something and hit enter: ";
  397.     cin >> dumpchar;
  398.     return 0;
  399. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement