Wednesday, August 19, 2020

Generating BBO files (.lin format files) using Thomas Andrews dealer

Thomas Andrews' dealer http://bridge.thomasoandrews.com/deal/ is, to my mind, the best bridge dealer out there and one I use extensively. It has a number of cool features but the one feature I love about it is that it is extensible in every imaginable way. One way you can extend it is by defining your own output formats.  In this blog post I will provide you with a tool to customize its output so that you can generate tailored hands that can then be loaded for play on BBO, the popular online Bridge platform (https://www.bridgebase.com)

Suppose, for example that you want to generate hands where North has 13 or more High Card Points(HCP).  You would then write a simple tcl script called example.tcl that looks like this:

 

main {

    if { [hcp north] >= 13 } {
        accept
    }
    reject
} 

Then when you execute this script by running the command deal -i example.tcl, the dealer generates hands where North has 13 or more HCP

By default, its output looks like this: 

 

          ♠ J74
          ♥ 3
          ♦ AQJ3
          ♣ AQT54
 ♠ AQ              ♠ T9653
 ♥ AT962           ♥ K74
 ♦ 9               ♦ T75
 ♣ KJ832           ♣ 96
          ♠ K82
          ♥ QJ85
          ♦ K8642
          ♣ 7
--------------------------
          ♠ QJ6
          ♥ AQ72
          ♦ KQ85
          ♣ 83
 ♠ AT432           ♠ K875
 ♥ 3               ♥ 8654
 ♦ 972             ♦ 63
 ♣ QT64            ♣ AJ2
          ♠ 9
          ♥ KJT9
          ♦ AJT4
          ♣ K975
 

Let us now suppose that you want to instead generate similar hands and use these to practice bidding with your partner on BBO.  BBO allows you to use your own hands - however these hands need to be in BBO's proprietary "lin" format which takes some learning, to put it mildly.  Unfortunately the dealer does not have any out-of-the-box mechanism for generating files that BBO can consume.  This is where the dealer's extensibility comes to our rescue.  You can extend the dealer's capability with  a simple piece of code that I am sharing here.

Here is the code to generate output in a lin format:

proc write_deal {} {
foreach hand {north east south west} {
set fmt($hand) "S[$hand spades]H[$hand hearts]D[$hand diamonds]C[$hand clubs]"
}
set handstring "$fmt(south),$fmt(west),$fmt(north),$fmt(east)"
# Need to add logic to calculate dealer and vulnerability
# For now we have set it so deal number is always 1
set dealno 1

# Dealer = 1,2,3,4 South, West, North and East respectively
set dealer 3
# Vul can be one of 'e', 'n', 'b' or ''
set vul ""
set msg "Deal $dealno"
puts "qx|o1|pn|South,West,North,East|st||md|$dealer$handstring,|rh||ah|$msg|sv|$vul|pg||"
}

To use, this code, do the following:

  • cd dealdir (this is the directory containing the dealer program called "deal") 
  • Locate the directory called "format" under it.  For example, on Windows it will probably be the directory windows\format.  Paste the above code in a file called "lin" in that directory
  • Add a directive inside your source file to source this file (see below) and you are all set

This is how your code will look like with this change (the one line addition to your original script is highlighted in purple in the code below):

source format/lin 
main {

    if { [hcp north] >= 13 } {
        accept
    }
    reject
}

Once you have done this, the same script will output something that looks like this:

qx|o1|pn|South,West,North,East|st||md|3S87HT5DT963CKQJ84,SQ3HK98762DKQ875C,SKJ964HAJ3DA42C53,SAT52HQ4DJCAT9762,|rh||ah|Deal 1|sv||pg||
qx|o1|pn|South,West,North,East|st||md|3SQJT64H843DJCA953,SA8752HQJTDT62C84,SK93HAK9DAKQ874CQ,SH7652D953CKJT762,|rh||ah|Deal 1|sv||pg||
qx|o1|pn|South,West,North,East|st||md|3SKHJ654DK9872CJ42,SQJ532HA987DT6CT6,SAT98HQ32DAJ54CA8,S764HKTDQ3CKQ9753,|rh||ah|Deal 1|sv||pg||
 

Save the output to a file and then upload that file to your BBO account. You can now actually bid/play with these newly generated hands on BBO.  For instructions on how to upload the file to BBO, see https://www.bridgebase.com/forums/topic/70978-how-to-upload-lin-file-from-handgenerator-for-teammatch.


Hope this blog post helps you.  Happy bridging!!!