3
# This script reformats the output of Descr.test_dealer into a nice
4
# table, with the theoretical values next to the hcp and suit distributions
7
# This is not the best piece of Perl that I've ever written.
10
# Frequency of suit lengths and hcp help by players. From Frederic H. Frost,
11
# "Bridge Odds Complete".
13
@suitlen = (1.27, 8.01, 20.59, 28.63, 23.87, 12.47, 4.16, 0.88, 0.12, 0.01, 0,0,0);
14
@rawhcp = (0.36, 0.79, 1.35, 2.46, 3.85, 5.19, 6.55, 8.03, 8.89, 9.36, 9.41, 8.94, 8.03, 6.91, 5.69, 4.42, 3.31, 2.36, 1.61, 1.04, 0.64, 0.38, 0.21, 0.11, 0.06, 0.03, 0.01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
16
$player_to_int{"N"} = 0;
17
$player_to_int{"E"} = 1;
18
$player_to_int{"S"} = 2;
19
$player_to_int{"W"} = 3;
20
$suit_to_int{"Spades"} = 0;
21
$suit_to_int{"Hearts"} = 1;
22
$suit_to_int{"Diamonds"} = 2;
23
$suit_to_int{"Clubs"} = 3;
24
$suit_to_int{"S"} = 0;
25
$suit_to_int{"H"} = 1;
26
$suit_to_int{"D"} = 2;
27
$suit_to_int{"C"} = 3;
28
$rank_to_int{"T"} = 10;
29
$rank_to_int{"J"} = 11;
30
$rank_to_int{"Q"} = 12;
31
$rank_to_int{"K"} = 13;
32
$rank_to_int{"A"} = 14;
39
($dummy, $dummy, $player) = split (/\s+/, $_);
40
$player = $player_to_int{$player};
41
for ($i=0; $i<38; $i++) {
43
($dummy, $dummy, $freq) = (split /\s+/, $_);
44
$hcp[$i][$player] = $freq;
46
} elsif ($_ =~ "Frequency Card") {
47
($dummy, $dumy, $player, $card) = (split /\s+/, $_);
48
$player = $player_to_int{$player};
49
$suit = $suit_to_int {substr($card, 0, 1)};
50
$rank = substr($card, 1, 1);
51
if (defined $rank_to_int{$rank}) {
52
$rank = $rank_to_int{$rank};
56
($dummy, $dummy, $count) = split (/\s+/, $_);
57
$hascard[$player][$suit][$rank] = $count;
58
} elsif ($_ =~ "Frequency") {
59
($dummy, $suit, $player) = split (/\s+/, $_);
60
$player = $player_to_int{$player};
61
$suit = $suit_to_int{$suit};
62
for ($i=0 ; $i<13; $i++) {
64
($dummy, $dummy, $freq) = split (/\s+/, $_);
65
$suit[$i][$player][$suit] = $freq;
67
} elsif ($_ =~ "Generated") {
68
($dummy, $constant, $dummy) = split (/\s+/, $_);
72
print "Generated $constant hands\n\n";
75
print "HCP Distribution\n================\n";
77
print " % diff % diff % diff % diff\n";
79
for ($i=0 ; $i<38 ; $i++) {
81
for ($j=0 ; $j<4; $j++) {
82
printf ("%5.2f ", $hcp[$i][$j]/$constant);
83
printf ("%6.3f ", $hcp[$i][$j]/$constant- $rawhcp[$i]);
85
printf ("%5.2f", $rawhcp[$i]);
89
foreach $k ("Spades", "Hearts", "Diamonds", "Clubs") {
90
print "\n$k Distribution\n=====================\n";
92
print " % diff % diff % diff % diff\n";
93
$k1 = $suit_to_int{$k};
94
for ($i=0 ; $i<14 ; $i++) {
96
for ($j=0 ; $j<4; $j++) {
97
printf ("%5.2f ", $suit[$i][$j][$k1]/$constant);
98
printf ("%6.3f ", $suit[$i][$j][$k1]/$constant-$suitlen[$i]);
100
printf ("%5.2f", $suitlen[$i]);
105
print "\nIndividual Cards\n================\n";
107
print " Spades Hearts Diamonds Clubs\n";
108
print "# N E S W N E S W N E S W N E S W\n";
110
for ($rank = 2 ; $rank < 15 ; $rank++) {
112
printf ("%s ", substr("23456789TJQKA", $rank-2, 1));
113
for ($suit = 0 ; $suit < 4; $suit++) {
115
for ($player = 0 ; $player < 4 ; $player++) {
116
printf ("%5.2f ", $hascard [$player][$suit][$rank]/$constant-25.00);