Skip to content

Contract bridge system analysis tool for making the most out of your system book.

License

Notifications You must be signed in to change notification settings

kdblocher/bridge

Repository files navigation

Tests Build CI/CD

Contract Bridge System Analysis Tool

System analysis tool for the game of Contract Bridge. Build a system book using human-readable syntax, and let the app get to work.

Created with Create React App, using the Redux and Redux Toolkit template. Huge shout-out to Giulio Canti for his amazing fp-ts library, without which this app's code would be much more verbose.

Demo

Try it out.

License / Contributing

The project is still in its nascent stages, and code is highly subject to change. Furthermore, the author makes heavy use of higher-order functional programming techniques and will not accept pull requests that do not follow this paradigm.

If you still want to contribute, please read the license and contributing guidelines before submitting a PR. Happy hacking!

Documentation

Bidding Syntax

The system is comprised of a bidding tree, written in outline form. The top-level bullets are openings bids, and each level of nesting below represents a responding bid by partner (2nd level is opening responses, 3rd is opener rebids, etc.)

Each line should be of the following form:

{Bid}: {Constraint}+

The tool will attempt to parse each line into a [set of] constraints, which it then uses to match hands against it.

Basic Examples

  • 1C: 11-21 3+C (Bid 1♣ with 11-21 HCP and 3 or more clubs)
  • 1N: 15-17 BAL (Bid 1NT with 15-17 HCP and a balanced hand)
  • P: 0-5 (Pass with 0-5 HCP)

Constraint Options

Name Syntax Description Examples
Point Range min - max
max -
min +
Holds if the HCP of the hand falls between min and max (inclusive). 12-14
7-
22+
Suit Range min - max s
max - s
min + s
Holds if the length of suit s falls between min and max (inclusive). M and m are allowed to specify majors or minors, respectively. 2-3H
4-S
6+C
Suit Comparison s1 op s2
op := < <= = >= >
Holds if the comparison between the lengths of suits s1 and s2 is true. C>D
Distribution BAL
semiBAL
unBAL
Holds if the hand distribution is balanced, semi-balanced (includes balanced), or unbalanced (not balanced or semi-balanced), respectively.
Set Trump s Flags s as the trump suit for the partnership. Always holds. S1
Primary s 1 Holds if s is 5+ cards, longer than higher-ranking suits and at least as long as lower-ranking suits. H1
Secondary s 2 Holds if s is 4+ cards, up to the length of the primary suit, but longer than the remaining two suits. C2
Honors s h... Holds if s_ has all of the specific honor(s) h (any of AKQJT). SAK
Top X of Y s x / y Holds if s contains the top x ranking cards out of the top y. S2/3 (AK/AQ/KQ)
Shape n n n n
n1 n2 n3 n4 *
Holds if the hand distribution is exactly n (for each suit).
Holds if the hand distribution is n for any order of suits.
4522 (3♥ rebid after Flannery)
4441* (Multi 2♦)
Response F1
FG
FS
Marks the bid as forcing for one round, to game, or to slam (respectively).
Relay -> b Marks the bid as a relay to bid b.
Bids accepting the relay may simply name the bid without : ... to automatically accept the relay.
2N: ->3C
   3C (accepts relay)
Other Bid b Holds when an alternative bid b at the same level holds. (This is useful combined with the not / ! operator.) 1H: 5+H !1N (don't bid 1♥ when 1NT is available)
Otherwise else Holds when all other bids above it do not. 1N: else 5-12 F1 (forcing NT response)
Conjunction c1 · c2 ... Holds if all constraints hold. 11-15 4S 5H
Disjunction c1 · or · c2 ... Holds if any constraint holds. 4414 or 4405 or 4315 or 3415
Negation not · c
! · c
Holds when c does not. not (14-15 BAL)
Grouping (c) Syntactic grouping of constraints c. 6+C or (5+C 4M)
(5-10 6+M) or (4441* 17-24)
Constant true
false
Trivially holds (or not), respectively.
  • "·" denotes a syntactic space between the terms in the syntax above. If there is no dot, do not space the terms.)
  • "..." denotes terms that can be repeated indefinitely.

Example Bidding Systems

2/1 starter

Notrump responses

Hand Syntax

Hands are entered in PBN syntax (see 3.4.11 for the full specification). They take the form {S}.{H}.{D}.{C} where each suit has zero or more single-digit rank identifiers (in any order): AKQJT98765432. (There must always be exactly three dots (.) so voids are distinguishable.)

An x may be used in place of any rank identifier to represent a spot card below T.

Sample Hands

  • AQJ4.8732.T92.K9 (equivalent to AQJ4 8732 T92 K9 )
  • AKQxx.Jxx..Qxxxx (equivalent to AKQxx Jxx - Qxxxx )