Exemplo n.º 1
0
    def test_fabpedigree(self):
        #https://fabpedigree.com/james/dbldum.htm
        # The original problem
        dda = libdda.DDAnalyzer(
            "QJT98.4.QJT9.KT2 "
            "AK76543.32.AK2.3 "
            "2.QT87.876.87654 "
            ".AKJ965.543.AQJ9", 1)
        dda.play_card(0, 12)  # Q lead allows declarer to make
        self.assertEqual(dda.analyze(0), 0)

        # A different lead can set
        dda = libdda.DDAnalyzer(
            "QJT98.4.QJT9.KT2 "
            "AK76543.32.AK2.3 "
            "2.QT87.876.87654 "
            ".AKJ965.543.AQJ9", 1)
        dda.play_card(1, 4)  # Leading trumps can set the contract
        self.assertEqual(dda.can_make(1), True)
        self.assertEqual(dda.can_make(2), False)
        self.assertEqual(dda.analyze(1), 1)

        # What if we give everybody a pitch?
        dda = libdda.DDAnalyzer(
            "QJT98.4.QJT9.KT2 "
            "AK76543.32.AK2.3 "
            "2.QT87.876.87654 "
            ".AKJ965.543.AQJ9", 1)
        dda.play_card(0, 12)  # Q lead allows declarer to make
        dda.give_pitch(0)
        self.assertEqual(dda.analyze(0), 1)
Exemplo n.º 2
0
    def test_fabpedigree(self):
        #https://fabpedigree.com/james/dbldum.htm
        dda = libdda.DDAnalyzer(".A2.K97.A T32.T.T.T AJ4..Q8.2 KQ.98.A2.")
        self.assertEqual(dda.analyze(), 5)

        # Shouldn't work with Sumit suit
        dda = libdda.DDAnalyzer(".A2.K97.A T32.T.T.T AJ4..Q8.2 KQ.98.A2.")
        dda.give_pitch(3)
        self.assertEqual(dda.analyze(), 4)
Exemplo n.º 3
0
 def test_two_suits(self):
     dda = libdda.DDAnalyzer("2.2.. 3.3.. 4.4.. 5.5..")
     self.assertEqual(dda.analyze(), 0)
     dda = libdda.DDAnalyzer("2.2.. 3.3.. 5.4.. 4.5..")
     self.assertEqual(dda.analyze(), 1)
     dda = libdda.DDAnalyzer("23... 4.3.. 6.4.. 5.5..", 1)
     self.assertEqual(dda.analyze(), 1)
     dda = libdda.DDAnalyzer("24... 57... 68... .23..", 1)
     self.assertEqual(dda.analyze(), 0)
Exemplo n.º 4
0
 def test_one_suit(self):
     dda = libdda.DDAnalyzer("26... 37... 48... 59...")
     self.assertEqual(dda.analyze(), 0)
     dda = libdda.DDAnalyzer("23... 45... 68... 79...")
     self.assertEqual(dda.analyze(), 0)
     dda = libdda.DDAnalyzer("23... 68... 79... 45...")
     self.assertEqual(dda.analyze(), 2)
     dda = libdda.DDAnalyzer("23... 49... 68... 57...")
     self.assertEqual(dda.analyze(), 1)
     dda = libdda.DDAnalyzer("23... 47... 68... 59...")
     self.assertEqual(dda.analyze(), 1)
Exemplo n.º 5
0
 def test_3nt_strip_squeeze(self):
     #https://www.larryco.com/bridge-learning-center/detail/524
     dda = libdda.DDAnalyzer("3478Q.8JK.8T.7JK "
                             "69A.27TA.AK.489T "
                             "25K.346.23467.25 "
                             "TJ.59Q.59JQ.36QA")
     dda.play_card(0, 4)
     self.assertEqual(dda.analyze(3), 3)  # Can actually make 4NT
Exemplo n.º 6
0
    def test_three_suit_strip(self):
        # https://www.lajollabridge.com/French/misc/Squeeze-Refresher.pdf
        # Page 31, they are wrong

        # We should only be able to take our 2 aces
        dda = libdda.DDAnalyzer(".Tx.xx.Qx .Q.KQx.KJ .x.AJ.Axx ..Txx.Txx")
        self.assertEqual(dda.analyze(), 2)

        # We can endplay W
        dda = libdda.DDAnalyzer("A.T.xx.Qx .Q.KQx.KJ x..AJ.Axx ..Txx.Txx")
        self.assertEqual(dda.analyze(), 4)

        # They say this shouldn't work, but it does if you play a heart first
        dda = libdda.DDAnalyzer("A.Tx.xx.Qx .QJ.KQx.KJ x.x.AJ.Axx ..Txxx.Txx")
        self.assertEqual(dda.analyze(), 4)

        # This should work too, as they promise
        dda = libdda.DDAnalyzer("A.Tx.xx.Ax .QJ.KQx.KJ x.x.AJ.Qxx ..Txxx.Txx")
        self.assertEqual(dda.analyze(), 4)
Exemplo n.º 7
0
    def test_simple_squeeze(self):
        #http://www.pittsburghbridge.org/JimmySez/JRKLess09.pdf
        # Page 4

        dda = libdda.DDAnalyzer(
            "KQT74.KQ93.53.T7 "
            "AJ.AJ4.T964.J642 "
            "98653.T862.7.985 "
            "2.75.AKQJ82.AKQ3", 2)
        dda.play_card(1, 13)  # K
        self.assertEqual(dda.analyze(0), 0)

        dda = libdda.DDAnalyzer(
            "KQT74.KQ93.53.T7 "
            "AJ.AJ4.T964.J642 "
            "98653.T862.7.985 "
            "2.75.AKQJ82.AKQ3", 2)
        dda.play_card(1, 13)  # K
        dda.give_pitch(0)
        self.assertEqual(dda.analyze(0), 1)
Exemplo n.º 8
0
    def test_simple_squeezes(self):
        # Positional simple squeeze
        dda = libdda.DDAnalyzer("2..2.2 ..7.45 ..6.36 ..345.")
        self.assertEqual(dda.analyze(), 3)

        # Positional simple squeeze shouldn't work when the threats are offside
        dda = libdda.DDAnalyzer("2..2.2 ..345. ..6.36 ..7.45")
        self.assertEqual(dda.analyze(), 2)

        # Positional simple squeeze shouldn't work when there's an extra loser
        dda = libdda.DDAnalyzer("2.2.2.2 .3.A.KQ .4.K.JA .5.345.")
        self.assertEqual(dda.analyze(), 2)

        # Positional simple squeeze also shouldn't work if
        # we have the SUMIT suit!!!
        dda = libdda.DDAnalyzer("2..2.2 ..7.45 ..6.36 ..345.")
        dda.give_pitch(1)
        self.assertEqual(dda.analyze(), 2)

        # Automatic squeeze
        dda = libdda.DDAnalyzer("2..5.2 ..6.45 .2..36 ..234.")
        self.assertEqual(dda.analyze(), 3)

        # Automatic squeezes work no matter which side has the guards
        dda = libdda.DDAnalyzer("2..5.2 ..234. .2..36 ..6.45")
        self.assertEqual(dda.analyze(), 3)
Exemplo n.º 9
0
Arquivo: ehas.py Projeto: pnaimoli/dda
def accept(deal):
    # Filter out zany distributions
    if deal.south.hcp + deal.north.hcp < 30:
        return False
    if len(deal.south.spades) + len(deal.north.spades) >= 8:
        return False
    if len(deal.south.hearts) + len(deal.north.hearts) >= 8:
        return False
    if not (balanced + semibalanced)(deal.north):
        return False

    TARGET_TRICKS = 12

    # Take only results where N/S make exactly 3NT with the given
    # opening lead
    lead = slam_lead(deal.west)
    dd_lead = convert_to_dd_card(deal.west, lead)
    dd_results = deal.dd_all_tricks("N", "W")
    if dd_results[dd_lead] != 13 - TARGET_TRICKS:
        return False

    # Convert to the hand string format dda accepts
    def suit_string(holding):
        return "".join([card.name for card in holding])
    def hand_string(hand):
        return ".".join([suit_string(holding) for holding in hand])
    hands = [deal.west, deal.north, deal.east, deal.south]
    board_string = " ".join([hand_string(hand) for hand in hands])

    # Run dda!
    # Can we defeat the contract with some extra cards?
    dda = libdda.DDAnalyzer(board_string)
    dda.play_card(lead.suit.value, lead.rank.value)
    dda.give_pitch(0)
    dda.give_pitch(2)

    if dda.can_make(13 - TARGET_TRICKS + 1):
        global NUM_FOUND
        NUM_FOUND += 1
        return True
    else:
        global NUM_FAILED
        NUM_FAILED += 1
        return False
Exemplo n.º 10
0
 def test_duh(self):
     dda = libdda.DDAnalyzer("2... 3... 4... 5...")
     self.assertEqual(dda.analyze(), 0)
     dda = libdda.DDAnalyzer("2... 3... 5... 4...")
     self.assertEqual(dda.analyze(), 1)
     dda = libdda.DDAnalyzer("2... .3.. .5.. .4..")
     self.assertEqual(dda.analyze(), 1)
     dda = libdda.DDAnalyzer("2... .3.. .5.. .4..", 0)
     self.assertEqual(dda.analyze(), 1)
     dda = libdda.DDAnalyzer("2... .3.. .4.. .5..", 1)
     self.assertEqual(dda.analyze(), 0)
     dda = libdda.DDAnalyzer("2... .3.. .5.. .4..", 1)
     self.assertEqual(dda.analyze(), 1)
Exemplo n.º 11
0
 def test_strip_and_duck(self):
     #https://www.lajollabridge.com/French/misc/Squeeze-Refresher.pdf
     dda = libdda.DDAnalyzer("AK.xx.xx. .KQJ.KQ.x x.ATx.AJ. xx.xx..xx")
     self.assertEqual(dda.analyze(), 5)
Exemplo n.º 12
0
 def test_guard_squeezes(self):
     #http://www.bridgeguys.com/squeeze/guard_squeeze.html
     dda = libdda.DDAnalyzer("A...KT3 .A.A.Q6 .K.K.A7 4...J54")
     self.assertEqual(dda.analyze(), 4)