@board = qw(GO A1 CC1 A2 T1 R1 B1 CH1 B2 B3 JAIL C1 U1 C2 C3 R2 D1 CC2 D2 D3 FP E1 CH2 E2 E3 R3 F1 F2 U2 F3 G2J G1 G2 CC3 G3 R4 CH3 H1 T2 H2);
@cc = qw(0 10 X X X X X X X X X X X X X X);
@chance = qw(0 10 11 24 39 5 R* R* U* -3 X X X X X X);
$samp = 2000000;
$pos = 0;
for (1..$samp) {
$roll = roll();
if ($roll >0) {
	$pos = ($pos + $roll) % 40;
	if ($board[$pos] =~ /CH/)
	{
		$card = $chance[int(rand(15))];
		if ($card<0) {$pos-=$chance[$card]}
		elsif ($card eq 'R*') {$pos = next_rr()}
		elsif ($card eq 'U*') {$pos = next_util()}
		else {$pos = $card unless $card eq 'X'}
	}
	if ($board[$pos] =~ /CC/)
	{ 
		$card = $cc[int(rand(15))];
		$pos = $card unless $card eq 'X';
	}
	if ($board[$pos] eq 'G2J') {$pos = 10}
} else { $pos = 10 }

$tally{$board[$pos]}++
}

print "Sample size: $samp\n";
print "Frequency for each space\n";
print "$_, $tally{$_}, ",$tally{$_}/$samp*100,"\n" for (sort {$tally{$a}<=>$tally{$b}} keys %tally);

sub next_rr { return $pos==7? 15 : $pos==22? 25 : 5 }
sub next_util { return $pos==22? 28 : 12 }

sub roll { 
$d1 = int(rand(4))+1; 
$d2 = int(rand(4))+1; 
$d = ($d1==$d2)? $d+1 : 0;
return $d>0 && $d%3==0? -1 : $d1+$d2;
}
