CreateDealType: Adding New Deal Types

CreateDealType is a BridgeComposer script that you may use to create random deals of various "types", such as Strong 1NT openers, splinter bids, and slam hands.

You may add new deal types (coded in JavaScript) to the file BCScript\CDT\xxxFilters1.js:

xxxFilters1.js screenshot

JavaScript Notes

A JavaScript reference is available at Below, we explain the JavaScript code above.

First, pick a name for your function. The name will be used only twice: once in your function declaration (line 7 in the example above), and immediately following the declaration in an AddFilter function call (line 20). Any name may be used as long as it is not a JavaScript reserved word and it has not already been used in the CreateDealType-related scripts. For these reasons, we suggest that you begin the name with your initials. In any event, the name must begin with a letter and consist only of letters, numbers, and the underscore character.

The body of your function is enclosed in braces (lines 8 and 18).

Global variables that may be used in your function are defined in BCScript\CDT\CdtGlobal.js. In particular, the variables N, E, S, and W contain the North, East, South, and West hands of a random board to be considered. The Hand object is declared in the file BCScript\BCDeal.js, and has the following members:

Hand object
suitan array of four Suit objects
hcpthe total high card points in the hand
isBalanced()function returning true if the hand has balanced shape
hasCard(card)function returning true if the hand contains a specified card
longest()function returning the index of the longest suit (0, 1, 2, or 3)


Each Suit object has the following members:

Suit object
cardarray of strings (each of length 1) giving the card ranks held
lengththe number of cards held
hcpthe total high card points of the cards held


If your function returns true, the board will be placed in the BridgeComposer document (line 17); if your function returns false, the board is discarded (lines 10 through 14).

The variables SPADES, HEARTS, DIAMS, and CLUBS are just constants (equal to 0, 1, 2, and 3, respecively). They are used to select a Suit object from the array of four Suit objects in each Hand object.

The punctuation used in the body is as defined by JavaScript. Here are the meanings of some commonly used symbols:

JavaScript Operators and Punctuation of Interest Here
/*Begin comment block: everything up to the next */ is ignored by JavaScript
*/End comment block
//Begin comment: everything up to the end of the current line is ignored by JavaScript
;Statement separator: marks the end of a statement; a new statement follows
{...}Statement group: the statements surrounded by braces are grouped together
.Member reference: In "variable.member", the named member belonging to the variable is referenced
||Logical OR operator
&&Logical AND operator
!Logical NOT operator
===Identical to (avoid ==, equal to, as it may perform unexpected conversions)
<Less than
>Greater than
<=Less than or equal
>=Greather than or equal
[...]Subscript: The number enclosed is used to select a particular object from an array of objects
=Assignment: the value on the right is stored into the variable on the left



Line 7: Declares the function, using a name determined as described above.

Line 9: A comment describing the type of deals the function will select.

Line 10: An if statement. The syntax of the if statement is:

if (condition) statement;

When the condition expression evaluates to true (or any nonzero value), the statement is performed. Otherwise, the statement is skipped.

The first term in the condition is S.hcp. As described above, S is the South Hand object, and hcp is the member giving the high card point count.

Then there is the < operator (less than) and the number 15. All together, this evaluates as true if the South high card points are less than 15.

Then there is the || operator (logical OR), which we'll skip for a moment.

Then there is S.hcp > 17, which evaluates as true if the South high card points are greater than 17.

Now back to || (logical OR). It operates on the two expressions on either side of it, and evaluates as true if either of the two expressions (or both) are true. (It evaluates as false if and only if both expressions are false.)

Putting it all together, the condition is true if the South high card points are less than 15 or greater than 17. In that case, the statement is performed, that is, return false;. The return statement exits the function and specifies its value. In other words, for any random deal, if South does not have 15 to 17 high card points, the deal is rejected. If South does in fact have 15 to 17 high card points, the return statement is not performed, and the function continues with the next line.

Line 11: Similarly to line 10, this line rejects the deal if North has less than 10 high card points.

Line 12: This line rejects the deal if the South hand is not balanced (4-3-3-3, 4-4-3-2, or 5-3-3-2 shape). Remember that ! is the logical NOT operator.

Line 13: The first line of a longish if statement that is split onto two lines. Remember that S.suit is an array of four Suit objects; S.suit[SPADES] references the spade Suit object in the South hand. .length is a member of the Suit object that gives the number of cards in that suit. This expression is true when South holds five or more spades. A logical OR operator sits between this expression and the expression on the next line.

Line 14: The second line of an if statement. The expression is true when South holds five or more hearts. The condition of the whole if statement is true when South holds either five or more spades or five or more hearts. In that case, return false; is performed and the deal is rejected.

Line 16: Assigns the string '1NT' to the global variable strAuction. This causes a partial Auction to be displayed by BridgeComposer for the deal, in which the dealer opens 1NT.

Line 17: We return the value true, which causes this random deal to be selected.

Line 18: The closing brace ends the function declaration.

Line 20: The AddFilter call registers our new function, so it will be listed in the deal type selection menu and it will be called when selected. See the complete description of AddFilter in BCScript\CDT\CdtGlobal.js. CDT1 is a "style" constant, currently specifying that South is the dealer by default. xxx1ntgg is the function name; substitute the name you picked for your function. The two strings are the group and type that are displayed in the deal type selection menu when the script starts up, and in the Event field of each selected board.

Script Help

If you try to modify the script but run into problems, you may email your script to to get help.

However, note that for security reasons, most email providers do not permit emailing scripts! Therefore, to attach a script to an email, first change the file extension from .js (or .wsf) to .txt. After receiving a script email attachment, save it and then change the extension from .txt back to .js (or .wsf). See File Extensions for further information.

DISCLAIMER: Software from this site is provided "as is". In no event shall the author be liable to you or any third party for any damages of any kind arising out of or relating to the software or the use thereof.