コード例 #1
0
ファイル: test_sets.py プロジェクト: pberkes/masterbaboon
    def test_one_game(self):
        all_cards = set()
        old_nsets = -1
        game = sets_solver.one_game()
        for cards in game:
            ncards = cards.shape[1]

            assert ncards % 3 == 0
            
            if ncards < 12:
                # this is only possible at the end of the deck
                left = len(list(game))
                assert left < 3
                
            if cards.shape[1] == 15:
                assert old_nsets == 0
                
            old_nsets = len(sets_solver.find_sets2(cards))
            cards_list = [tuple(c) for c in cards.T]
            all_cards = all_cards.union(set(cards_list))
            
        # all cards must have been played
        cards = [card for card in itertools.product(range(3), repeat=4)]
        assert all_cards == set(cards)
コード例 #2
0
ファイル: test_sets.py プロジェクト: gtruelove/masterbaboon
    def test_one_game(self):
        all_cards = set()
        old_nsets = -1
        game = sets_solver.one_game()
        for cards in game:
            ncards = cards.shape[1]

            assert ncards % 3 == 0

            if ncards < 12:
                # this is only possible at the end of the deck
                left = len(list(game))
                assert left < 3

            if cards.shape[1] == 15:
                assert old_nsets == 0

            old_nsets = len(sets_solver.find_sets2(cards))
            cards_list = [tuple(c) for c in cards.T]
            all_cards = all_cards.union(set(cards_list))

        # all cards must have been played
        cards = [card for card in itertools.product(range(3), repeat=4)]
        assert all_cards == set(cards)
コード例 #3
0
ファイル: test_sets.py プロジェクト: pberkes/masterbaboon
 def test_find_sets2(self):
     for i in range(100):
         cards = sets_solver.random_cards()
         sets = sets_solver.find_sets(cards)
         sets2 = sets_solver.find_sets2(cards)
         self.assertEqual(sets, sets2)
コード例 #4
0
ファイル: more_set.py プロジェクト: gtruelove/masterbaboon
import pylab
import scipy
from sets_solver import find_sets2, one_game, random_cards

# distribution of number of sets in random draws with 15 cards
nsolutions_indep = []
for i in range(150000):
    cards = random_cards(ncards=15)
    nsolutions_indep.append(len(find_sets2(cards)))

pylab.gcf().set_size_inches(11, 6.4)
freq, bins, _ = pylab.hist(nsolutions_indep,
                           bins=range(-1, 14),
                           normed=1,
                           hold=0)
pylab.draw()
print 'Prob of 0 sets for the independent case', freq[
    1], 'or 1 in', 1. / freq[1]
#('Prob of 0 sets for the independent case', 0.00038668213395202477, 'or 1 in', 2586.1034482758619)

nsolutions = []
n15 = []
for i in range(5000):
    count15 = 0
    for cards in one_game():
        if cards.shape[1] > 12:
            count15 += 1
            nsolutions.append(len(find_sets2(cards)))
    n15.append(count15)

pylab.gcf().set_size_inches(11, 6.4)
コード例 #5
0
ファイル: set_results.py プロジェクト: pberkes/masterbaboon
import pylab
from sets_solver import find_sets2, one_game, random_cards


# distribution of number of sets in random draws
nsolutions_indep = []
for i in range(10000):
    cards = random_cards()
    nsolutions_indep.append(len(find_sets2(cards)))
freq, bins, _ = pylab.hist(nsolutions_indep, bins=range(-1,14), normed=1, hold=0)
print 'Prob of 0 sets for the independent case', freq[1], 'or 1 in', 1./freq[1]

# distribution of number of sets during a game
nsolutions = []
for i in range(5000):
    for cards in one_game():
        nsolutions.append(len(find_sets2(cards)))

freq, bins, _ = pylab.hist(nsolutions, bins=range(-1,14), normed=1, hold=0)
print 'Prob of 0 sets for the game case', freq[1], 'or 1 in', 1./freq[1]

# TODO: are there correlations within games?
コード例 #6
0
ファイル: test_sets.py プロジェクト: gtruelove/masterbaboon
 def test_find_sets2(self):
     for i in range(100):
         cards = sets_solver.random_cards()
         sets = sets_solver.find_sets(cards)
         sets2 = sets_solver.find_sets2(cards)
         self.assertEqual(sets, sets2)