예제 #1
0
def prev_tricks():
    first_trick = Trick(leading_player_index=0,
                        cards=[(OBER, ACORNS), (ACE, HEARTS), (KING, HEARTS),
                               (EIGHT, HEARTS)],
                        winner=0,
                        score=18)
    sec_trick = Trick(leading_player_index=0,
                      cards=[(UNTER, BELLS), (OBER, LEAVES), (UNTER, LEAVES),
                             (NINE, HEARTS)],
                      winner=1,
                      score=7)
    return [first_trick, sec_trick]
예제 #2
0
    def sample_game_state(self, public_info):
        # sample opponent hands
        if public_info["current_trick"] is None:
            current_trick = Trick(
                leading_player_index=public_info["leading_player_index"])
        else:
            current_trick = public_info["current_trick"]

        player_hands = sample_opponent_hands(
            tricks=public_info["tricks"],
            current_trick=current_trick,
            trumpcards=public_info["trumpcards"],
            playerindex=public_info["current_player_index"],
            player_hand=self.hand)

        # recreate possible mode proposals from public info
        mode_proposals = sample_mode_proposals(public_info)

        # add player_hands and possible actions to game state
        game_state = deepcopy(public_info)
        game_state["mode_proposals"] = mode_proposals
        game_state["player_hands"] = player_hands
        game = Game(game_state=game_state,
                    players=[
                        RandomPlayer(),
                        RandomPlayer(),
                        RandomPlayer(),
                        RandomPlayer()
                    ])
        game_state["possible_actions"] = game.get_possible_actions()

        return game_state
예제 #3
0
def test_possible_cards(trick_game_during):
    curr_trick = trick_game_during.current_trick
    hand = trick_game_during.playerlist[3].get_hand()
    assert trick_game_during.possible_cards(current_trick=curr_trick,
                                            hand=hand) == [(UNTER, HEARTS),
                                                           (ACE, LEAVES),
                                                           (NINE, LEAVES),
                                                           (EIGHT, LEAVES),
                                                           (TEN, BELLS),
                                                           (EIGHT, BELLS)]
    hand = trick_game_during.playerlist[0].get_hand()
    assert trick_game_during.possible_cards(current_trick=curr_trick,
                                            hand=hand) == [(TEN, ACORNS),
                                                           (NINE, ACORNS),
                                                           (SEVEN, ACORNS)]
    curr_trick = Trick(leading_player_index=0,
                       cards=[(SEVEN, HEARTS), None, None, None])
    hand = trick_game_during.playerlist[3].get_hand()
    assert trick_game_during.possible_cards(current_trick=curr_trick,
                                            hand=hand) == [(UNTER, HEARTS)]
    hand = trick_game_during.playerlist[1].get_hand()
    assert trick_game_during.possible_cards(current_trick=curr_trick,
                                            hand=hand) == [(OBER, HEARTS),
                                                           (UNTER, ACORNS),
                                                           (SEVEN, HEARTS)]
예제 #4
0
def test_play_wenz(wenz_game):
    assert not wenz_game.finished()
    wenz_game.play()
    assert wenz_game.bidding_game.finished()
    assert wenz_game.bidding_game.game_mode == (WENZ, None)
    assert wenz_game.trick_game.finished()
    assert len(wenz_game.trick_game.tricks) == 8
    trick = Trick(leading_player_index=3,
                  cards=[(KING, LEAVES), (KING, BELLS), (TEN, HEARTS),
                         (NINE, HEARTS)],
                  winner=2,
                  score=18)
    trick.current_player_index = 2
    assert wenz_game.trick_game.tricks[-1] == trick
예제 #5
0
def test_play_partner_mode(partner_game):
    assert not partner_game.finished()
    partner_game.play()
    assert partner_game.bidding_game.finished()
    assert partner_game.trick_game.offensive_players == [1, 0]
    assert partner_game.trick_game.finished()
    assert len(partner_game.trick_game.tricks) == 8
    trick = Trick(leading_player_index=1,
                  cards=[(NINE, ACORNS), (SEVEN, BELLS), (KING, ACORNS),
                         (TEN, BELLS)],
                  winner=3,
                  score=14)
    trick.current_player_index = 0
    assert partner_game.trick_game.tricks[-1] == trick
예제 #6
0
def test_play_solo(solo_game):
    assert not solo_game.finished()
    solo_game.play()
    assert solo_game.bidding_game.finished()
    assert solo_game.bidding_game.game_mode == (SOLO, ACORNS)
    assert solo_game.trick_game.finished()
    assert len(solo_game.trick_game.tricks) == 8
    trick = Trick(leading_player_index=1,
                  cards=[(SEVEN, BELLS), (TEN, BELLS), (NINE, BELLS),
                         (ACE, BELLS)],
                  winner=3,
                  score=21)
    trick.current_player_index = 0
    assert solo_game.trick_game.tricks[2] == trick
예제 #7
0
def get_possible_cards(game_mode, card_sequence, player_hand):
    num_cards_curr_trick = len(card_sequence) % 4
    if len(card_sequence) == 0:
        return player_hand
    else:
        first_card = card_sequence[-num_cards_curr_trick][0]
        leading_player = card_sequence[-num_cards_curr_trick][1]
        curr_trick = Trick(leading_player_index=leading_player)
        curr_trick.num_cards = num_cards_curr_trick
        curr_trick.cards[leading_player] = first_card
        previously_ran_away = False
        if game_mode == (PARTNER_MODE, ACORNS):
            num_tricks_before = len(card_sequence) // 4
            for card_index in range(0, num_tricks_before, 4):
                # check if ACORNS was played in that trick
                first_card = card_sequence[card_index][0]
                if first_card[1] == ACORNS and first_card[0] not in [UNTER, OBER]:
                    # if yes, check if ACE was played
                    cards_in_trick = [c[0] for c in card_sequence[card_index: card_index + 4]]
                    if (ACE, ACORNS) not in cards_in_trick:
                        previously_ran_away = True
        return possible_cards(game_mode, curr_trick, player_hand, previously_ran_away)
예제 #8
0
 def __init__(self, playerlist, game_state):
     self.playerlist = playerlist
     self.max_num_tricks = 8
     self.leading_player_index = game_state['leading_player_index']
     self.game_mode = game_state['game_mode']
     self.mode_proposals = game_state['mode_proposals']
     self.offensive_players = [game_state['declaring_player']]
     if self.game_mode[0] == PARTNER_MODE:
         for player in self.playerlist:
             if (7, self.game_mode[1]) in player.starting_hand:
                 self.offensive_players.append(
                     self.playerlist.index(player))
                 break
     self.trumpcards = define_trumpcards(self.game_mode)
     self.tricks = game_state['tricks']
     if game_state['current_trick'] is not None:
         self.current_trick = game_state['current_trick']
     else:
         self.current_trick = Trick(
             leading_player_index=self.leading_player_index)
     self.current_player_index = self.current_trick.current_player_index
     self.scores = [0 for player in playerlist]
     for trick in game_state["tricks"]:
         self.scores[trick.winner] += trick.calculate_points()
예제 #9
0
 def reset_current_trick(self):
     self.tricks.append(self.current_trick)
     self.current_trick = Trick(self.current_player_index)
예제 #10
0
def current_trick():
    curr_trick = Trick(leading_player_index=1,
                       cards=[None, (ACE, ACORNS), (EIGHT, ACORNS), None])
    return curr_trick
예제 #11
0
import pytest
from schafkopf.trick import Trick
import schafkopf.helpers as hlp
from schafkopf.suits import BELLS, HEARTS, LEAVES, ACORNS, SUITS
from schafkopf.ranks import SEVEN, EIGHT, NINE, UNTER, OBER, KING, TEN, ACE, RANKS


trumpcards = [(OBER, i) for i in SUITS] + [(UNTER, i) for i in SUITS] \
                    + [(ACE, HEARTS), (TEN, HEARTS), (KING, HEARTS), (NINE, HEARTS), (EIGHT, HEARTS), (SEVEN, HEARTS)]

first_trick = Trick(leading_player_index=0)
first_trick.cards = [(NINE, HEARTS), (UNTER, ACORNS), (OBER, HEARTS),
                     (TEN, BELLS)]
first_trick.score = 15
first_trick.winner = 2
sec_trick = Trick(leading_player_index=2)
sec_trick.cards = [(ACE, LEAVES), (ACE, HEARTS), (ACE, ACORNS),
                   (SEVEN, ACORNS)]
sec_trick.score = 26
sec_trick.winner = 1

tricks = [first_trick, sec_trick]

current_trick = Trick(leading_player_index=1)
current_trick.cards = [None, (UNTER, BELLS), (TEN, LEAVES), None]

playerindex = 1
player_hand = [(TEN, HEARTS), (OBER, LEAVES), (UNTER, LEAVES), (SEVEN, LEAVES),
               (OBER, BELLS)]