示例#1
0
def four_items(db_module):
    cards.delete_all()
    cards.add_card(Card(summary='one', owner='brian'))
    cards.add_card(Card(summary='two', owner='brian', done=True))
    cards.add_card(Card(summary='three', owner='okken', done=True))
    cards.add_card(Card(summary='three', owner='okken'))
    cards.add_card(Card(summary='four'))
示例#2
0
 def test_hand_can_cast_itself_to_new_ranked(self):
     hand = Hand()
     hand.add_card(Card("C", "A"))
     hand.add_card(Card("D", "A"))
     new_hand = hand.to_ranked("C")
     for card in new_hand:
         assert isinstance(card, RankedCard)
示例#3
0
def init_cards():
    global deck, p_hand, c_hand, up_card, nc_kou, np_kou, c_kou, p_kou
    deck = []  #此为待揭的牌
    nc_kou = np_kou = 0  #电脑和玩家的扣牌数
    c_kou = []  #电脑扣的牌
    p_kou = []  #玩家扣的牌
    for pear in range(2):  #pear是“副”的意思,这里要用2副牌
        for suit in range(1, 5):  #suit是“花色”的意思,扑克牌共有4种花色
            for rank in range(1, 14):  #rank指牌的符号如“A”、“9”等
                next = Card(suit, rank)
                deck.append(next)
    deck.append(Card(5, 14))
    deck.append(Card(6, 14))  #这两行是初始化比较特殊的大王和小王

    p_hand = []  #此为玩家手中的牌
    for cards in range(0, 5):
        card = random.choice(deck)
        p_hand.append(card)
        deck.remove(card)

    c_hand = []  #此为电脑手中的牌
    for cards in range(0, 5):
        card = random.choice(deck)
        c_hand.append(card)
        deck.remove(card)
示例#4
0
文件: game.py 项目: photi/pokerbot
 def __init__(self):
     self.clubs = {Card(0, k) for k in xrange(13)}
     self.diamonds = {Card(1, k) for k in xrange(13)}
     self.hearts = {Card(2, k) for k in xrange(13)}
     self.spades = {Card(3, k) for k in xrange(13)}
     self.all_cards = list(self.clubs | self.diamonds | self.hearts
                           | self.spades)
示例#5
0
 def test_hard_17(self):
     hand = Hand([
         Card(rank='A', suit='spade'),
         Card(rank='K', suit='spade'),
         Card(rank='6', suit='spade'),
     ])
     self.assertEqual(hand.score(), 17)
示例#6
0
def test_stacking(cards_db, summary, owner, state):
    """Make sure adding to db doesn't change values."""
    ...
    expected = Card(summary, owner=owner, state=state)
    i = cards_db.add_card(Card(summary, owner=owner, state=state))
    card = cards_db.get_card(i)
    assert card == expected
示例#7
0
def test_discard_card__reverses():
    """Check if discard_card reverses the game direction after a King card has been discarded."""
    s = mock_setup_round(['♣4 ♡K', '♣K ♣9'], '♢5 ♢6 ♢7 ♢8', '♡3')
    s.discard_card(s.players[0], Card('♡', 'K'))
    assert s.direction == -1
    s.discard_card(s.players[1], Card('♣', 'K'))
    assert s.direction == 1
示例#8
0
def test_list(db_empty):
    some_cards = [Card(summary="one"), Card(summary="two")]
    for c in some_cards:
        cards.add_card(c)

    all_cards = cards.list_cards()
    assert all_cards == some_cards
示例#9
0
def main():
  P1 = Deck()
  for x in range(1,10):
    card = Card(2,x)
    P1.insertCard(card)
  for x in range(1,8):
    P1.insertCard(Card(3,x))
  for x in range(7,10):
    P1.insertCard(Card(4,x))  
  print getColorDict(P1)
  return
  P1Wins = 0
  P2Wins = 0
  P1CumulativeScore = 0
  P2CumulativeScore = 0
  for i in range(0,100):
    P1Score,P2Score = simulateAGame()
    P1CumulativeScore+=P1Score
    P2CumulativeScore+=P2Score
    if P1Score>P2Score:
      P1Wins+=1
    elif P2Score>P1Score:
      P2Wins+=1
    print  "P1 is dumb P2 is always draw!"
    print "After 100 rounds, P1Wins: {} P2Wins: {}\nP1 Total:{}, P2 Total: {}".format(P1Wins,P2Wins,P1CumulativeScore,P2CumulativeScore)
示例#10
0
def four_items(db_module):
    cards.delete_all()
    cards.add_card(Card(summary="one", owner="brian"))
    cards.add_card(Card(summary="two", owner="brian", done=True))
    cards.add_card(Card(summary="three", owner="okken", done=True))
    cards.add_card(Card(summary="three", owner="okken"))
    cards.add_card(Card(summary="four"))
示例#11
0
 def test_get_actions(self):
     self.player1.cards = [Card(1, 1), Card(2, 2)]
     actions = self.game.get_actions(self.player1)
     self.assertEqual(len(actions), 2)
     self.assertEqual(actions, [
         Action(self.player1, Card(1, 1)),
         Action(self.player1, Card(2, 2))
     ])
示例#12
0
def card_ace_test():
    a = Card('A', 'd')
    b = Card('2', 'c')
    c = Card('J', 'h')
    if a.is_ace() and not b.is_ace() and not c.is_ace():
        return True
    else:
        return False
示例#13
0
def card_suit_test():
    a = Card('A', 'd')
    b = Card('2', 'c')
    c = Card('J', 'h')
    if a.get_suit() == 'd' and b.get_suit() == 'c' and c.get_suit() == ('h'):
        return True
    else:
        return False
 def test_bust(self):
     hand = Hand([
         Card(rank='K', suit='spade'),
         Card(rank='Q', suit='spade'),
         Card(rank='J', suit='spade'),
         Card(rank='A', suit='spade'),
     ])
     hand.is_bust()
示例#15
0
文件: test.py 项目: NiyaMei/DURAK
def test1():
    card1 = Card("spades", 10)
    card2 = Card("diamonds", 11)
    deck1 = Deck()
    deck1.add_card(card1)
    deck1.add_card(card2)
    for card in deck1:
        card.show_card()
示例#16
0
 def test_referee_should_compute_team_score(self):
     team = Team(0, Player(), Player())
     cards = [Card("C", "E"), Card("C", "N"), Card("C", "J")]
     trick = Trick(cards).to_ranked("C")
     team.get_cards(trick)
     assert self.referee.count_team_points(team) == 34
     team.started = True
     assert self.referee.count_team_points(team) == 0
示例#17
0
def db_non_empty(db_empty):
    some_cards = (
        Card(summary="first item"),
        Card(summary="second item"),
        Card(summary="third item"),
    )
    ids = [cards.add_card(c) for c in some_cards]
    return {"initial_cards": some_cards, "ids": ids}
示例#18
0
def card_rank_test():
    a = Card('A', 'd')
    b = Card('2', 'c')
    c = Card('J', 'h')
    if a.get_rank() == 'A' and b.get_rank() == '2' and c.get_rank() == ('J'):
        return True
    else:
        return False
示例#19
0
def card_equal_test():
    '''Testing whether cards are greater/less than or equal too one another'''
    a = Card('A', 'd')
    b = Card('2', 'c')
    c = Card('A', 'h')
    if a == c and c == c and c != b and b != a:
        return True
    else:
        return False
示例#20
0
def printGameBoard(communityDecks):
  P1Deck = communityDecks['P1']
  P2Deck = communityDecks['P2']
  for number in range(10,0,-1):
    for color in range (1,6):
      card = Card(Color(color).value,number)
      if P1Deck.hasCard(card):
        #pass
      #  print Color(color).name
        value = number
        if value==1:
          value="HS*"+str(P1Deck.countCard(card))
        print str(value).ljust(7,' '),
      else:
        print ''.ljust(7,' '),

    print ""
  for color in range(1,6):
    card = Card(Color(color).value,number)
    colorname = Color(color).name
    deck = communityDecks[colorname]
    if len(deck)>0:
      card = deck.cards[len(deck.cards)-1]
      value = card.value
    else:
      value = ''
    if value == 1:
      value = 'HS'
    output=colorname[0]+str(value)
    print output.ljust(7,' '),
  print "" #just need a newline
 # deck = communityDecks['DISCARD']
 # if len(deck)>0:
 #   card = deck.cards[len(deck.cards)-1]
 #   value = card.value
 #   colorname = Color(card.color).name
 # else:
 #   value = ''
 # if value == '':
 #   output="Discard:Empty"
 # else:
 #   if value == 1:
 #     value = 'HS'
 #   output="Discard:"+colorname[0]+str(value)
 # print output
  #now need to print out P2Deck...upside down from how we did P1
  for number in range(1,11,1):
    for color in range (1,6):
      card = Card(Color(color).value,number)
      if P2Deck.hasCard(card):
        value = number
        if value==1:
          value="HS*"+str(P2Deck.countCard(card))
        print str(value).ljust(7,' '),
      else:
        print ''.ljust(7,' '),
    print "\n"
示例#21
0
 def test_really_hard_14(self):
     hand = Hand([
         Card(rank='A', suit='spade'),
         Card(rank='A', suit='club'),
         Card(rank='A', suit='heart'),
         Card(rank='A', suit='diamond'),
         Card(rank='K', suit='spade')
     ])
     self.assertEqual(hand.score(), 14)
示例#22
0
    def test_with_employee_with_thre_cards(self):
        self.employee.add_card(Card(10))
        self.employee.add_card(Card(20))
        self.employee.add_card(Card(5))

        result = self.calculator.calculate(self.employee)
        expected = 350

        self.assertEqual(expected, result)
示例#23
0
def test_count(db_empty):
    # GIVEN a db with 2 cards
    db = db_empty
    db.add(Card(summary='one'))
    db.add(Card(summary='two'))

    # count() returns 2
    count = db.count()
    assert 2 == count
示例#24
0
def cards_db_three_cards(session_cards_db):
    db = session_cards_db
    # start with empty
    db.delete_all()
    # add three cards
    db.add_card(Card("Learn something new"))
    db.add_card(Card("Build useful tools"))
    db.add_card(Card("Teach others"))
    return db
示例#25
0
 def test_getCard(self):
     card1 = Card(1, 'question', 'answer', 'qhint', 'ahint', 13)
     card2 = Card(2, 'frage', 'antwort', 'qhint', 'ahint2', 20)
     id1 = self.cards.addCard(card1)
     id2 = self.cards.addCard(card2)
     card1a = self.cards.getCard(id1)
     card2a = self.cards.getCard(id2)
     self.assertEqual(card1, card1a)
     self.assertEqual(card2, card2a)
示例#26
0
 def test_cards_can_cast_themselves_to_ranked_cards(self):
     card = Card("C", "A")
     ranked_card = card.to_ranked("C")
     assert isinstance(ranked_card, Trump)
     assert ranked_card == Trump(card)
     card = Card("H", "A")
     ranked_card = card.to_ranked("C")
     assert isinstance(ranked_card, NonTrump)
     assert ranked_card == NonTrump(card)
示例#27
0
def card_greater_test():
    '''Testing whether cards are greater/less than or equal too one another'''
    a = Card('A', 'd')
    b = Card('2', 'c')
    c = Card('J', 'h')
    if c > b and b > a and c > a and not a > c and not b > c:
        return True
    else:
        return False
示例#28
0
def face_card_rank_test():
    a = Card('A', 'd')
    b = Card('J', 'c')
    c = Card('Q', 'h')
    d = Card('K', 's')
    if a < b < c < d and d > c > b > a:
        return True
    else:
        return False
示例#29
0
def card_less_test():
    '''Testing whether cards are greater/less than or equal too one another'''
    a = Card('A', 'd')
    b = Card('2', 'c')
    c = Card('J', 'h')
    if a < b and b < c and a < c and not c < a and not c < b:
        return True
    else:
        return False
示例#30
0
 def test_pop_should_remove_one_card(self):
     stack = CardStack()
     stack.add_card(Card("C", "A"))
     stack.add_card(Card("D", "A"))
     l = len(stack.cards)
     for _ in range(2):
         card = stack.pop(0)
         assert isinstance(card, Card)
         assert len(stack.cards) == l - 1
         l -= 1