Jump to content

hi someone convert c++ to java for me


FearMe

Recommended Posts

thx!!!

 

 

void combat (vector<double>& health, double oaccuracy, double obase_damage)
{
        for (int j = 1; j < health.size (); j++)
        {
                for (int k = 1; k < obase_damage; k++)
                {
                        if (j - k >= 0)
                                health [j - k] += oaccuracy * health [j] / obase_damage;
                        else
                                health [0] += oaccuracy * health [j] / obase_damage;
                }
                health [j] *= 1 - oaccuracy;
                health [j] += oaccuracy * health [j] / obase_damage;
        }
}
void statistics (double& p, double& win, double& loss, vector<double> health, vector<double> ohealth)
{
        double temp = 1 - (1 - health [0]) * (1 - ohealth [0]);
        temp -= p;
        if (health [0] > 0 || ohealth [0] > 0)
        {
                win += temp * (ohealth [0] / (ohealth [0] + health [0]));
                loss += temp * (health [0] / (ohealth [0] + health [0]));
        }
        p += temp;
}
void create_health (vector<double>& health, double constitution)
{
        for (int i = 0; i < constitution * 10; i++)
                health.push_back (0);
        health [health.size () - 1] = 1;
}
int main()
{
        cout << "Enter both players' stats to calculate chances of winning." << endl << endl;
        double attack; // Your Attack level
        double strength; // Your Strength level
        double defence; // Your Defence level
        double constitution; // Your Constitution level
        double oattack; // Opponent's Attack level
        double ostrength; // Opponent's Strength level
        double odefence; // Opponent's Defence level
        double oconstitution; // Opponent's Constitution level
        cout << "Attack:                                  ";
        cin >> attack; // Your Attack level
        cout << "Strength:                              ";
        cin >> strength; // Your Strength level
        cout << "Defence:                                ";
        cin >> defence; // Your Defence level
        cout << "Constitution:                  ";
        cin >> constitution; // Your Constitution level
        cout << endl;
        cout << "Opponent's Attack:        ";
        cin >> oattack; // Opponent's Attack level
        cout << "Opponent's Strength:    ";
        cin >> ostrength; // Opponent's Strength level
        cout << "Opponent's Defence:      ";
        cin >> odefence; // Opponent's Defence level
        cout << "Opponent's Constitution: ";
        cin >> oconstitution; // Opponent's Constitution level
        cout << endl;
        double effective_attack = 10 * (attack + 8 + 3); // 5/8 from standard formula, 3 from style bonus
        double effective_strength = strength + 8; // ,,
        double base_damage = effective_strength + 5; // ,,
        double effective_defence = 10 * (defence + 8); // ,,
        double oeffective_attack = 10 * (oattack + 8 + 3); // ,,
        double oeffective_strength = ostrength + 8; // ,,
        double obase_damage = oeffective_strength + 5; // ,,
        double oeffective_defence = 10 * (odefence + 8); // ,,
        double accuracy;
        double oaccuracy;
        if (attack < odefence)
                accuracy = (effective_attack - 1) / (2 * oeffective_defence);
        else
                accuracy = 1 - (oeffective_defence + 1) / (2 * effective_attack);
        if (oattack < defence)
                oaccuracy = (oeffective_attack - 1) / (2 * effective_defence);
        else
                oaccuracy = 1 - (effective_defence + 1) / (2 * oeffective_attack);
        cout << "Your accuracy:            " << accuracy << endl;
        cout << "Opponent's accuracy:    " << oaccuracy << endl;
        cout << endl;
        vector<double> health;
        vector<double> ohealth;
        create_health (health, constitution);
        create_health (ohealth, oconstitution);
        double p = 0;
        double win = 0;
        double loss = 0;
        for (int hit = 0; win + loss < 0.99 && hit < 1000; hit++)
        {
                combat (health, oaccuracy, obase_damage);
                combat (ohealth, accuracy, base_damage);
                statistics (p, win, loss, health, ohealth);
        }
        cout << "Your win chance:                " << win << endl;
        cout << "Opponent's win chance:   " << loss << endl;
        return 0;
}

Link to comment
Share on other sites

>> and << operators I'm assuming just wait/put out data. Obviously it's just printing out text and then waiting for input to store in a variable.

Ah nvm, I get it now. I thought endl was a variable(didn't look for it at all, just assumed), it turns out it means end line... I think I can convert it myself now. >_>

Link to comment
Share on other sites

>> and << operators I'm assuming just wait/put out data. Obviously it's just printing out text and then waiting for input to store in a variable.

 

^^this

std::cout << "kjhkjhkj" << std::endl; //will output whatever follows the "<<" sign on the console/terminal 

std::cin >> variable; // will take an input and place it in some variable.

 

btw keep your main function as clean as possible ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...