from deuces import Card, Deck


class Game():
    """
    Contains a deck of cards that can be accessed by players to play
    various card games.
    """

    def __init__(self, name='kiwi'):
        self.players = []
        self.name = name
        self.deck = Deck()
        self.visible_cards = []

    def add_player(self, player):
        self.players.append(player)

    def shuffle(self):
        self.deck.shuffle()

    def deal(self, ncards):
        for i in range(ncards):
            for p in self.players:
                p.cards.append(self.deck.draw())

    def flip_flop(self):
        """Create flop.
        Flips over 3 cards and makes them publicly visible, as would
        happen when creating the flop in Texas Hold'em.
        """
        self.visible_cards += self.deck.draw(3)

    def flip_cards(self, ncards=1):
        """Like flip_flop, but allows variable number of cards."""
        if ncards == 1:
            self.visible_cards.append(self.deck.draw(ncards))
        else:
            self.visible_cards += self.deck.draw(ncards)

    def query_players(self):
        players = '%s players: ' % self.name
        for p in self.players:
            players += '%s ' % p.tag
        return players

    def query_state(self):
        info = '%s visible cards: ' % self.name
        for c in self.visible_cards:
            info += Card.int_to_pretty_str(c)
        return info

from deuces import Card, Deck


class Game():
    """
    Contains a deck of cards that can be accessed by players to play
    various card games.
    """

    def __init__(self, name='kiwi'):
        self.players = []
        self.name = name
        self.deck = Deck()
        self.visible_cards = []

    def add_player(self, player):
        self.players.append(player)

    def shuffle(self):
        self.deck.shuffle()
        self.visible_cards = []

    def deal(self, ncards):
        for i in range(ncards):
            for p in self.players:
                p.cards.append(self.deck.draw())

    def flip_flop(self):
        """Create flop.
        Flips over 3 cards and makes them publicly visible, as would
        happen when creating the flop in Texas Hold'em.
        """
        self.visible_cards += self.deck.draw(3)

    def flip_cards(self, ncards=1):
        """Like flip_flop, but allows variable number of cards."""
        if ncards == 1:
            self.visible_cards.append(self.deck.draw(ncards))
        else:
            self.visible_cards += self.deck.draw(ncards)

    def query_players(self):
        players = '%s players: ' % self.name
        for p in self.players:
            players += '%s ' % p.tag
        return players

    def query_state(self):
        info = '%s visible cards: ' % self.name
        for c in self.visible_cards:
            info += Card.int_to_pretty_str(c)
        return info

Fix behavioural bug in shuffling
Fix behavioural bug in shuffling

Previously shuffling would create a new deck, implying that all the
cards had been "picked up" and were being shuffled for a new hand.
However, this did not pick up the visible cards from the game, so the
visible cards would just continue to grow unchecked. This clears the
visible cards when shuffling occurs so it truly is a new deck.

  from deuces import Card, Deck
  
  
  class Game():
      """
      Contains a deck of cards that can be accessed by players to play
      various card games.
      """
  
      def __init__(self, name='kiwi'):
          self.players = []
          self.name = name
          self.deck = Deck()
          self.visible_cards = []
  
      def add_player(self, player):
          self.players.append(player)
  
      def shuffle(self):
          self.deck.shuffle()
+         self.visible_cards = []
  
      def deal(self, ncards):
          for i in range(ncards):
              for p in self.players:
                  p.cards.append(self.deck.draw())
  
      def flip_flop(self):
          """Create flop.
          Flips over 3 cards and makes them publicly visible, as would
          happen when creating the flop in Texas Hold'em.
          """
          self.visible_cards += self.deck.draw(3)
  
      def flip_cards(self, ncards=1):
          """Like flip_flop, but allows variable number of cards."""
          if ncards == 1:
              self.visible_cards.append(self.deck.draw(ncards))
          else:
              self.visible_cards += self.deck.draw(ncards)
  
      def query_players(self):
          players = '%s players: ' % self.name
          for p in self.players:
              players += '%s ' % p.tag
          return players
  
      def query_state(self):
          info = '%s visible cards: ' % self.name
          for c in self.visible_cards:
              info += Card.int_to_pretty_str(c)
          return info
  
Fix behavioural bug in shuffling
## Code Before:
from deuces import Card, Deck


class Game():
    """
    Contains a deck of cards that can be accessed by players to play
    various card games.
    """

    def __init__(self, name='kiwi'):
        self.players = []
        self.name = name
        self.deck = Deck()
        self.visible_cards = []

    def add_player(self, player):
        self.players.append(player)

    def shuffle(self):
        self.deck.shuffle()

    def deal(self, ncards):
        for i in range(ncards):
            for p in self.players:
                p.cards.append(self.deck.draw())

    def flip_flop(self):
        """Create flop.
        Flips over 3 cards and makes them publicly visible, as would
        happen when creating the flop in Texas Hold'em.
        """
        self.visible_cards += self.deck.draw(3)

    def flip_cards(self, ncards=1):
        """Like flip_flop, but allows variable number of cards."""
        if ncards == 1:
            self.visible_cards.append(self.deck.draw(ncards))
        else:
            self.visible_cards += self.deck.draw(ncards)

    def query_players(self):
        players = '%s players: ' % self.name
        for p in self.players:
            players += '%s ' % p.tag
        return players

    def query_state(self):
        info = '%s visible cards: ' % self.name
        for c in self.visible_cards:
            info += Card.int_to_pretty_str(c)
        return info

## Instruction:
Fix behavioural bug in shuffling
## Code After:
from deuces import Card, Deck


class Game():
    """
    Contains a deck of cards that can be accessed by players to play
    various card games.
    """

    def __init__(self, name='kiwi'):
        self.players = []
        self.name = name
        self.deck = Deck()
        self.visible_cards = []

    def add_player(self, player):
        self.players.append(player)

    def shuffle(self):
        self.deck.shuffle()
        self.visible_cards = []

    def deal(self, ncards):
        for i in range(ncards):
            for p in self.players:
                p.cards.append(self.deck.draw())

    def flip_flop(self):
        """Create flop.
        Flips over 3 cards and makes them publicly visible, as would
        happen when creating the flop in Texas Hold'em.
        """
        self.visible_cards += self.deck.draw(3)

    def flip_cards(self, ncards=1):
        """Like flip_flop, but allows variable number of cards."""
        if ncards == 1:
            self.visible_cards.append(self.deck.draw(ncards))
        else:
            self.visible_cards += self.deck.draw(ncards)

    def query_players(self):
        players = '%s players: ' % self.name
        for p in self.players:
            players += '%s ' % p.tag
        return players

    def query_state(self):
        info = '%s visible cards: ' % self.name
        for c in self.visible_cards:
            info += Card.int_to_pretty_str(c)
        return info
