Skip to content

Commit

Permalink
Merge pull request datamllab#28 from billmuch/bugfix
Browse files Browse the repository at this point in the history
Fix bug of utils.py:is_in_cards:
  • Loading branch information
hsywhu authored Nov 13, 2019
2 parents 05173f0 + 6be68eb commit 7420d4e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
30 changes: 13 additions & 17 deletions rlcard/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,23 +171,19 @@ def is_in_cards(origin_cards, check_cards):
Returns:
(boolean): True if the cards are in the original cards.
'''
check_cards_cp = check_cards.copy()
cards = origin_cards.copy()
i = 0
while i < len(check_cards_cp):
j = 0
while j < len(cards):
if cards[j].rank == check_cards_cp[i].rank and cards[j].suit == check_cards_cp[i].suit:
cards.pop(j)
check_cards_cp.pop(i)
if(len(cards) == 0 or len(check_cards_cp) == 0):
break
j -= 1
j += 1
if(len(cards) == 0 or len(check_cards_cp) == 0):
break
i += 1
return len(check_cards_cp) == 0
check_cards_pos = set()
for check_card in check_cards:
found = False
for i in range(len(origin_cards)):
if i in check_cards_pos:
continue
if check_card.rank == origin_cards[i].rank and check_card.suit == origin_cards[i].suit:
found = True
check_cards_pos.add(i)
break
if not found:
return False
return True

def elegent_form(card):
''' Get a elegent form of a card string
Expand Down
4 changes: 4 additions & 0 deletions tests/utils/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,13 @@ def test_take_out_cards(self):
def test_is_in_cards(self):
deck54 = init_54_deck()
deck_standard = init_standard_deck()
deck54_plus_BJ = init_54_deck()
deck54_plus_BJ.append(Card('BJ', ''))
self.assertTrue(is_in_cards(deck54, deck_standard))
self.assertTrue(is_in_cards(deck54, [Card('BJ', ''), Card('RJ', '')]))
self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', '')]))
self.assertFalse(is_in_cards(deck54, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))
self.assertTrue(is_in_cards(deck54_plus_BJ, [Card('BJ', ''), Card('BJ', ''), Card('D', '3')]))

def test_print_cards(self):
self.assertEqual(len(elegent_form('S9')), 2)
Expand Down

0 comments on commit 7420d4e

Please sign in to comment.