def test_get_score(self): hand = Hand() hand.hand = [ Card(x, y) for x, y in [("7", "♠"), ("7", "♥"), ("8", "♦")] ] assert isinstance(hand.get_score(), int) assert hand.get_score() == 22
def __init__(self, num): self.num = num self.game_score = 0 self.hand = Hand() self.melds = Melds() self.round = None self.ai_only = False
def test_get_key(self): test_hand = Hand() test_hand.hand = [ Card(x, y) for x, y in [("A", "♥"), ("2", "♥"), ("3", "♥"), ("4", "♥"), ("T", "♥"), ("J", "♥"), ("Q", "♥")] ] key_string = ', '.join( ["%s" % Colour.green(str((i + 1))) for i in range(7)]) assert test_hand.get_key() == key_string
def test_set_hand(self): hand1 = Hand() hand1.hand = [ Card(x, y) for x, y in [("A", "♥"), ("2", "♥"), ("3", "♥"), ("T", "♥"), ("J", "♥"), ("Q", "♥")] ] hand2 = Hand() hand2.set_hand(hand1.hand) assert hand1.hand == hand2.hand
class Player(metaclass=ABCMeta): __metaclass__ = ABCMeta def __init__(self, num): self.num = num self.game_score = 0 self.hand = Hand() self.melds = Melds() self.round = None self.ai_only = False def __str__(self): return "Player %i" % self.num def turn(self, game_round): self.round = game_round def take_from_deck(self): self.hand.draw_card(self.round.deck.take_card()) def take_from_discard(self): self.hand.draw_card(self.round.deck.take_discard()) def discard(self, user_input): user_input = int(user_input) - 1 self.round.deck.discard_card(self.hand.discard_card(user_input)) def knock(self): self.round.show_knocked = True def get_name(self): return str(self) def update_score(self): self.game_score += self.hand.get_score() def get_hand(self): return self.hand def get_game_score(self): return self.game_score def display_round_score(self): return self.hand.score def has_someone_knocked(self): return self.round.knocked
def test_draw_card(self): hand = Hand() hand.draw_card(Card("A", "♥")) assert re.match(r'A.*?♥', str(hand))
def test_hand(self): hand = Hand() assert hand.score == 0
class Player(metaclass=ABCMeta): __metaclass__ = ABCMeta def __init__(self, num): self.num = num self.game_score = 0 self.hand = Hand() self.melds = Melds() self.round = None self.ai_only = False def __str__(self): return "Player %i" % self.num def turn(self, game_round, ai_only): self.round = game_round self.ai_only = ai_only self.has_someone_knocked() self.choose_to_discard_or_pick_up() self.discard_or_knock() def get_name(self): return "Player %i" % self.num def update_score(self): self.game_score += self.hand.get_score() def get_hand(self): return self.hand def get_game_score(self): return self.game_score def display_round_score(self): return self.hand.score def has_someone_knocked(self): if self.round.knocked: print(View.render(template=TEMPLATE_PATH + '/knocked.txt')) # Todo: move to new view class def render_turn_start(self): print(View.render( template=TEMPLATE_PATH + '/player-turn-start.txt', turn_number=self.round.turn, player_number=self.round.current_player + 1, score=self.hand.get_score(), hand=str(self.hand), discard=self.round.deck.show_discard() )) def render_player_turn_end(self): print(View.render( template=TEMPLATE_PATH + '/player-turn-end.txt', hand=str(self.hand), key=self.hand.get_key() )) @abstractmethod def choose_to_discard_or_pick_up(self): pass @abstractmethod def discard_or_knock(self): pass
def deal(self, deck: list): hand = Hand() for _ in range(self.cardCount): hand.draw_card(deck.pop()) return hand