MatteB_01

poker

Jan 30th, 2022
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.87 KB | None | 0 0
  1. from random import shuffle
  2.  
  3. FILE = "mazzo.txt"
  4. VALORI = ["2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A"]
  5. SEMI = {"Q": "\u2662" , "C" : "\u2661", "F" : "\u2663" , "P" : "\u2660"}
  6.  
  7.  
  8. def main():
  9.  
  10.     with open(FILE, "r") as file:
  11.         mazzo = []
  12.         for carta in file:
  13.             mazzo.append(carta.strip())
  14.  
  15.     shuffle(mazzo)
  16.  
  17.     with open(FILE, "w") as file:
  18.         for carta in mazzo:
  19.             file.write(f"{carta}\n")
  20.  
  21.     while len(mazzo) >=5:
  22.         evaluate(mazzo[:5])
  23.         mazzo = mazzo[5:]
  24.  
  25.  
  26. def evaluate(mano):
  27.     valoriMano = []
  28.     colore = False
  29.     scala = False
  30.     poker = False
  31.     full = False
  32.     tris = False
  33.     coppia = False
  34.     doppiaCoppia = False
  35.  
  36.  
  37.     for carta in mano:
  38.         valori = carta.split(" ")
  39.         valoriMano.append({"numero" : valori[0], "seme" : valori[1]})
  40.  
  41.     #---SCALA, COLORE E SCALA REALE-----------
  42.  
  43.     for i in range(len(valoriMano)):
  44.  
  45.         if valoriMano[i]["seme"] == valoriMano[i-1]["seme"]:
  46.             colore = True
  47.         else:
  48.             colore = False
  49.             break
  50.  
  51.     ordinate = []
  52.     for carta in valoriMano:
  53.         ordinate.append(VALORI.index(carta["numero"]))
  54.     ordinate.sort()
  55.  
  56.     for i in range(len(ordinate)):
  57.         if i != 0 and (ordinate[i] == ordinate[i - 1] + 1):
  58.             scala = True
  59.  
  60.         elif i == 0:
  61.                 if (ordinate[i] == 0 and ordinate[i - 1] == 12):
  62.                     scala = True
  63.         else:
  64.             scala = False
  65.             break
  66.  
  67.     #----------POKER, FULL, TRIS, DOPPIA COPPIA E COPPIA---------
  68.  
  69.     counter = 0
  70.     verify = {}
  71.     for carta in valoriMano:
  72.  
  73.         if carta["numero"] not in verify:
  74.             verify[carta["numero"]] = 1
  75.         else:
  76.             verify[carta["numero"]] += 1
  77.  
  78.  
  79.     if 4 in verify.values():
  80.         poker = True
  81.     elif 3 in verify.values() and 2 in verify.values():
  82.         full = True
  83.  
  84.     coppie = 0
  85.  
  86.     for val in verify.values():
  87.         if val == 2:
  88.             coppie += 1
  89.  
  90.     if coppie == 2:
  91.         doppiaCoppia = True
  92.  
  93.     elif coppie == 1:
  94.         coppia = True
  95.  
  96.     #-------------STAMPA A SCHERMO DEI RISULTATI----------------
  97.     # #CARTE
  98.     for carta in valoriMano:
  99.         print(f"{carta['numero']}{SEMI[carta['seme']]}", end= " ")
  100.  
  101.  
  102.     #PUNTI
  103.     if scala and colore:
  104.         print(" | SCALA REALE!")
  105.         return
  106.  
  107.     elif poker:
  108.         print(" | POKER!")
  109.         return
  110.  
  111.     elif colore:
  112.         print(" | COLORE!")
  113.         return
  114.  
  115.     elif full:
  116.         print(" | FULL!")
  117.         return
  118.  
  119.     elif scala:
  120.         print(" | SCALA!")
  121.  
  122.     elif tris:
  123.         print(" | TRIS!")
  124.  
  125.     elif doppiaCoppia:
  126.         print(" | DOPPIA COPPIA!")
  127.         return
  128.  
  129.     elif coppia:
  130.         print(" | COPPIA!")
  131.         return
  132.  
  133.     else:
  134.         print(" | niente  :/")
  135.         return
  136.  
  137.  
  138.  
  139. main()
Add Comment
Please, Sign In to add comment