Advertisement
MeckeOfficial

Farkle Gamelogic to calculate Points

Dec 27th, 2022 (edited)
1,111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.64 KB | Source Code | 0 0
  1. # Input an Array of Numbers like [1,2,2,3,4,4]
  2. async def calc_points(points):
  3.  
  4.     print(sorted(points))
  5.     result = 0
  6.  
  7.     score = {
  8.         "1":0,
  9.         "2":0,
  10.         "3":0,
  11.         "4":0,
  12.         "5":0,
  13.         "6":0,
  14.     }
  15.  
  16.     for p in points:
  17.         score[str(p)] += 1
  18.  
  19.     a = score["1"]
  20.     b = score["2"]
  21.     c = score["3"]
  22.     d = score["4"]
  23.     e = score["5"]
  24.     f = score["6"]
  25.  
  26.     if a and b and c and d and e and f == 1:
  27.         result += 1500
  28.        
  29.     elif a and b and c and d and e >= 1:
  30.  
  31.         if a == 2:
  32.             result += 100
  33.         elif e == 2:
  34.             result += 50
  35.        
  36.         result += 500
  37.    
  38.     elif b and c and d and e and f >= 1:
  39.  
  40.         if a == 2:
  41.             result += 100
  42.         elif e == 2:
  43.             result += 50
  44.        
  45.         result += 750
  46.  
  47.     for k in score:
  48.         if score[k] < 3:
  49.  
  50.             if int(k) == 1:
  51.                 result += 100 * score[k]
  52.             elif int(k) == 5:
  53.                 result += 50 * score[k]
  54.  
  55.         if score[k] == 3:
  56.             if int(k) == 1:
  57.                 result += 1000
  58.             else:
  59.                 result += int(k) * 100
  60.  
  61.         elif score[k] == 4:
  62.             if int(k) == 1:
  63.                 result += 2000
  64.             else:
  65.                 result += int(k) * 100 * 2
  66.  
  67.         elif score[k] == 5:
  68.             if int(k) == 1:
  69.                 result += 4000
  70.             else:
  71.                 result += int(k) * 100 * 4
  72.  
  73.         elif score[k] == 6:
  74.             if int(k) == 1:
  75.                 result += 8000
  76.             else:
  77.                 result += int(k) * 100 * 8
  78.  
  79.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement