Beispiel #1
0
def test_make_lead_and_play_card():
    deal = {
        'N': set(['C14', 'C13', 'C12', 'C11']),
        'E': set(['S14', 'S13', 'H12', 'H11']),
        'S': set(['D14', 'D13', 'H14', 'H13']),
        'W': set(['D12', 'D11', 'S12', 'S11'])
    }
    d = Deal(deal=deal)
    # This function also runs the play_card function
    d.make_lead()
    assert (d.lead in d.original_hands['W'])
    d.current_hands['W'].add(d.lead)
    assert_equal(d.original_hands, d.current_hands)
    assert_equal(d.card_no, 2)
Beispiel #2
0
def test_play_to_all_leaves():
    d = Deal(seed=0)
    d.make_lead()
    # print(d.original_hands)
    disp = Displayer()
    dec = Decisions()
    sim = Simulator()
    e = GameEngine(disp, dec, sim)
    e.play_to_all_leaves(d)
    assert_equal(d.trick_no, 5)
    assert_equal(d.card_no, 17)
    assert_equal(d.current_trick, [])
    # we save this number from a previous run. Good to check we always traverse the whole tree
    assert_equal(d.leaf_nodes, 832)
Beispiel #3
0
def test_find_all_layouts_and_run_sims():
    deal = {
        'N': set(['C14', 'C13', 'C12', 'C11']),
        'E': set(['S14', 'S13', 'H12', 'H11']),
        'S': set(['D14', 'D13', 'H14', 'H13']),
        'W': set(['D12', 'D11', 'S12', 'S11'])
    }
    d = Deal(deal=deal)
    sim = Simulator()
    dec = Decisions()
    disp = Displayer()

    e = GameEngine(disp, dec, sim)
    d.make_lead('D12')
    layouts = sim.find_layouts(d)
    # This should be the case because west has played a card already and north/south haven't
    assert (len(layouts[2]) > len(layouts[0]))
Beispiel #4
0
    def run_sims_position(self, player_layouts, lead):
        """
        For each player (NS combined), we play out the full game tree for every possible
        combination of hands that their opponents may have after the lead
        """
        all_sims = []

        for position_layouts in player_layouts:
            simulations = {}
            for full_hands in position_layouts:
                new_deal = Deal(deal=full_hands)
                new_deal.make_lead(lead)
                simulations.update(self.play_to_all_leaves(new_deal))

            all_sims.append(simulations)

        return all_sims