use strict; if (!@ARGV) { print STDERR "Usage: pbn2lin.pl pbnfile boardnumber contract decl\n"; exit(1); } my ($pbn, $board, $contract, $decl) = @ARGV; $contract = uc($contract); $decl = uc($decl); my $found = 0; my $done = 0; my %hand; my @c = ('S', 'H', 'D', 'C'); my @d = ('S', 'W', 'N', 'E', 'S', 'W', 'N', 'E'); my @longd = ('North', 'East', 'South', 'West'); open (PBNFILE, $pbn) or die "Can't open $pbn"; while() { next if ($done); chomp; # parse an .obs file hand record if (m/^\[Board "(\d+)"/) { $found = ($board == $1); } next if (!$found); if (m/^\[Deal /) { my @seats = split /[ :\"]/; splice (@seats, 0, 2); # remove first 2 my $startseat = shift @seats; # what seat hand starts at my $di = index('SWNE', $startseat); foreach my $seat (@seats) { my $hn = $d[$di++]; my @s = split /\./, $seat; foreach my $j (0,1,2,3) { $hand{$hn} .= "$c[$j]$s[$j]"; } } } $done = 1 if (m/^\[Result /); } my $decl_at_bottom=1; my $dealernum; my $di; if ($decl_at_bottom) { $dealernum = 1; $di = index('SWNE', $decl); } else { # make dealer be same as declarer $dealernum = index('SWNE', $decl) + 1; $di = 0; } print "pn|South,West,North,East|st||st||md|$dealernum$hand{$d[$di]},$hand{$d[$di+1]},$hand{$d[$di+2]},$hand{$d[$di+3]}| rh||ah|Board $board, $pbn|sv|o|mb|$contract|mb|p|mb|p|mb|p |at|Click ^\$40 to start, Use ^\$6 to take back the last card that you played. |pg||pf|y| ";