Last active
February 8, 2017 18:46
-
-
Save danielevans/c4680bcc6aeb4e2daea79823918fcd15 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'bridge' | |
SAYC_2_1.define do | |
# opening: true implies requirement that history contains only pass bids | |
convention :strong_2_club do | |
opening true | |
long_points minimum: 22 | |
balanced true | |
bid level: 2, strain: Bridge::Strain::Club | |
end | |
convention :one_notrump_opening, tags: :notrump_opening do | |
opening true | |
high_card_points 15..17 | |
balanced true | |
bid level: 1, strain: Bridge::Strain::NoTrump | |
end | |
convention :two_notrump_opening, tags: :notrump_opening do | |
opening true | |
high_card_points 20..21 | |
balanced true | |
bid level: 2, strain: Bridge::Strain::NoTrump | |
end | |
convention :three_notrump_opening, tags: :notrump_opening do | |
opening true | |
high_card_points 25..27 | |
balanced true | |
bid level: 3, strain: Bridge::Strain::NoTrump | |
end | |
convention :major_opening do | |
opening true | |
length suit: Bridge::Strain.majors, minimum: 5 | |
seat 1..4 do | |
long_points minimum: 13 | |
end | |
seat 3..4 do | |
long_points minimum: 11 | |
end | |
seat 4 do | |
only_if do |hand, _history| # rule of 15 | |
hand.length(Bridge::Strain::Spades) + hand.high_card_points >= 15 | |
end | |
end | |
bid do |hand, _history| | |
strain = hand.length(Bridge::Strain::Heart) > hand.length(Bridge::Strain::Spade) ? Bridge::Strain::Heart : Bridge::Strain::Strain | |
bid! level: 1, strain: strain | |
end | |
end | |
convention :minor_opening do | |
opening true | |
length suit: Bridge::Strain.minors, minimum: 3 | |
seat 1..4 do | |
long_points minimum: 13 | |
end | |
seat 3..4 do | |
long_points minimum: 11 | |
end | |
seat 4 do | |
only_if do |hand, _history| # rule of 15 | |
hand.length(Strain::Spades) + hand.high_card_points >= 15 | |
end | |
end | |
bid do |hand, _history| | |
strain = if hand.length(Bridge::Strain::Diamond) == hand.length(Bridge::Strain::Club) && hand.length(Bridge::Strain::Diamond) == 3 | |
Bridge::Strain::Club | |
elsif hand.length(Bridge::Strain::Diamond) >= hand.length(Bridge::Strain::Club) | |
Bridge::Strain::Diamond | |
else | |
Bridge::Strain::Club | |
end | |
bid! level: 1, strain: strain | |
end | |
end | |
convention :preempt_opening do | |
opening true | |
long_points 7..12 | |
only_if do |hand, _history| | |
(Bridge::Strain::Suits - Bridge::Strain::Club).any? do |strain| | |
hand.length(strain) >= 6 && hand.strong?(strain) | |
end || (hand.length(Bridge::Strain::Club) >= 7 && hand.strong?(Bridge::Strain::Club)) | |
end | |
bid do |hand, _history| | |
strain = hand.longest_suit # TODO: could be 6/6 or 7/6 and only one strong | |
bid! level: (hand.length(strain) - 4), strain: strain | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks so much for including me on this gist1
I had some more thoughts (and released them...) while meditating:
More problem domain nomenclature; I'm not sure what of this you know, so here's a brain dump of my understandings: bids are calls and (re)doubles are calls and passes are calls. (Re)doubles and passes are not bids. Opener is the first to make a bid call; Responder is his partner. Overcaller is the first to make a bid call (I think, not a double), and Advancer is his partner. The system (Standard American) describes natural bid calls, pass calls, and doubles (for penalty). Conventions are codified in http://web2.acbl.org/documentLibrary/play/ConventionCard.pdf which contains a great deal more problem domain nomenclature. Standard American Yellow Card is the Standard American system with the Yellow Card set of conventions adopted from the convention card, codified here: http://web2.acbl.org/documentlibrary/play/SP3%20(bk)%20single%20pages.pdf . Aside: the big difference between the system "Standard American" and 2-over-1 which Zack's club plays is the point range of a natural non-jump bid of two in a new suit by responder: in Standard American, it is 10-18 (I think) points long; in 2-over-1 it is 12-18 (I think) points long.
Also, it occurred to me (again while meditating) that a format similar to this one is a potential format for the _history argument, inspired by section 3.5 at http://www.tistis.nl/pbn/pbn_v21.txt :
1D 1S 3H 4S
4NT X Pass Pass
5C X 5H X
Pass Pass Pass
That is, in CS theory terms, valid auctions and completed auctions are themselves (finite) languages drawn from the alphabet (sigma) of calls, where the machine recognizing the latter language not only verifies that the sentence (sequence of calls) obeys the bidding rules (as with the former language) but also requiring that it end in "[Call] Pass Pass Pass". I'm not sure if it's a helpful language, because the level of abstraction may be wrong: perhaps you'd like _history to have some other, perhaps OO, richer structure than "sequence of calls", since you're not trying simply to recognize valid sentences, but rather test incomplete auctions for utility, right? Still, just figured I'd share my meditation noodling.