Beispiel #1
0
 def test_trix2(self):
     tri2 = tcards('k2 r2 b2')
     tri3 = tcards('r3 g3 b3')
     distraction = tcards('g5 b8 r9 k10 k11 k13')
     cards = distraction + tri2 + tri3
     pr = TMultiFinder(3, True)
     out, le = pr.recognize(cards)
     pytest.assume(len(out) == 2)
     pytest.assume(tri2 == out[2])
     pytest.assume(tri3 == out[3])
Beispiel #2
0
    def test_comparison_hand(self, c1, c2, exp):
        """
        Check if the rank of two patterns is evaluated correctly
        :param c1:
        :param c2:
        :param exp:
        :return:
        """
        ds1 = TDoubleStraight(tcards(c1))
        ds2 = TDoubleStraight(tcards(c2))

        assert ds2.gt_hand(ds1) is exp
Beispiel #3
0
    def play(self, lastcards: Set[Card], cards_validator):
        """
        :rtype: Set[Card]
        :param lastcards:
        """
        validpattern = None
        while validpattern is None:
            inp = prompt("What would you like to play on {}\n"
                        "Write 'pass' for pass\n"
                        "Your Cards: {}\n".format(lastcards or '{}', sorted(self.hand, key=lambda c: c.rank)),
                         lexer=TichuLexer())
            try:
                if inp == "pass" or inp == "p":
                    print( 'You pass...')
                    cards = []
                else:
                    cards = tcards(inp)

                validpattern = cards_validator(cards)
                if validpattern is None:
                    print("Invalid pattern, try again...")

            except Exception as e:
                print(sys.exc_info())
                print("'{}' is invalid! Try again!".format(e))

        self.hand.difference_update(cards)
Beispiel #4
0
    def initUI(self):
        self.statusBar().showMessage('Init GUI…', 10)
        self.setWindowTitle('TiQu')
        self.setToolTip('This will be well, a Tichu App')
        btOk = QPushButton('Ok', self)
        btOk.setToolTip('Gagi')

        exitAct = QAction(QIcon('exit.png'), '&Exit', self)
        exitAct.setStatusTip('Exitting... Exciting!')
        exitAct.triggered.connect(qApp.quit)

        self.menuBar = QMenuBar()
        file = self.menuBar.addMenu('&Gagi')
        file.addAction(exitAct)

        cards = tcards('g2 b3 k5')

        qcardgrid = TCardGrid(cards)
        self.setCentralWidget(qcardgrid)
Beispiel #5
0
    def test_valid(self, cards, deck):
        """
        Just give a list of valid patterns

        :param cards:
        :return:
        """
        tc = tcards(cards)
        table = tc[0]
        played = tc[1]
        validator = CardsValidator(table, deck)
        validator.verify(played)
        assert validator.played_cards

        @mark.parametrize('table,played,hand,wish,allowed', [
            ([b2, g2, k2], [k3, b3, g3], [k3, b3, g3, phoenix], 3, True),
            ([b2, g2], [b3, g3], [k3, b3, g3, phoenix], 3, True),
            ([b2, g2, k2], [k3, b3, g3], [k3, b3, g3, k5, g5, k5, phoenix
                                          ], 5, False),
            ([b2, g2], [b3, g3], [k3, b3, g3, g4, phoenix], 4, False),
        ])
        def test_wish_allowed(table, played, hand, wish, allowed):
            validator = CardsValidator(table, hand, wish)
            validator.verify()
Beispiel #6
0
 def test_illegal_straight(self, c):
     with pytest.raises(ValueError):
         st1 = TStraight(tcards(c))
Beispiel #7
0
 def test_compare_hand(self, c1, c2, exp):
     st1 = TStraight(tcards(c1))
     st2 = TStraight(tcards(c2))
     assert st2.gt_hand(st1) is exp
Beispiel #8
0
 def test_multi(self, multi, exp):
     cards = tcards(multi)
     assert exp == cards
Beispiel #9
0
 def test_illegal_multi(self, c):
     with pytest.raises(ValueError):
         cards = tcards(c)
         TMulti(cards)
Beispiel #10
0
 def test_3ph(self):
     cards = tcards('k2 g2 ph b3 g3')
     pr = TMultiFinder(3, False)
     out, le = pr.recognize(cards, True)
     assert {2: (tcards('k2 g2 ph')), 3: (tcards('b3 g3 ph'))} == out
Beispiel #11
0
 def test_3fail(self):
     cards = tcards('k2 r2 b3 g3')
     pr = TMultiFinder(3, True)
     out, le = pr.recognize(cards)
     assert out == {}
Beispiel #12
0
 def test_4simpleph(self):
     cards = tcards('k2 r2 b2 b3')
     pr = TMultiFinder(4, True)
     out, le = pr.recognize(cards)
     assert out == {}
Beispiel #13
0
 def test_compare(self, c1, c2, exp):
     fh1 = TFullHouse(tcards(c1))
     fh2 = TFullHouse(tcards(c2))
     assert exp == fh2.gt_table(fh1)
Beispiel #14
0
 def valid_cards(cards, rank, length):
     tc = tcards(cards)
     ds = TDoubleStraight(tc)
     assert rank == ds.rank
     assert length == ds.cardinality
Beispiel #15
0
 def failing_cards(cards):
     tc = tcards(cards)
     with pytest.raises(ValueError):
         TDoubleStraight(tc)
Beispiel #16
0
 def test_4simple(self):
     cards = tcards('k2 r2 b2 g2')
     pr = TMultiFinder(4, True)
     out, le = pr.recognize(cards)
     assert {2: (cards)} == out
Beispiel #17
0
 def test_invalid(self, c):
     with pytest.raises(ValueError):
         tc = tcards(c)
         fh = TFullHouse(tc)
         print(fh)
Beispiel #18
0
 def test_creation(self, c, rank):
     tc = tcards(c)
     fh = TFullHouse(tc)
     assert rank == fh.rank
Beispiel #19
0
 def test_leftovers(self, cards):
     with pytest.raises(ValueError):
         tc = tcards(cards)
         fh = TFullHouse(tc)
         print(fh)
Beispiel #20
0
 def test_2x2(self):
     cards = tcards('k2 r2 b3 g3')
     pr = TMultiFinder(2, True)
     out, le = pr.recognize(cards)
     assert out == {2: (tcards('k2 r2')), 3: (tcards('b3 g3'))}
Beispiel #21
0
    def test_valid(self, cards, rank, cardinality):
        tc = tcards(cards)
        s = TStraight(tc)

        assert rank == s.rank
        assert cardinality == s.cardinality
Beispiel #22
0
 def test_compare(self, c1, c2, exp):
     m1 = TMulti(tcards(c1))
     m2 = TMulti(tcards(c2))
     assert m2.gt_table(m1) is exp
Beispiel #23
0
 def test_redundant(self, cards, red):
     tc = tcards(cards)
     s = TStraight(tc)
     assert red == s.redundant_cards
Beispiel #24
0
 def test_rank_numberof(self, rank, c, numberof):
     cards = tcards(c)
     tm = TMulti(cards)
     assert rank == tm.rank
     assert numberof == tm.cardinality
Beispiel #25
0
 def test_set_capabilities(self):
     l = tcards('g2 k2 ma ph')
     s1 = set(l)
     s1.remove(tcard('g2'))
     s2 = set(tcards('k2 ma ph'))
     assert s1 == s2