c_cpp 在Amaz游戏中的炉石致死率https://www.youtube.com/watch?v=clEKDpjQ7Ok

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c_cpp 在Amaz游戏中的炉石致死率https://www.youtube.com/watch?v=clEKDpjQ7Ok相关的知识,希望对你有一定的参考价值。

// 100,000,000 times simulation of Hearthstone lethal rate in an Amaz game:
//     https://www.youtube.com/watch?v=clEKDpjQ7Ok
//
// rate killing stegodon: 0.00423331
// rate lethal: 0.00234898
//
// consistent with theoretical calculation
//     P1 = stegodon dead = ( C(8,6)* (3^2) + C(8,7) * 3 + C(8,8) ) / (4^8) = 277/65536 = 0.4227%
//     P2 = face hit when stegodon is dead = 1 - (2/3)^2 = 5/9
//     win rate = P1 * P2 = 0.2348%

#include <iostream>  // cout
#include <cstdlib>  // rand()

using std::cout;


// pick a random non-zero indice from an array
int picktarget(int n_targets, const int *targets) {

    // construct a non-zero vector
    int n_nonzero = 0;
    int *nonzero_targets = new int[n_targets];

    for(int i = 0; i < n_targets; i++){
        if (targets[i] > 0) {
            nonzero_targets[n_nonzero] = i;  // record indice of nonzero entry
            n_nonzero++;  // count++
        }
    }

    // return a random indice with non-zero entry
    return nonzero_targets[rand() % n_nonzero];
}


int main(void){

    // parameters
    const int n_shot = 8;
    const int n_targets = 4;
    const int *targets = new int[4]{4, 4, 6, 8};
    const int iter = 100000000;  // # of experiments

    // temp/common variables
    int *targets_left = new int[n_targets];  // target instance to shoot
    int picked;  // temp variable for picked target
    int n, i;  // loop variables
    int n_stegodon_killed = 0;
    int n_lethal = 0;

    // init
    srand(time(NULL));

    // main loop
    for (n = 0; n < iter; n++) {

        // initialize a target instance
        for (i = 0; i < n_targets; i++)
            targets_left[i] = targets[i];

        // shoot
        for (i = 0; i < n_shot; i++) {
            // pick
            picked = picktarget(n_targets, targets_left);
            // hit
            targets_left[picked] -= 1;
        }

        // count
        if (targets_left[2] == 0) {
            n_stegodon_killed++;
            if (targets_left[3] < targets[3]) {
                n_lethal++;
            }
        }

        // print result
        /*for(int i=0; i < n_targets; i++)
             cout << targets_left[i];
        cout << "\n";
        */
    }

    cout << "rate killing stegodon: " << (1.0 * n_stegodon_killed / iter)
         << "\nrate lethal: " << (1.0 * n_lethal / iter);

    return 0;
}

以上是关于c_cpp 在Amaz游戏中的炉石致死率https://www.youtube.com/watch?v=clEKDpjQ7Ok的主要内容,如果未能解决你的问题,请参考以下文章

CCF炉石传说

ccf-20160903--炉石传说

CSP-201609-3 炉石传说

CCF 201609-3 炉石传说

ccf 201609-3 炉石传说

CCF - 201609-3 - 炉石传说