示例#1
0
    def test_others(self):
        '''Testing other players'''
        g = Game.Game(Me({}), [Player("Foo", 4), Player("Bar", 14)])

        assert len(g.others) == 2
        assert g.others[0].name == "Foo"
        assert g.others[0].numCards == 4
        assert g.others[1].name == "Bar"
        assert g.others[1].numCards == 14
示例#2
0
    def test_snapshot(self):
        '''Test a game state snapshot'''
        g = Game.Game(Me({'White'}), [Player("Foo", 17)])
        g2 = g.snapshot()
        t = Cards.Triple('White', 'Rope', 'Hall')

        g.me.ask(t)
        g.others[0].show(t)

        assert not g2.me.asked
        assert not g2.others[0].shown
示例#3
0
def readPlayer(defaultName, defaultNumCards=3, maxCards=None):
    '''Query user for name of a player'''
    name = _read("Name", default=defaultName)
    while True:
        numCards = _read("How many cards does %s have?" % name,
                         default=defaultNumCards,
                         coerceTo=int)
        print("got %s" % numCards)
        if maxCards and numCards > maxCards:
            if maxCards == 1:
                msg = "There's only 1 card"
            else:
                msg = "There are only %s cards" % maxCards

            print("%s left for %s!" % (msg, name))
            continue

        return Player(name, numCards)
示例#4
0
    def test_repr(self):
        g = Game.Game(Me({'White'}), [Player("Foo", 17)])

        assert repr(g) == "Game(Me(['White']), [Player('Foo', 17)])"
示例#5
0
 def test_dupe_player_names(self):
     '''Test behavior when multiple other names are identical'''
     with pytest.raises(ImpossibleError):
         Game.Game(Me({}), [Player("Foo", 3), Player("Foo", 13)])
示例#6
0
 def test_wrong_number_card(self):
     '''Test behavior when we have the wrong number of cards'''
     with pytest.raises(ImpossibleError):
         Game.Game(Me({}), [Player("Foo", 3)])
示例#7
0
    def test_me(self):
        '''Testing my behaviors as a player'''
        g = Game.Game(Me({'Plum'}), [Player("Foo", 17)])

        assert g.me.numCards == 1
        assert g.me.hasCards == {'Plum'}