Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. class Player:
  2. def __init__(self, deck):
  3. self.deck = deck
  4. self.battlefieldl = []
  5.  
  6. def can_play(self):
  7. return len(self.deck)
  8.  
  9. def battlefield(self, playvalue):
  10. self.battlefieldl = [self.deck.pop(0) for i in range(min(playvalue, 4))]
  11. return(self.battlefieldl)
  12.  
  13. def add_cards(self, battlefield):
  14. self.deck.extend(battlefield)
  15.  
  16. def main():
  17. deck1 = input("Insert the first half of the deck: ")
  18. deck2 = input("Insert the second half of the deck: ")
  19. player1 = Player(list(map(int, deck1.split())))
  20. player2 = Player(list(map(int, deck2.split())))
  21.  
  22. isLoser = False
  23. while not isLoser:
  24. if player1.can_play() == 0 and player2.can_play() == 0:
  25. return 0
  26. elif player1.can_play() == 0:
  27. return 1
  28. elif player2.can_play() == 0:
  29. return 2
  30.  
  31. x = min(player1.can_play(), player2.can_play())
  32.  
  33. battlefield1 = player1.battlefield(x)
  34. battlefield2 = player2.battlefield(x)
  35. while battlefield1[-1] == battlefield2[-1] and player1.can_play() !=0 and player2.can_play() != 0:
  36. x = min(player1.can_play(), player2.can_play())
  37. battlefield1.extend(player1.battlefield(x))
  38. battlefield2.extend(player2.battlefield(x))
  39.  
  40. if battlefield1[-1] > battlefield2[-1]:
  41. player1.add_cards(battlefield1)
  42. player1.add_cards(battlefield2)
  43. elif battlefield2[-1] > battlefield1[-1]:
  44. player2.add_cards(battlefield2)
  45. player2.add_cards(battlefield1)
  46. else:
  47. if player1.can_play() == 0 and player2.can_play() == 0:
  48. return 0
  49. elif player1.can_play() == 0:
  50. return 1
  51. else:
  52. return 2
  53.  
  54. if __name__ == "__main__":
  55. print(main())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement