- #36
Mark44
Mentor
- 37,660
- 9,915
I realized that when I counted the total wins for each set and the ties.pbuk said:That loop will execute 1,000,001 times.
I realized that when I counted the total wins for each set and the ties.pbuk said:That loop will execute 1,000,001 times.
Complete enumeration of the probability space for the two-way competition is way cheaper than that.pbuk said:That loop will execute 1,000,001 times.
C:\>test.pl
Player 1 (3d6) scores 50972 points
Player 2 (1d20) scores 51632 points
Player 3 (5,5,5,6,21,21) scores 52916 points
Player 1 (3d6) rolled a mean of 10.5 pips per roll
Player 2 (1d20) rolled a mean of 10.5 pips per roll
Player 3 (5,5,5,6,21,21) rolled a mean of 10.5 pips per roll
There were 25920 combinations with a total of 155520 points available
The total points awarded were 155520
#!/usr/bin/perl
use strict;
use warnings;
# Points = winning points: 6 = clear win, 3 = two-way tie, 2 = three-way tie
my $p1_points = 0;
my $p2_points = 0;
my $p3_points = 0;
# Total = total pips rolled
my $p1_total = 0;
my $p2_total = 0;
my $p3_total = 0;
my $total_combos = 0;
sub scores ( $$$$$ );
foreach my $d1 ( 1, 2, 3, 4, 5, 6 ) {
foreach my $d2 ( 1, 2, 3, 4, 5, 6 ) {
foreach my $d3 ( 1, 2, 3, 4, 5, 6 ) {
foreach my $d4 ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 ) {
foreach my $d5 ( 5, 5, 5, 6, 21, 21 ) {
my @result = scores ( $d1, $d2, $d3, $d4, $d5 );
$p1_points = $p1_points + $result[0];
$p2_points = $p2_points + $result[1];
$p3_points = $p3_points + $result[2];
$p1_total = $p1_total + $result[3];
$p2_total = $p2_total + $result[4];
$p3_total = $p3_total + $result[5];
$total_combos = $total_combos + 1;
};
};
};
};
};
if ( $total_combos != 6 * 6 * 6 * 20 * 6 ) {
print STDERR "Calculated total combinations is ", 6 * 6 * 6 * 20 * 6, " but this code found $total_combos instead\n";
exit;
};
print "Player 1 (3d6) scores $p1_points points\n";
print "Player 2 (1d20) scores $p2_points points\n";
print "Player 3 (5,5,5,6,21,21) scores $p3_points points\n";
print "\n";
print "Player 1 (3d6) rolled a mean of ", $p1_total/$total_combos, " pips per roll\n";
print "Player 2 (1d20) rolled a mean of ", $p2_total/$total_combos, " pips per roll\n";
print "Player 3 (5,5,5,6,21,21) rolled a mean of ", $p3_total/$total_combos, " pips per roll\n";
print "\n";
print "There were $total_combos combinations with a total of ", $total_combos * 6, " points available\n";
print "The total points awarded were ", $p1_points + $p2_points + $p3_points, "\n";
sub scores ( $$$$$ ) {
my $p1d1 = $_[0];
my $p1d2 = $_[1];
my $p1d3 = $_[2];
my $p2d1 = $_[3];
my $p3d1 = $_[4];
# Player 1 scores 3d6
my $p1_score = $p1d1 + $p1d2 + $p1d3;
# Player 2 scores 1d20
my $p2_score = $p2d1;
# Player 3 scores pips equal to 5, 5, 5, 6, 21, 21 on a d6;
my $p3_score = $p3d1;
if ( $p1_score > $p2_score && $p1_score > $p3_score ) {
return ( 6, 0, 0, $p1_score, $p2_score, $p3_score );
} elsif ( $p2_score > $p1_score && $p2_score > $p3_score ) {
return ( 0, 6, 0, $p1_score, $p2_score, $p3_score );
} elsif ( $p3_score > $p1_score && $p3_score > $p2_score ) {
return ( 0, 0, 6 , $p1_score, $p2_score, $p3_score);
} elsif ( $p1_score == $p2_score && $p1_score > $p3_score ) {
return ( 3, 3, 0, $p1_score, $p2_score, $p3_score );
} elsif ( $p1_score == $p3_score && $p1_score > $p2_score ) {
return ( 3, 0, 3, $p1_score, $p2_score, $p3_score );
} elsif ( $p2_score == $p3_score && $p2_score > $p1_score ) {
return ( 0, 3, 3, $p1_score, $p2_score, $p3_score );
} elsif ( $p1_score == $p2_score && $p1_score == $p3_score ) {
return ( 2, 2, 2, $p1_score, $p2_score, $p3_score );
} else {
print STDERR "No clear winner, no two way tie, no three way tie. What is going on?\n";
print STDERR "Player 1: $p1d1 $p1d2 $p1d3 = $p1_score\n";
print STDERR "Player 2: $p2d1 = $p2_score\n";
print STDERR "Player 3: $p3d1 = $p3_score\n";
exit;
};
};
That cannot be true: 3D6 will always beat 1 or 2 whereas D20 will sometimes lose.PeroK said:PS I assigned the third player a fixed score of everything from 1-20 and there is no score that creates an advantage for 3D6.
A third player score of 1 or 2 leaves the contest between 3D6 and D20 level. In terms of outright wins.pbuk said:That cannot be true: 3D6 will always beat 1 or 2 whereas D20 will sometimes lose.
Indeed. For non-linear problems (and you can't get much more non-linear than win/lose) Monte-Carlo methods are not in general worthwhile.jbriggs444 said:Complete enumeration of the probability space for the two-way competition is way cheaper than that.
I suspect 3d6 may score better against [2, 2, 2, 36] (particularly if you only count clear wins) but I can't be bothered to fire up a Linux instance at the moment to test your Perl scriptjbriggs444 said:I did a complete enumeration for a 3-way competition and only needed 25,920 cases. My intuition about 3d6 beating 1d20 in a three way match against (5, 5, 5, 6, 21, 21) was faulty.
You suspect wrongly!pbuk said:I suspect 3d6 may score better against [2, 2, 2, 36] (particularly if you only count clear wins) but I can't be bothered to fire up a Linux instance at the moment to test your Perl script
Yes of course, I missed that point.PeroK said:A third player score of 1 or 2 leaves the contest between 3D6 and D20 level. In terms of outright wins.
PS the third player must score at least 3 to influence the contest.
Yes, because of the above, although for this case d20 and 3d6 should be equal because of the same point?PeroK said:You suspect wrongly!
If we take player 3 scores from 1 to 20 inclusive and run 100,000 games, the wins for D20 and 3D6 are:pbuk said:Yes of course, I missed that point.
Yes, because of the above, although for this case d20 and 3d6 should be equal because of the same point?
In fact [2, 2, 2, 36] will win 1/4 of the time with d20 and 3d6 each 3/8 (not counting ties)?
Counting ties...pbuk said:Yes of course, I missed that point.
Yes, because of the above, although for this case d20 and 3d6 should be equal because of the same point?
In fact [2, 2, 2, 36] will win 1/4 of the time with d20 and 3d6 each 3/8 (not counting ties)?
C:\>test2.pl
Player 1 (3d6) scores 38880 points
Player 2 (1d20) scores 38880 points
Player 3 (2,2,2,36) scores 25920 points
Player 1 (3d6) rolled a mean of 10.5 pips per roll
Player 2 (1d20) rolled a mean of 10.5 pips per roll
Player 3 (2,2,2,36) rolled a mean of 10.5 pips per roll
There were 17280 combinations with a total of 103680 points available
The total points awarded were 103680
Real programmers can write Fortran in any language.pbuk said:Your post would have received a like if it hadn't been in Perl
Here are the probabilities:PeroK said:You could actually compute the probabilities fairly easily, and prove the matter. I might try that now.
I disagree. In fact, those are the situations where theoretical calculations get so tricky that Monte-Carlo methods have a significant advantage. Even if one can get an analytical answer, I would not completely trust it if it did not agree with a Monte-Carlo simulation. I have seen examples in this forum where a very complicated thread eventually (after several days) arrived at the same answer that a 10 minute Monte-Carlo simulation gave.pbuk said:Indeed. For non-linear problems (and you can't get much more non-linear than win/lose) Monte-Carlo methods are not in general worthwhile.
It is easy to install in Windows. In fact, my experience is that some tools that I used on Windows machines had Perl as part of their installation.pbuk said:I suspect 3d6 may score better against [2, 2, 2, 36] (particularly if you only count clear wins) but I can't be bothered to fire up a Linux instance at the moment to test your Perl script
Boo! I have known people who have the silliest complaints about Perl. Perl has some significant advantages for many scripting applications.pbuk said:Your post would have received a like if it hadn't been in Perl
Here's a simple example of what I mean. The UK national lottery draw is six unique numbers 1..59 so the chance of a winning ticket is trivially 1 in ## {59 \choose 6} = 45,057,474 ##. How many Monte Carlo trials would you need to reliably get close to the analytic solution?FactChecker said:I disagree. In fact, those are the situations where theoretical calculations get so tricky that Monte-Carlo methods have a significant advantage. Even if one can get an analytical answer, I would not completely trust it if it did not agree with a Monte-Carlo simulation. I have seen examples in this forum where a very complicated thread eventually (after several days) arrived at the same answer that a 10 minute Monte-Carlo simulation gave.
Yes. Trivial problems are easier to solve analytically. I wish that I lived in a trivial world.pbuk said:Here's a simple example of what I mean. The UK national lottery draw is six unique numbers 1..59 so the chance of a winning ticket is trivially 1 in ## {59 \choose 6} = 45,057,474 ##. How many Monte Carlo trials would you need to reliably get close to the analytic solution?
If you think about it, the only way to get any accuracy would be to calculate the probability for each individual ball using a Monte Carlo method (with only 39 outcomes with the minimum frequency (for 2) better than 1 in 78 this should be computable with very high confidence of accuracy) and then use an analytic method to calculate the probability of any given choice. If you just go looking for that needle in the haystack you are still going to need billions of trials to reliably get anywhere near.FactChecker said:Now, suppose that every even number, n, tentatively picked, was rejected with a probability of 1/n. I can modify the Monte-Carlo simulation in a minute. How easy is the analytic solution?
And anlytically solvable problems can be solved analytically and feasibly enumerable problems can be solved by complete enumeration; in neither case are they better solved by Monte Carlo. Your argument is analagous to 'I have to bang in a lot of nails so whenever I need to fix a screw or a pop rivet I reach for the hammer'.FactChecker said:Yes. Trivial problems are easier to solve analytically. I wish that I lived in a trivial world.
Be careful. I have dealt with plenty of analytical methods in probability and statistics (although I admit that I am rusty).pbuk said:Your argument is analagous to 'I have to bang in a lot of nails so whenever I need to fix a screw or a pop rivet I reach for the hammer'.