-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaycards.py
38 lines (27 loc) · 1.14 KB
/
playcards.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import random
from typing import List, Tuple, Dict
# https://www.alt-codes.net/suit-cards.php
# '♠ ♥ ♣ ♦ ♤ ♡ ♧ ♢'
NAIPES = '♠ ♡ ♢ ♧'.split()
CARTAS = '2 3 4 5 6 7 8 9 10 j Q K A'.split()
CARTA = Tuple[str, str]
BARALHO = List[CARTA]
def criar_baralho(aleatorio: bool = False) -> BARALHO:
"""Criar um baralho com 52 cartas"""
baralho: BARALHO = [(n, c) for c in CARTAS for n in NAIPES]
if aleatorio:
random.shuffle(baralho)
return baralho
def distribuir_cartas(baralho: BARALHO) -> Tuple[BARALHO, BARALHO, BARALHO, BARALHO]:
"""Gerencia a mão de cartas de acordo com o baralho gerado"""
return baralho[0::4], baralho[1::4], baralho[2::4], baralho[3::4]
def jogar() -> None:
"""Inicia um jogo de cartas para 4 jogadores"""
cartas: BARALHO = criar_baralho(aleatorio=True)
jogadores: List[str] = 'P1 P2 P3 P4'.split()
maos: Dict[str, BARALHO] = {j: m for j, m in zip(jogadores, distribuir_cartas(cartas))}
for jogador, cartas in maos.items():
carta: str = ' '.join(f"{j}{c}" for (j, c) in cartas)
print(f'{jogador}: {carta}')
if __name__ == '__main__':
jogar()