#include <iostream>
#include <cstdlib>
#include <ctime>

class Player {
    int hp;
    int maxHp;
public:
    Player(int h) : hp(h), maxHp(h) {}

    void damage(int d) {
        hp -= d;
        if (hp < 0) hp = 0;
    }

    void recovery(int d) {
        hp += d;
        if (hp > maxHp) hp = maxHp;
    }

    int GetHp() const { return hp; }
};

int alive(const Player& p) {
    return p.GetHp() > 0;
}

int main() {
    srand(time(nullptr));

    Player R(10000), P(10000), G(10000);
    int turn = 1;
    

    while (alive(R) + alive(P) + alive(G) >= 2) {

        int action, value;

        // Rの行動(Pを狙う)
        action = rand() % 3;
        value  = rand() % 2500;
        (action == 0 ? P.damage(value) : (action == 1 ? G.damage(value) : R.recovery(value)));

        // Pの行動(Gを狙う)
        action = rand() % 3;
        value  = rand() % 2500;
        (action == 0 ? G.damage(value) : (action == 1 ? R.damage(value) : P.recovery(value)));

        // Gの行動(Rを狙う)
        action = rand() % 3;
        value  = rand() % 2500;
        (action == 0 ? R.damage(value) : (action == 1 ? P.damage(value) : G.recovery(value)));

        std::cout << "Turn " << turn++
                  << " R:" << R.GetHp()
                  << " P:" << P.GetHp()
                  << " G:" << G.GetHp() << '\n';
    }

    if (R.GetHp() > 0) std::cout << "R wins!\n";
    else if (P.GetHp() > 0) std::cout << "P wins!\n";
    else std::cout << "G wins!\n";
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: