Facebook
From Ofer Hagai, 3 Years ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 81
  1. from random import randint
  2.  
  3.  
  4. class CardWar:
  5.     def __init__(self, a, b):
  6.         self.a = a
  7.         self.b = b
  8.         self.sideA = []
  9.         self.sideB = []
  10.  
  11.     def compare(self):
  12.         i = 0
  13.         while True:
  14.             if len(self.a) == 0 and len(self.b) == 0:
  15.  
  16.                 if len(self.sideA) > len(self.sideB):
  17.                     print(f'Side deck A = {self.sideA}')
  18.                     print(f'Side deck B = {self.sideB}')
  19.                     print('Player one has won the game')
  20.                     break
  21.                 print(f'Side deck A = {self.sideA}')
  22.                 print(f'Side deck B = {self.sideB}')
  23.                 print('Player two has won the game')
  24.                 break
  25.  
  26.             elif self.a[i] > self.b[i]:
  27.                 self.sideA.append(self.b[i])
  28.                 self.sideA.append(self.a[i])
  29.                 print(f'{self.a[i]} is bigger than {self.b[i]}, player one has won the round.')
  30.                 del self.a[i]
  31.                 del self.b[i]
  32.  
  33.  
  34.             elif self.a[i] < self.b[i]:
  35.                 self.sideB.append(a[i])
  36.                 self.sideB.append(b[i])
  37.                 print(f'{self.b[i]} is bigger than {self.a[i]}, player two has won the round.')
  38.                 del self.b[i]
  39.                 del self.a[i]
  40.  
  41.             else:
  42.                 while True:
  43.                     x = randint(1, 2)
  44.                     y = randint(1, 2)
  45.                     if x > y:
  46.                         self.sideA.append(b[i])
  47.                         self.sideA.append(a[i])
  48.                         print(f'{x} is bigger than {y}, player one has won the draw round.')
  49.                         del self.a[i]
  50.                         del self.b[i]
  51.  
  52.                         break
  53.                     elif x < y:
  54.                         self.sideB.append(self.a[i])
  55.                         self.sideB.append(self.b[i])
  56.                         print(f'{y} is bigger than {x}, player two has won the draw round.')
  57.                         del self.b[i]
  58.                         del self.a[i]
  59.  
  60.                         break
  61.                     else:
  62.                         continue
  63.  
  64.  
  65. a = [randint(1, 15) for i in range(15)]
  66. b = [randint(1, 15) for i in range(15)]
  67. game = CardWar(a, b)
  68. game.compare()
  69.  

Replies to Cards War rss

Title Name Language When
Re: Cards War Ofer Hagai text 3 Years ago.