#!/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;
};
};