BASIC STRING MANIPLUATION TO ROTATE BRIDGE HANDS
To manipulate the lin file in excel, you have to work with text strings (the entire handviewer thing you cut and paste into excel is a single text string).
Label the following excel cells
A1: Forum post
B1: Comments
C1: DLR
D1: Decl
E1: Vul
F1: cDLR
G1: cDecl
i1: http hand
Paste some handviewer hand record into cell i2.
The first thing you need to know when rotating a file is who dealt the original hand, and who is the declarer (or which position) you want to be declarer. The next thing you need to know is what is the vulnerability.
Let's start with who dealt the hand. This is easy, we will call the four plays 1, 2, 3, and 4 where 1=south, 2=west, 3=north, and 4=East.
This equation will extract into a cell for who is dealer. Enter this equation into cell C2
=MID(i2,SEARCH("%7Cmd",i2)+8,1) (where I2 is where you pasted your hand record). This returns a 1, 2, 3 or 4.
To extract the vulnerability you can use this equation Enter this equation into cell E2
=MID(i2,SEARCH("%7Cmb",ci)-1,1) (where i2 is where you pasted your hand record). This returns a 0, e, n, b. When rotating hands, you don't need to change the vul if it is 0 on b, and you only need to change the "e" to "n" or "n" to "e" if you rotate the hand one or three steps. If you rotate is 0 or 2 steps, no vulnerability change is needed.
So when I rotate hands, I have one cell with the Actual declarer position when the hand was played. There will be ways to automate this, but the easiest is when you paste a hand into excel, enter the real declarer position as either "N", "E", "W", "S". So enter the real declarer position into cell D2.'
The automation assumes you want declarer to be "south" so it will rotate the hands depending upon which letter you enter here. Before we get to how to handle the actual hands during rotating, lets examine how we calculate what the vulnerability will be after the hands are rotated. Lets make a few assumptions. First if when we rotate the hands, the dealer will have to change. We show the new dealer in cell F2 using the following equation.
=ABS(C2-IF(D2="S",0,IF(D2="W",1,IF(D2="N",2,3))))
In cell G2, we correct the vulnerability for the rotated hand using this equation.
=IF(OR(E2="b",E2="0"),E2,IF(ISEVEN(C2-F2),E2,IF(E2="e","n","e")))
The equations above get you ready to rotate the hand. The actual part of the hands that need to be rotated are the cards. As you may know the cards are stored in the order of South's hand,West hands,north hands,East hand. Actually the east hand is not given to us on the current bbo search engine (handviewer calculates the last 13 cards for you). So what we need do is: if West is the original declarer, change the hand record so they are in this order (original positions retained in title (west,north,east,south), and if North is the dealer (north,east,south,west), and finally if east is the dealer (east,south,west,north).
This means based upon the original declarer, you need to extract the hands. Let's take a simple example. West is the declarer. So you will want to start the hand record by removing the south hand from the beginning of the string, and reinserting it at the end of the hand string. One way to do this is to first, extract the string that represents all four hands in the correct order. Let's call this the SWNE order. The following equation (in cell M2 will do just that, again where i2 is the http hand record...
=CONCATENATE(LEFT(RIGHT(I2,LEN(I2)-SEARCH("md%7C",I2)-5),60),) this returns (the %2C's are not a mistake).
S46JQAH89AD26C6TJ%2CS357H56JD578TC457%2CS8TH34TD9JKC238KA%2C
Now to get the sequence WNES, NESW, and ESWN you can just lob off the first hand each time and add it back to end in cells N2, O2, and P2
N2 contains: =CONCATENATE(RIGHT(M2,40),",",LEFT(M2,17))
O2 contains: =CONCATENATE(RIGHT(N2,38),",",LEFT(N2,17))
P2 contains: =CONCATENATE(",",LEFT(M2,57))
Excel will "pick" the correct version of the hands (SWNE, WNES, NESW, or ESWN) based upon the value in "DECLARER" column (cell D2 in this example). Normally I would include this pick in the equation in cell A2, but here to show how it is done, lets put the following equation in cell L2
=IF(D2="S",M2,IF(D2="W",N2,IF(D2="N",O2,P2))) This equation effectively rotates the "Declarer" as identified in Cell D2 to "south".
Reconstruct the lin file information. After gathering all the pieces (vul, dealer, cVul, cDel, hands rotated for all positions), it is time to put the pieces together, along with any comments by the following equation in cell A2
=CONCATENATE("[hv=lin=md|",F2,L2,"|st||sv|",G2,"|m",RIGHT(I2,LEN(I2)-SEARCH("mb%7C",I2)),"]400|300|",B2,"[/hv]")
That will create the handviewer example shown above with the bidding, hands, vulnerability, play all corrected for the rotated hand. Let's break out what each part of the equation does.
=CONCATENATE("[hv=lin=md|", <--- this part sets calls the handviewer applet to display the lin hand, the md| part replaces needed things stripped out.
F2, <-- inserts the corrected dealer from cell F2
L2, <-- inserts the rotated hands based on who is declarer from cell L2
"|st||sv|", <-- inserts some needed text to set up the correct vulnerability
G2, <--- Inserts the correct vulnerability (0, n, e, b) based on the rotated had
"|m", <-- adds a piece of text needed to start the bidding
RIGHT(I2,LEN(I2)-SEARCH("mb%7C",I2)), <-- inserts all the bidding and play from the hand
"] 400|300|", <-- sets the size of the hand diagram
B2, <-- adds any comments you may have made about the hand in cell B2
"[/hv]") <-- closes the handviewer applet that the hv tag opens.
You can copy the field to subsequent rows and to keep multiple rows each one handling one hand. Thousands of hands could be on one spreadsheet.
No one needs type the equations into excel. If you are interested in this specific use of excel, I will be glad to email you a spreadsheet described as above. The point was to show how to manipulate the text strings.
Next we show how to build a "bridgebrowser" type datatbase spreadsheet that allows you find your hands based upon your opening bid, opponents bid, partners response, openers rebid, responders second bid. combinations of those, final contract, opening lead, your hcp, etc. I am certain the equations I use in building the various parts of the database could use some improvement (mine work, there are going to be more elegant solutions, however, I am sure).
If you wanted to display the rotated hand in a modern browser, you could make a slight change to a copy of cell A2 which you paste in cell K2. Here is the equation
CONCATENATE("htp://www.bridgebase.com/tools/handviewer.html?lin=md|",F2,L2,"|st||sv|",G2,"|m",RIGHT(I2,LEN(I2)-SEARCH("mb%7C",I2)))