Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // PROVIDED BY: M. Scott Leuthaeuser
- // MODIFIED BY: Sasazuka
- // CONTACT E-MAIL: michael (dot) leuthaeuser [at] gmail (dot) com
- // FILE: ChiSim.cpp
- // VERSION: 0.1.0.B
- // PURPOSE: Simulate Enveloping Mist uptime under ideal conditions
- // Includes average Chi generated using new 5.2 model
- // DIRECTIVES -----------------------------------------------------------------
- #include <cstdlib>
- #include <iostream>
- #include <iomanip>
- #include <ctime>
- #include <string>
- using namespace std;
- // ----------------------------------------------------------------------------
- // STRUCTURES------------------------------------------------------------------
- struct Sim
- {
- float time;
- int chiGenerated;
- int chiWasted;
- float downtime;
- };
- // ----------------------------------------------------------------------------
- // GLOBAL CONSTANTS -----------------------------------------------------------
- // Probability of generating 1 Chi each tick
- const int G_CHI_PROBABILITY = 15;
- // Increase in probability when a tick doesn't generate Chi
- const int G_CHI_PROBABILITY_MOD = 15;
- // Number of iterations
- const int G_ITERATIONS = 100000;
- // Average total sim duration
- const float G_TIME = 300.0;
- // Variation on total sim duration as a percent of G_TIME
- const float G_VARIANCE = 0.2;
- // Enveloping duration in ticks
- const float G_DURATION = 7.0;
- // Number of ticks you can fresh early and still get full duration
- const float G_REFRESH = 1.0;
- // Max Chi pool
- const int G_CHI_MAX = 4;
- // How much Chi you start with
- const int G_CHI_INIT = 0;
- // How much Chi Enveloping consumes
- const int G_CHI_REQ = 3;
- // ----------------------------------------------------------------------------
- // FUNCTION PROTOTYPES --------------------------------------------------------
- Sim simulate( float time, bool useNewModel );
- bool generateChi( bool useNewModel );
- bool generateChi( bool useNewModel, bool resetProbability );
- // ----------------------------------------------------------------------------
- // ============================================================================
- int main( int argc, char* argv[] ) {
- Sim total, iteration;
- bool useNewModel = false;
- if ( argc > 1 ) {
- useNewModel = true;
- }
- total.time = 0;
- total.chiGenerated = 0;
- total.chiWasted = 0;
- total.downtime = 0;
- srand( time(0) );
- // Simulate
- for( int c = 0; c < G_ITERATIONS; c++ ) {
- iteration = simulate(
- G_TIME * ( 1.0 + ( G_VARIANCE * 2 * ( ( rand() % 101 ) / 100.0 ) - G_VARIANCE ) ),
- useNewModel );
- total.time += iteration.time;
- total.chiGenerated += iteration.chiGenerated;
- total.chiWasted += iteration.chiWasted;
- total.downtime += iteration.downtime;
- }
- // Output results
- cout << "AVERAGE DOWNTIME: "
- << total.downtime / G_ITERATIONS
- << " / " << total.time / G_ITERATIONS
- << " (" << total.downtime / total.time * 100 << "%)" << endl;
- cout << "AVERAGE CHI WASTED: "
- << (float) total.chiWasted / G_ITERATIONS
- << " / "
- << (float) total.chiGenerated / G_ITERATIONS
- << " (" << (float) total.chiWasted / (float) total.chiGenerated * 100
- << "%)" << endl;
- cout << "USING NEW MODEL: " << ( useNewModel ? "true" : "false" ) << endl;
- cout << "AVG CHI GENERATED: " << total.chiGenerated / (float) G_ITERATIONS << endl;
- cout << "AVG TIME: " << total.time / (float) G_ITERATIONS << endl;
- // Pause
- cout << endl << "Press any key to continue..." << endl;
- cin.sync();
- // Exit
- return 0;
- }
- // ============================================================================
- bool generateChi( bool useNewModel ) {
- return generateChi( useNewModel, false );
- }
- bool generateChi( bool useNewModel, bool resetProbability ) {
- static int probability_modifier = 0;
- if ( resetProbability ) {
- probability_modifier = 0;
- return false;
- }
- if ( useNewModel ) {
- if ( rand() % 100 < ( G_CHI_PROBABILITY + probability_modifier ) ) {
- probability_modifier = 0;
- return true;
- } else {
- probability_modifier += G_CHI_PROBABILITY_MOD;
- }
- } else {
- return ( rand() % 100 < G_CHI_PROBABILITY );
- }
- return false;
- }
- Sim simulate( float time, bool useNewModel ) {
- Sim i;
- i.time = 0;
- i.chiGenerated = 0;
- i.chiWasted = 0;
- i.downtime = 0;
- int chi = G_CHI_INIT;
- float remDuration = 0;
- //cout << "Time: " << time << endl;
- for( i.time; i.time < time; i.time++ ) {
- // cout << "TIME: " << i.time << ", CHI: " << chi << ", DURATION: " << remDuration;
- if( remDuration < G_REFRESH && chi >= G_CHI_REQ ) {
- // cout << " REFRESH!";
- chi -= G_CHI_REQ;
- remDuration += G_DURATION;
- }
- if( remDuration == 0 ) {
- // cout << " DOWNTIME!";
- i.downtime++;
- }
- if ( generateChi( useNewModel ) ) {
- if(chi == G_CHI_MAX) {
- // cout << " CHI WASTED!";
- i.chiWasted++;
- } else {
- // cout << " CHI GENERATED!";
- chi++;
- }
- i.chiGenerated++;
- }
- // cout << endl;
- if( remDuration > 1.0 ) {
- remDuration--;
- } else {
- remDuration = 0;
- }
- }
- generateChi( useNewModel, true );
- return i;
- }
Advertisement
Add Comment
Please, Sign In to add comment