Esempio n. 1
0
    async def play(self, last_cards) -> TEvent:
        # cards = [] if not table_buffer else table_buffer[-1]
        validator = CardsValidator(last_cards, self.hand)

        for penalty in range(3):
            await self.extplayer.play(last_cards, validator.verify)

            if validator.played_cards is not None:
                if len(validator.played_cards) == 0:
                    return TEvent(TEventType.Pass, self.player_number)
                else:
                    cards = validator.played_cards
                    try:
                        self.remove_from_hand(cards)
                        return TEvent(TEventType.Plays, self.player_number,
                                      cards)
                    except ValueError as e:
                        print(e)

            else:
                print("Player {} did wrong!".format(self.player_number))

        print("Player {} had its chance -> Forced passing!".format(
            self.player_number))
        return TEvent(TEventType.Pass, None)
Esempio n. 2
0
 def logEventParams(self,
                    current_pl_number: int,
                    event,
                    data=None,
                    message=None):
     ev = TEvent(event, current_pl_number, data, message)
     self.logEvent(ev)
Esempio n. 3
0
 async def dist_first(self, cards: List[Card]):
     await super().dist_first(cards)
     # super().init_cards(cards, player_number)
     await self.server_events.put(TEvent(TEventType.Dist1, cards))
     while True:
         event = await self.client_events.get()
         if event.event == TEventType.BigTichu or event.event == TEventType.Ack:
             return event
Esempio n. 4
0
 async def schupf(self) -> Dict[int, Card]:
     await self.server_events.put(
         TEvent(TEventType.Schupf, self.player_number))
     schupfed = False
     while not schupfed:
         event: TEvent = await self.client_events.get()
         if event.event == TEventType.Schupf:
             return event.data
Esempio n. 5
0
 async def play(self,
                lastcards: Set[Card],
                card_receiver: Callable[[Set[Card], bool], bool],
                wish=None) -> Set[Card]:
     # get cards from connection
     # await remote action?
     valid = False
     event = TEvent(TEventType.Plays, self.player_number, lastcards)
     while not valid:
         await self.server_events.put(event)
         client_event = await self.client_events.get()
         print(client_event)
Esempio n. 6
0
def tevent_hook(o):
    if '_event' not in o:
        return o
    _event = o['_event']
    # type
    type = TEventType[_event['type']]
    player = _event.get('player')
    message = _event.get('message')
    # todo: decode cards better
    data = _event.get('data')
    if type == TEventType.Plays:
        data = tcards(data)
    elif type == TEventType.Wish:
        data = tcards(data)

    return TEvent(type, data, message)
Esempio n. 7
0
 async def dist_second(self, cards: List[Card]):
     self.hand.update(cards)
     return TEvent(TEventType.Ack, self.player_number)
Esempio n. 8
0
 async def dist_first(self, cards: List[Card]):
     self.hand = set(cards)
     return TEvent(TEventType.Ack, self.player_number)