scarab
Deleted
Jun 26, 2000, 9:08 AM
Post #3 of 3
(767 views)

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 06262000).]
