Exemplo n.º 1
0
    def test_create(self):
        lh = DiscretizedNLHoldem.get_lut_holder()

        assert lh.LUT_1DCARD_2_2DCARD.dtype == np.dtype(np.int8)
        assert lh.LUT_2DCARD_2_1DCARD.dtype == np.dtype(np.int8)
        assert lh.LUT_IDX_2_HOLE_CARDS.dtype == np.dtype(np.int8)
        assert lh.LUT_HOLE_CARDS_2_IDX.dtype == np.dtype(np.int16)
Exemplo n.º 2
0
 def test_get_1d_card(self):
     lh = DiscretizedNLHoldem.get_lut_holder()
     assert lh.get_1d_card(card_2d=[0, 3]) == 3
     assert lh.get_1d_card(card_2d=[12, 3]) == 51
     assert lh.get_1d_card(card_2d=np.array([0, 0], dtype=np.int8)) == 0
     assert lh.get_1d_card(card_2d=np.array([0, 0], dtype=np.int32)) == 0
     assert lh.get_1d_card(card_2d=Poker.CARD_NOT_DEALT_TOKEN_2D) == Poker.CARD_NOT_DEALT_TOKEN_1D
Exemplo n.º 3
0
    def test_hole_card_luts(self):
        """ tests reversibility """
        lh = DiscretizedNLHoldem.get_lut_holder()
        for h in range(1326):
            _c_1d = lh.get_1d_hole_cards_from_range_idx(
                h)  # Tests 1d conversion
            _c_2d = lh.get_2d_hole_cards_from_range_idx(
                h)  # Tests 2d conversion

            c_1d = (lh.LUT_IDX_2_HOLE_CARDS[h])
            c_2d = np.array([
                lh.LUT_1DCARD_2_2DCARD[c_1d[0]],
                lh.LUT_1DCARD_2_2DCARD[c_1d[1]]
            ],
                            dtype=np.int8)

            assert np.array_equal(c_1d, _c_1d)
            assert np.array_equal(c_2d, _c_2d)

        # Tests inverse and thus validates that the mapping is unique for both 1d and 2d implicitly
        for c1 in range(51):
            for c2 in range(c1 + 1, 50):
                cc1 = lh.LUT_1DCARD_2_2DCARD[c1]
                cc2 = lh.LUT_1DCARD_2_2DCARD[c2]
                hole_cards = np.array([cc1, cc2], dtype=np.int8)
                assert lh.get_range_idx_from_hole_cards(hole_cards) == \
                       lh.LUT_HOLE_CARDS_2_IDX[c1, c2]
Exemplo n.º 4
0
    def test_get_range_idx_from_hole_cards(self):
        lh = DiscretizedNLHoldem.get_lut_holder()
        n = 0
        for c1 in range(51):
            for c2 in range(c1 + 1, 52):
                assert lh.LUT_HOLE_CARDS_2_IDX[c1, c2] == n

                n += 1
Exemplo n.º 5
0
 def test_get_2d_cards(self):
     lh = DiscretizedNLHoldem.get_lut_holder()
     assert np.array_equal(lh.get_2d_cards(cards_1d=np.array([])), np.array([]))
     assert np.array_equal(lh.get_2d_cards(cards_1d=np.array([3])), np.array([[0, 3]]))
     assert np.array_equal(lh.get_2d_cards(cards_1d=np.array([3, 51])), np.array([[0, 3], [12, 3]]))
     assert np.array_equal(lh.get_2d_cards(cards_1d=np.array([])), np.array([]))
     assert np.array_equal(lh.get_2d_cards(cards_1d=np.array([0, Poker.CARD_NOT_DEALT_TOKEN_1D], dtype=np.int8)),
                           np.concatenate((np.array([[0, 0]]), Poker.CARD_NOT_DEALT_TOKEN_2D.reshape(-1, 2))))