Advertisement
HasteBin0

Python Rock/Paper/Scissors Observation

Dec 23rd, 2017
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.22 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. def reroute(i: int) -> str:
  4.     if i == 0: return "Rock"
  5.     if i == 1: return "Paper"
  6.     if i == 2: return "Scissors"
  7.     return
  8.  
  9. def beats(x: int, y: int) -> bool:
  10.     if x == 0: # Rock
  11.         if y == 0: return False # draws to Rock
  12.         if y == 1: return False # loses to Paper
  13.         if y == 2: return True  # wins  to Scissors
  14.     if x == 1: # Paper
  15.         if y == 0: return True  # wins  to Rock
  16.         if y == 1: return False # draws to Paper
  17.         if y == 2: return False # loses to Scissors
  18.     if x == 2: # Scissors
  19.         if y == 0: return False # loses to Rock
  20.         if y == 1: return True  # wins  to Paper
  21.         if y == 2: return False # draws to Scissors
  22.     return
  23.  
  24. def beat(x: int, y: int) -> bool:
  25.     return (x + 2) % 3 == y
  26.  
  27. print(not any((beat(a, b) ^ beats(a, b)) for a in (0, 1, 2) for b in (0, 1, 2)),
  28.       end='\n\n')
  29.  
  30. winners: [int] = [0, 0, 0]
  31.  
  32. for a in (0, 1, 2):
  33.     for b in (0, 1, 2):
  34.         c: bool = beat(a, b)
  35.         print(reroute(a), ('beats' if c else 'loses'), reroute(b))
  36.         if c: winners[a] += 1
  37.  
  38. print("\nWins",
  39.       f"Rock    {winners[0]}",
  40.       f"Paper   {winners[1]}",
  41.       f"Scissors {winners[2]}",
  42.       sep='\n')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement