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

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

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

 



mattmatt
Deleted

Jun 26, 2000, 7:47 AM

Post #1 of 3 (572 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 (572 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 (572 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).]

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives