CGI/Perl Guide | Learning Center | Forums | Advertise | Login Site Search: in Perl Guide PerlGuru Forums Learning Ctr

Home: Perl Programming Help: Beginner:
ANOTHER QUESTION....

mattmatt
Deleted

Jun 26, 2000, 7:47 AM

Post #1 of 3 (931 views)
 ANOTHER QUESTION.... Can't Post
ok i am making an online wrestling game where each person has a certain amount of strength, and for each 1 more strength that someone has more than another person, they have a 2% more chance to win so like if one person has 45 strength and another has 55 strength, the person w/ 55 str. would have a 70% chance to win... but what i am asking is how to actually DO the percentages and give the person with the lesser strength a chance to win, its kinda hard to explain what i want but i hope you understood me

mattmatt
Deleted

Jun 25, 2000, 10:17 PM

Post #2 of 3 (931 views)
 Re: ANOTHER QUESTION.... [In reply to] Can't Post
does that actually work out where if someone has 5 less strength than another person, they still have a CHANCE? because i already have it where the person with the greatest strength wins, but i CANT keep it like that because in real life its not like the underdog cant defeat the big guy =)

what i want is where its kind of a random winner, BUT the person with the greater strength has a little bit more of a chance to be the random person

scarab
Deleted

Jun 26, 2000, 9:08 AM

Post #3 of 3 (931 views)
 Re: ANOTHER QUESTION.... [In reply to] Can't Post
Are the players' chances to win based on a random roll? Are there other factors involved with the decision whether or not a player wins? I think this is what you mean. If you let \$strength1 be player1's strength and \$chance1 be the percentage chance for player1 to win:

\$chance1 = (\$strength1 * 2) / 100;
\$chance2 = (\$strength2 * 2) / 100;

If you want to calculate who is going to win:

\$rand1 = rand(1)*\$chance1;
\$rand2 = rand(1)*\$chance2;

if (\$rand1 <= 0 | | \$rand2 <= 0) {
\$winner = -1;
} elsif (\$rand1 > \$rand2) {
\$winner = 1;
} elsif (\$rand2 > \$rand1) {
\$winner = 2;
} elsif (\$rand1 == \$rand2) {
\$winner = 0;
}

Obviously, if winner = 1, player1 won, etc. winner = 0 is a tie, and winner = -1 is an error. That's the simplest and most straightforward way to do it methinks. I also don't think you'll run into any logic errors there. It might not be mathematically correct, but you'll run into > 100% chances of winning for both players if their strengths exceed 50. You might put a check somewhere else that keeps their strengths < 50, so you don't have to worry about 100%+ chances to win.

scarab.

[This message has been edited by scarab (edited 06-26-2000).]

 Announcements     PerlGuru Announcements Perl Programming Help     Frequently Asked Questions     Beginner     Intermediate     Advanced     Regular Expressions     mod_perl     DBI     Win32 Programming Help Fun With Perl     Perl Quizzes - Learn Perl the Fun Way     Perl Golf     Perl Poetry Need a Custom or Prewritten Perl Program?     I need a program that...     I Need a Programmer for Freelance Work     Throw Down The Gauntlet General Discussions     General Questions     Feedback     Tutorial/Article Suggestions for The Learning Cent     Internet Security Other Programming Languages     Javascript     PHP

 Search this forum this category all forums for All words Any words Whole Phrase (options) Powered by Gossamer Forum v.1.2.0