Advertisement
PrezesSmoku

Yahtzee

May 18th, 2023 (edited)
758
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.99 KB | None | 0 0
  1. import random
  2. kosci = [2,1,3,6,4]
  3.  
  4.  
  5. nazwy_punktow = ['Jedynki', 'Dwójki', 'Trójki', 'Czwórki', 'Piątki', "Szóstki",
  6.                  "3 jednakowe","4 jednakowe","Full","Mały strit","Duży strit","Generał","Szansa"]
  7. punkty = ['','','','','','','','','','','','','']
  8. def rzuc_koscmi(numery_kosci:str):
  9.     for i in numery_kosci:
  10.         index = int(i) - 1
  11.         kosci[index] = random.randint(1,6)
  12.      
  13. def pokaz_kosci():
  14.     print('_________________________')
  15.     for i in range(len(kosci)):
  16.         print(f'{i+1}. {kosci[i]}')
  17.     print('_________________________')
  18.  
  19. # def pokaz_kosci():
  20. #     print('_________________________')
  21. #     print(f'Kości: 1.{kosci[0]}/2.{kosci[1]}/3.{kosci[2]}/4.{kosci[3]}/5.{kosci[4]}/')
  22. #     print('_________________________')
  23.  
  24.  
  25. def sprawdz_czy_przerzucamy():
  26.     odp = input("czy chcesz przerzucać kości?(t/n) ")
  27.     if odp == 't' or odp == 'T':
  28.         return True
  29.     else:
  30.         return False
  31.  
  32. def pokaz_tabele_punktow():
  33.     print('_________________________')
  34.     for i in range(len(punkty)):
  35.         print(f'{i+1}.{nazwy_punktow[i]}\t{punkty[i]}')
  36.     print('_________________________')
  37.  
  38. def wstaw_w_liczbowym(liczba):
  39.     liczba_punktow = 0
  40.     for kosc in kosci:
  41.         if kosc == liczba:
  42.             liczba_punktow += kosc
  43.     punkty[liczba-1] = liczba_punktow
  44.  
  45. def wstaw_3i4_jednakowe(pole,ilosc):
  46.     lista_wystapien = [0,0,0,0,0,0]
  47.     for kosc in kosci:
  48.         lista_wystapien[kosc-1] += 1
  49.     if ilosc in lista_wystapien:
  50.         punkty[pole-1] = sum(kosci)
  51.     else:
  52.         punkty[pole-1] = 0
  53.  
  54. def wstaw_full(pole):
  55.     lista_wystapien = [0,0,0,0,0,0]
  56.     for kosc in kosci:
  57.         lista_wystapien[kosc-1] += 1
  58.     if 3 in lista_wystapien and 2 in lista_wystapien:
  59.         punkty[pole-1] = 25
  60.     else:
  61.         punkty[pole-1] = 0
  62.  
  63. def wstaw_duzy_strit(pole):
  64.     kosci.sort()
  65.     dlugosc_strita = 0
  66.     for i in range(1,5):
  67.         if kosci[i-1] == kosci[i] - 1:
  68.             dlugosc_strita += 1
  69.         else:
  70.             dlugosc_strita = 0
  71.     if dlugosc_strita == 4:
  72.         punkty[pole-1] = 40
  73.     else:
  74.         punkty[pole-1] = 0
  75.  
  76. def wstaw_maly_strit(pole):
  77.     kosci.sort()
  78.     dlugosc_strita = 0
  79.     for i in range(1,5):
  80.         if kosci[i-1] == kosci[i] - 1:
  81.             dlugosc_strita += 1
  82.             if dlugosc_strita == 3:
  83.                 punkty[pole-1] = 30
  84.                 return
  85.         else:
  86.             dlugosc_strita = 0
  87.     punkty[pole-1] = 0
  88.  
  89. def wstaw_general(pole):
  90.     lista_wystapien = [0,0,0,0,0,0]
  91.     for kosc in kosci:
  92.         lista_wystapien[kosc-1] += 1
  93.     if 5 in lista_wystapien:
  94.         punkty[pole-1] = 50
  95.     else:
  96.         punkty[pole-1] = 0
  97.  
  98. def wstaw_szansa(pole):
  99.     punkty[pole-1] = sum(kosci)
  100.  
  101. def wstaw_punkty():
  102.     pole = int(input('Gdzie chcesz wstawić punkty (podaj numer rubryki): '))
  103.     if punkty[pole-1] == '':
  104.         if 1 <= pole <= 6:
  105.             wstaw_w_liczbowym(pole)
  106.         elif pole == 7:
  107.             wstaw_3i4_jednakowe(pole,3)
  108.         elif pole == 8:
  109.             wstaw_3i4_jednakowe(pole,4)
  110.         elif pole == 9:
  111.             wstaw_full(pole)
  112.         elif pole == 10:
  113.             wstaw_maly_strit(pole)
  114.         elif pole == 11:
  115.             wstaw_duzy_strit(pole)
  116.         elif pole == 12:
  117.             wstaw_general(pole)
  118.         elif pole == 13:
  119.             wstaw_szansa(pole)
  120.     else:
  121.         print('Wybrałeś pole w którym już wstawiłeś punkty')
  122.         wstaw_punkty()
  123.  
  124.  
  125.  
  126. for tura in range(13):
  127.     rzuc_koscmi("12345")
  128.     pokaz_tabele_punktow()
  129.     pokaz_kosci()
  130.     for i in range(2):
  131.         czy_przerzut = sprawdz_czy_przerzucamy()
  132.         if czy_przerzut:
  133.             kosci_do_przerzutu = input("Wypisz numery kości, które chcesz przerzucić(bez spacji): ")
  134.             rzuc_koscmi(kosci_do_przerzutu)
  135.             pokaz_kosci()
  136.         else:
  137.             break
  138.     pokaz_tabele_punktow()
  139.     pokaz_kosci()
  140.     wstaw_punkty()
  141.     pokaz_tabele_punktow()
  142.  
  143. print(f"Twój wynik to: {sum(punkty)}")
  144.  
  145.  
  146.  
  147.  
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement