def game(self): dealer = Dealer(self.players) dealer.deal() current_player = dealer.who_starts() cards = CardList([]) while True: if (all(player.last_played_cards.type == HandType.PASS for player in current_player.opponents(self.players)) and current_player.last_played_cards.type != HandType.PASS): cards = CardList([]) current_player.last_played_cards = self.turn(current_player, cards) if current_player.last_played_cards.type != HandType.PASS: cards = current_player.last_played_cards if len(current_player.hand) > 0: current_player = current_player.next_player(self.players) else: self.outputter.display_player(current_player, cards.cards) break self.outputter.display_message( f"Player {current_player.name}, wielding {current_player.bot.name}, is the winner!" )
def turn(self, player, last_played_cards): while True: self.outputter.display_player(player, last_played_cards.cards) self.outputter.display_cards(player.hand, self.outputter.width / 32, 6 * self.outputter.height / 7) time.sleep(1) chosen_cards = (player.bot.choose_cards( last_played_cards, player.hand) if player.bot is not None else self.outputter.choose_cards(player.hand)) candidate_cards = CardList(chosen_cards) if candidate_cards.is_valid_play(player.hand, last_played_cards): self.outputter.display_cards( candidate_cards.cards, self.outputter.width / 2 - 2.5 * self.outputter.card_width, self.outputter.height / 2 - 0.5 * self.outputter.card_height, ) for card in candidate_cards.cards: player.hand.remove(card) player.hand.sort(key=lambda card: card.number) return candidate_cards
def choose_cards(self, last_card_list, hand): num_hand = len(hand) num_played = last_card_list.length if num_played == 0: return [hand[0]] elif num_played > 3: pass else: for i in range(0, num_hand - num_played + 1): selected_cards = hand[i : i + num_played] if CardList(selected_cards).is_valid_play(hand, last_card_list): return selected_cards return []
dealer = Dealer(self.players) dealer.deal() current_player = dealer.who_starts() cards = CardList([]) while True: if (all(player.last_played_cards.type == HandType.PASS for player in current_player.opponents(self.players)) and current_player.last_played_cards.type != HandType.PASS): cards = CardList([]) current_player.last_played_cards = self.turn(current_player, cards) if current_player.last_played_cards.type != HandType.PASS: cards = current_player.last_played_cards if len(current_player.hand) > 0: current_player = current_player.next_player(self.players) else: self.outputter.display_player(current_player, cards.cards) break self.outputter.display_message( f"Player {current_player.name}, wielding {current_player.bot.name}, is the winner!" ) if __name__ == "__main__": # App([Player("A", StupidBot()), Player("B", AlexBot())]) dealer = Dealer([Player("A", None), Player("B", None)]) dealer.deal() print( HandAnalyser(dealer.players[0].hand).find_possible_plays(CardList([]))) #print(HandAnalyser([Card(i) for i in range(0, 18)]).find_possible_plays(CardList([]))) print(dealer.players[0].hand)
def filter_valid(self, possible_plays, last_played_cards): return [ play for play in possible_plays if CardList(play).is_valid_play(self.cards, last_played_cards) ]
def __init__(self, name, bot): self.hand = [] self.last_played_cards = CardList([]) self.name = name self.bot = bot