# Perl Data Entry script to produce Bridge hands in PBN format # # Bob Crosby Jan 2003 Version 1.0 # $PBN="template.pbn"; $end = '"]'; open(DAT,">>$PBN") || die("Cannot Open File"); # $line1 = '[Event "Venice Cup"]' ; $line2 = '[Site "Edmonton:EBC"]' ; $line3 = '[Date "2003.06.05"]' ; $line4 = '[West "Dupont"]' ; $line5 = '[North "Crosby"]' ; $line6 = '[East "Garozzo"]' ; $line7 = '[South "Pitbull"]' ; # # Just as easy to edit the above in the file itself # print "Enter Board Number \n "; $number = ; $number =~ s/\s// ; $line8 = '[Board "' . $number . $end ; # print DAT "$line1\n"; print DAT "$line2\n"; print DAT "$line3\n"; print DAT "$line4\n"; print DAT "$line5\n"; print DAT "$line6\n"; print DAT "$line7\n"; print DAT "$line8\n"; # # Input the Bridge hands # $repeat = "Y" ; while ($repeat eq "Y" ) { print "Enter NORTH hand \n" ; $north = ; $north =~ s/\s/./g ; $north =~ s/.$// ; $repeat = uc &promptUser("Change the input ? (Y/N) ", "N"); } # $repeat = "Y" ; while ($repeat eq "Y" ) { print "Enter EAST hand \n" ; $east = ; $east =~ s/\s/./g ; $east =~ s/.$// ; $repeat = uc &promptUser("Change the input ? (Y/N) ", "N"); } # $repeat = "Y" ; while ($repeat eq "Y" ) { print "Enter SOUTH hand \n " ; $south = ; $south =~ s/\s/./g ; $south =~ s/.$// ; $repeat = uc &promptUser("Change the input ? (Y/N) ", "N"); } # $repeat = "Y" ; while ($repeat eq "Y" ) { print "Enter WEST hand \n" ; $west = ; $west =~ s/\s/./g ; $west =~ s/.$// ; $repeat = uc &promptUser("Change the input ? (Y/N) ", "N"); } # $deal ='[Deal "N:' ; # print DAT "$deal$north $east $south $west$end\n"; $line10 = '[Dealer "N"]' ; $line11 = '[Vulnerable "NS"]'; $line12 = '[Auction "N"]'; print DAT "$line10\n"; print DAT "$line11\n"; print DAT "$line12\n"; # # Input bidding # print "Enter Bidding & end with AP \n"; while ($bid !~ m/AP/) { $bid = ; print DAT "$bid" ; } print "Enter Contract \n " ; $contract = ; $contract =~ s/\s// ; $line14 = '[Contract "' . $contract . $end ; print DAT "$line14 \n"; # $line15 = '[Declarer "S"]' ; $line16 = '[Play "W"]' ; print DAT "$line15 \n"; print DAT "$line16 \n"; # # Display hands # $north =~ s/\./ /g ; $east =~ s/\./ /g ; $west =~ s/\./ /g ; $south =~ s/\./ /g ; print " $north \n"; print "\n" ; print "$west $east \n" ; print "\n" ; print " $south \n"; print "\n" ; # # Input the play # print "Enter Play & end with an * \n"; print " W N E S \n" ; while ($play !~ m/\*/) { $play = ; print DAT "$play" ; } print "Enter result \n " ; $result = ; $result =~ s/\s// ; $line17 = '[Result "' . $result . $end ; print DAT "$line17 \n"; print DAT "\n" ; # # PBN file completed # PBN comments done by editing PBN file # close(DAT); sub promptUser { #-------------------------------------------------------------------# # two possible input arguments - $promptString, and $defaultValue # # make the input arguments local variables. # #-------------------------------------------------------------------# local($promptString,$defaultValue) = @_; #-------------------------------------------------------------------# # if there is a default value, use the first print statement; if # # no default is provided, print the second string. # #-------------------------------------------------------------------# if ($defaultValue) { print $promptString, "[", $defaultValue, "]: "; } else { print $promptString, ": "; } $| = 1; # force a flush after our print $_ = ; # get the input from STDIN (presumably the keyboard) #------------------------------------------------------------------# # remove the newline character from the end of the input the user # # gave us. # #------------------------------------------------------------------# chomp; #-----------------------------------------------------------------# # if we had a $default value, and the user gave us input, then # # return the input; if we had a default, and they gave us no # # no input, return the $defaultValue. # # # # if we did not have a default value, then just return whatever # # the user gave us. if they just hit the key, # # the calling routine will have to deal with that. # #-----------------------------------------------------------------# if ("$defaultValue") { return $_ ? $_ : $defaultValue; # return $_ if it has a value } else { return $_; } }