Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdio>
- #include <stdio.h>
- #include <time.h>
- #include <math.h>
- #include <windows.h>
- #include <unistd.h>
- using namespace std;
- #define FIELD 256
- #define ICE 256
- #define DESERT 384
- #define FOREST 460
- #define SWAMP 460
- #define MOUNTAIN 640
- int ec;
- //Add lamp of darkness later.
- typedef enum PathType
- {
- PATH_STANDARD = 0,
- PATH_ALTERNATE = 1
- } PathType;
- #define ASSERT printf("ASSERT %d\n", __LINE__);cout << "To close type something and hit enter: ";cin >> dumpchar;exit(-1);
- //0 to 12288
- #define EC_ARRAY_SIZE (49)
- #define EC_SAMPLE_SIZE (32768)
- #define MAX_NUM_TILES (100)
- #define ALIAHAN_ENCOUNTER (60 * 15 + 0) //In frames
- #define MAGIC_BALL_ENCOUNTER (60 * 30 + 0) //In frames
- #define ALIAHAN_ALT_PATH_STATIC_TIME (278) //In frames
- #define MAGIC_BALL_ALT_PATH_STATIC_TIME (273) //In frames
- #define OUTDOOR_STEP_TIME (16) //In frames
- #define STEP_TIME (OUTDOOR_STEP_TIME) //In frames
- #define ALIAHAN_TEST
- //#define MAGIC_BALL_TEST
- //#define DEBUG
- static int SpreadArray[EC_ARRAY_SIZE] =
- { 9, 9, 42, 69, 105, 171, 208, 253, 317, 362,
- 456, 533, 613, 685, 780, 936, 1032, 1065, 1220, 1245,
- 1378, 1359, 1462, 1449, 1454, 1351, 1343, 1380, 1401, 1277,
- 1220, 1126, 996, 908, 793, 716, 615, 528, 443, 390,
- 279, 240, 167, 142, 106, 64, 46, 20, 5};
- int ECArray[EC_SAMPLE_SIZE];
- int dumpchar;
- class Tile
- {
- public:
- int ec_decrement;
- int encounter_time_loss;
- bool make_break_decision;
- Tile();
- };
- Tile::Tile(void)
- {
- ec_decrement = 0;
- encounter_time_loss = 0;
- make_break_decision = false;
- }
- void initTile (Tile &Tile, int type, int enc)
- {
- Tile.ec_decrement = type;
- Tile.encounter_time_loss = enc;
- }
- Tile TileArray[MAX_NUM_TILES];
- Tile TileArrayAlt[MAX_NUM_TILES]; //Tile break attaches to TileArrayAlt[0];
- int NumSteps = 0;
- int NumAltSteps = 0;
- int AltPathTime = 0;
- void SetupAllTiles()
- {
- #ifdef ALIAHAN_TEST
- //Aliahan to Reeve
- int k = 0;
- //The first tile is the first enemy tile
- //The last tile is the last enemy tile (one step from destination)
- //MAIN_PATH
- for(int i = 0; i<21; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], FIELD, ALIAHAN_ENCOUNTER);
- }
- for(int i = 0; i<12; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- if(i == 8)
- {
- TileArray[k].make_break_decision = true;
- }
- initTile(TileArray[k++], FOREST, ALIAHAN_ENCOUNTER);
- }
- for(int i = 0; i<4; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], FIELD, ALIAHAN_ENCOUNTER);
- }
- NumSteps = k;
- //ALT_PATH
- k = 0;
- for(int i = 0; i<2; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArrayAlt[k++], FOREST, ALIAHAN_ENCOUNTER);
- }
- NumAltSteps = k;
- AltPathTime = ALIAHAN_ALT_PATH_STATIC_TIME;
- #endif
- #ifdef MAGIC_BALL_TEST
- //Reeve to Magic Ball Cave
- int k = 0;
- //The first tile is the first enemy tile
- //The last tile is the last enemy tile (one step from destination)
- //MAIN_PATH
- for(int i = 0; i<21; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], FIELD, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<3; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], FOREST, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<1; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], MOUNTAIN, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<3; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], FOREST, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<9; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], MOUNTAIN, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<3; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], FOREST, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<7; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], MOUNTAIN, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<2; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- if(i == 0)
- {
- TileArray[k].make_break_decision = true;
- }
- initTile(TileArray[k++], FIELD, MAGIC_BALL_ENCOUNTER);
- }
- for(int i = 0; i<3; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArray[k++], DESERT, MAGIC_BALL_ENCOUNTER);
- }
- NumSteps = k;
- //ALT_PATH
- k = 0;
- for(int i = 0; i<1; i++)
- {
- if(k >= MAX_NUM_TILES)
- {
- ASSERT;
- }
- initTile(TileArrayAlt[k++], FIELD, ALIAHAN_ENCOUNTER);
- }
- NumAltSteps = k;
- AltPathTime = MAGIC_BALL_ALT_PATH_STATIC_TIME;
- #endif
- }
- void InitArrays()
- {
- int k;
- for(int i = 0; i<EC_ARRAY_SIZE; i++)
- {
- for(int j = 0; j < SpreadArray[i]; j++)
- {
- if(k >= EC_SAMPLE_SIZE)
- {
- ASSERT;
- }
- ECArray[k++] = i*256;
- }
- }
- //Sanity checks
- if(k != EC_SAMPLE_SIZE || ECArray[0] != 0 || ECArray[EC_SAMPLE_SIZE-1] != 12288)
- {
- ASSERT;
- }
- #ifdef DEBUG
- for(int i = 0; i<100; i++)
- {
- printf("ECArray[i] = %d\n", ECArray[i]);
- }
- #endif
- }
- int GetRandomEC()
- {
- int ret = ECArray[rand() % EC_SAMPLE_SIZE];
- return ret;
- }
- int Simulate(void)
- {
- int last_encounter_tile = -1;
- int ec = GetRandomEC(); //Start
- bool alt_path_taken = false;
- bool printenable = false;
- int time = 0;
- int num_encounters = 0;
- //if(ec < 9000) //HACK TEST
- //{
- // return 0;
- //}
- //
- ////0 to 12288
- //ec = 512;
- printenable = true;
- //
- if(ec == 256 * 48)
- {
- //printf("ec = %d\n", ec);
- //printenable = true;
- }
- if(printenable)
- {
- printf("START ec %d time %d steps 0\n", ec, time);
- }
- for(int steps = 0; steps < NumSteps; steps++)//Main path steps.
- {
- ec -= TileArray[steps].ec_decrement; //Take a step
- time += STEP_TIME;
- if(ec <= 0) //See if we got into an encounter.
- {
- time += TileArray[steps].encounter_time_loss; //Battle time loss
- ec = GetRandomEC();
- last_encounter_tile = steps; //This really should be converted to distance covered.
- num_encounters++;
- }
- if(printenable)
- {
- printf("ec %d time %d steps %d\n", ec, time, steps+1);
- }
- //See if we're going onto the alt path.
- #if 1
- if(TileArray[steps].make_break_decision == true && alt_path_taken == false)
- {
- alt_path_taken = true;
- if(last_encounter_tile <= 50) //This is the break decision
- {
- int alt_steps = 0;
- for(alt_steps = 0; alt_steps < NumAltSteps; alt_steps++)//Alt path steps forwards.
- {
- ec -= TileArrayAlt[alt_steps].ec_decrement; //Take a step
- time += STEP_TIME;
- if(ec <= 0) //See if we got into an encounter.
- {
- time += TileArrayAlt[alt_steps].encounter_time_loss; //FIXME For now...
- ec = GetRandomEC();
- num_encounters++;
- //FIXME Don't mark last encounter here yet.
- break; //Start walking back.
- }
- if(printenable)
- {
- printf("ec %d time %d alt_steps %d\n", ec, time, alt_steps+1);
- }
- }
- if(alt_steps == NumAltSteps) //If we made it to the reset.
- {
- time += AltPathTime;
- ec = GetRandomEC();
- }
- for(; alt_steps >= 0; alt_steps--)//Alt path steps backwards. //FIXME There's an issue with an extra step here.
- {
- ec -= TileArrayAlt[alt_steps].ec_decrement; //Take a step
- time += STEP_TIME;
- if(ec <= 0) //See if we got into an encounter.
- {
- time += TileArrayAlt[alt_steps].encounter_time_loss;
- ec = GetRandomEC();
- num_encounters++;
- //FIXME Don't mark last encounter here yet.
- }
- if(printenable)
- {
- printf("ec %d time %d alt_steps %d\n", ec, time, alt_steps+1);
- }
- }
- steps -= 1;
- }
- }
- #endif
- }
- if(printenable)
- {
- printf("Final Time %d num_encounters %d\n", time, num_encounters);
- }
- return time;
- }
- int main ()
- {
- int this_time;
- long long total_time = 0;
- double average_time = 0;
- int iterations = 1;
- int count = 0;
- //int mintime = 60 * 100;
- srand(time(NULL));
- InitArrays();
- SetupAllTiles();
- for(int i=0; i<iterations; i++)
- {
- this_time = Simulate();
- if(this_time > 0)
- {
- total_time += this_time;
- count++;
- }
- }
- average_time = double(total_time)/double(count);
- printf("average_num_frames = %.4f or %.4f seconds\n", average_time, average_time/60);
- /*for(int i=0; i<40; i++)
- {
- printf("%d\n",TileArray[i].ec_decrement);
- }*/
- cout << "To close type something and hit enter: ";
- cin >> dumpchar;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement