#!/usr/bin/perl -w use strict; # practice.pl - Copyright 2020 Pete Matthews Jr # Version By Description # 2020-02-29 PDM Deal practice hands to meet programmed requirements my $PGM = "practice.pl"; # change values here my $VERSION = "$PGM version 2020-02-09"; my $DEBUG=1; my $Dealer="S"; my $Vulnerable="None"; #----------------------------------------------------------------# my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$tsdst) = localtime(time); $year += 1900; $mon++; my $DATE = "$year.$mon.$mday"; #----------------------------------------------------------------# sub Prepend() { print OUTFILE <<"EoP" % PBN 2.1 % EXPORT %Content-type: text/x-pbn; charset=ISO-8859-1 %Creator: BridgeComposer Version 5.76 %Created: Thu Jan 16 22:26:45 2020 -0500 %BCOptions Center GutterH STBorder STShade %BidAndCardSpacing Thin %BoardsPerPage 1 %CardTableColors #cccccc,#ffffff,#999999 %EventSpacing 0 %Font:CardTable "Arial",11,400,0 %Font:Commentary "Times New Roman",12,400,0 %Font:Diagram "Times New Roman",12,400,0 %Font:Event "Times New Roman",12,400,0 %Font:FixedPitch "Courier New",10,400,0 %Font:HandRecord "Arial",11,400,0 %GutterSize 500,500 %HRTitleDate $DATE %HRTitleEvent "" %HRTitleSetID "" %HRTitleSetIDPrefix "" %HRTitleSite "" %HtmlClubs native,"https://bridgecomposer.com/suitimg/c.gif" %HtmlDiamonds native,"https://bridgecomposer.com/suitimg/d.gif" %HtmlHearts native,"https://bridgecomposer.com/suitimg/h.gif" %HtmlNavBar 0.75,#cfe2f3 %HtmlSpades native,"https://bridgecomposer.com/suitimg/s.gif" %Margins 500,500,500,500 %PaperSize 1,2159,2794,2 %ParaIndent 0 %PipColors #000000,#000000,#000000,#000000 %PipFont "Cards","Cards",0,0x73,0x68,0x64,0x63 %ScoreTableColors #e6e6e6,#000000 %SelectedBoard 3 %ShowBoardLabels 2 %ShowCardTable 2 %TSTCustomSortOrder Default %TSTReport List %TSTReportOrder ByNumber %TSTReportShade Yes EoP } #----------------------------------------------------------------# sub Usage() { # 1 2 3 4 5 6 7 #234567890123456789012345678901234567890123456789012345678901234567890123456789 print <<"EndUsage"; $VERSION Usage: $PGM [-n] -n Do not create NAME.pbn (only NAME.txt). This optional switch is used for opening lead problems. NAME The NAME of existing .tcl file and resulting .txt and .pbn files. Also used as the Event (deal title) in .pbn. The NAME on the command line will be uppercased, so NAME in .tcl should be upper case for consistency. count The number of deals to be created in each output file (default 100). This script generates "count" deals as specified within the .tcl program. The result will be the file .pbn, intended to be read in by Bridge Composer. The file should then be printed as a "curtain card" for bidding practice. Note: All components must be in the current directory, including the Deal program by Thomas Andrews, which this script employs. Each line of .txt will contain the PBN specification for one deal. This work file is preserved until the next run with the same . Create the .tcl script with a text editor. It is used to select full deals and write them to the work file. It must define a "write_deal" procedure for one PBN deal per line. The function of the $PGM script is relatively simple. The smarts are in .tcl. $PGM runs .tcl times, to produce deals in .txt. Once this phase has been completed, $PGM reads the whole file, writing each deal with boilerplate into .pbn. Reference: http://bridge.thomasoandrews.com/deal/ EndUsage # 1 2 3 4 5 6 7 #234567890123456789012345678901234567890123456789012345678901234567890123456789 exit 1; } #----------------------------------------------------------------# sub MakeOutputFile ($$$) { my ($WORKFILE, $OUTFILE, $NAME) = @_; my $Board=0; my $first=1; ($DEBUG) && print STDERR " WORKFILE=$WORKFILE, OUTFILE=$OUTFILE\n"; # -- Check File Existence ( -e $WORKFILE ) || die "--> work file does not exist: $WORKFILE <--"; open (WORKFILE, "<", $WORKFILE) or die "--> unable to open work file to read: $WORKFILE <--"; open (OUTFILE, ">$OUTFILE") or die "--> unable to open output file: $OUTFILE <--"; Prepend; # -- Read input, one deal per line, copy to output with editing while () { my $Deal = $_; # skips first line ??? if ($first) { $first = 0; } else { print OUTFILE "\n"; } print OUTFILE "\[Event \"$NAME\"\]\n"; print OUTFILE "\[Site \"\"\]\n"; print OUTFILE "\[Date \"$DATE\"\]\n"; $Board++; print OUTFILE "\[Board \"$Board\"\]\n"; print OUTFILE "\[West \"\"\]\n"; print OUTFILE "\[North \"\"\]\n"; print OUTFILE "\[East \"\"\]\n"; print OUTFILE "\[South \"\"\]\n"; print OUTFILE "\[Dealer \"$Dealer\"\]\n"; print OUTFILE "\[Vulnerable \"$Vulnerable\"\]\n"; print OUTFILE $Deal; print OUTFILE "\[Scoring \"\"\]\n"; print OUTFILE "\[Scoring \"\"\]\n"; print OUTFILE "\[BCFlags \"1f\"\]\n"; } ($DEBUG) && print STDERR " Board=$Board\n"; close (WORKFILE); close (OUTFILE); } #----------------------------------------------------------------# sub MakeWorkFile ($$$) { my ($TCLFILE, $WORKFILE, $Count) = @_; ($DEBUG) && print STDERR " TCLFILE=$TCLFILE, WORKFILE=$WORKFILE, Count=$Count\n"; my $x; # -- Assure Work File does not exist (take no prisoners) if (-f $WORKFILE) { unlink ($WORKFILE) or die "unable to remove $WORKFILE\n"; } # -- Run Existing Tcl script under Deal program system ("deal -i $TCLFILE $Count \> $WORKFILE") and die "Error creating $WORKFILE \n"; } #----------------------------------------------------------------# # -- Process command line arguments ($DEBUG) && print STDERR "#ARGV=$#ARGV\n"; ($#ARGV >= 0) or Usage; my $PBN = 1; my $NAME = uc (shift @ARGV); if ($NAME eq "-N") { # this kludge does not scale $PBN = 0; ($#ARGV >= 0) or Usage; $NAME = uc (shift @ARGV); } my $Count = shift @ARGV; defined($Count) or $Count = 100; my $TCLFILE = "$NAME.tcl"; my $WORKFILE = "$NAME.txt"; my $OUTFILE = "$NAME.pbn"; # -- Run the Tcl file to make the deals in the work file, one per line (-f $TCLFILE) or die "Tcl script not found: $TCLFILE\n"; MakeWorkFile ($TCLFILE, $WORKFILE, $Count); # -- Write the deal files into a full PBN file if ($PBN) { MakeOutputFile ($WORKFILE, $OUTFILE, $NAME); print STDERR "$OUTFILE complete.\n"; } else { print STDERR "$WORKFILE complete, $OUTFILE skipped (-n).\n"; } exit 0;