DrunkenToad

Untitled

Oct 16th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.66 KB | None | 0 0
  1. import random
  2. import string
  3.  
  4. moves = ['rock', 'paper', 'scissors']
  5.  
  6. class Player:
  7.     def move(self):
  8.         return moves[0]
  9.  
  10.     def learn(self, my_move, their_move):
  11.         pass
  12.    
  13.  
  14. class Random(Player):
  15.     def move(self):
  16.         return(random.choice(moves))
  17.    
  18.     def learn(self, my_move, their_move):
  19.         pass
  20.  
  21. class Human(Player):
  22.     def move(self):
  23.         self.Humanmove = []
  24.         while self.Humanmove == []:
  25.             self.Humanmove = str.lower(input("rock, paper, scissors:  "))
  26.             if self.Humanmove not in moves:
  27.                 print("Invalid move, try again")
  28.                 self.Humanmove = []
  29.             else:
  30.                 return self.Humanmove
  31.  
  32.    
  33. class Reflect(Player):
  34.     def __init__(self):
  35.         self.Refmove = []
  36.     def move(self):
  37.         if self.Refmove == []:
  38.             return moves[0]
  39.         else:
  40.             return self.Refmove
  41.     def learn(self, my_move, their_move):
  42.         self.Refmove = their_move
  43.    
  44.    
  45.      
  46. class Cycle(Player):
  47.     def __init__(self):
  48.         self.Cmove = []
  49.     def move(self):
  50.         if self.Cmove == []:
  51.             return moves [0]
  52.         else:
  53.             return self.Cmove
  54.     def learn(self, my_move, their_move):
  55.         if my_move == moves[0]:
  56.             self.Cmove = moves[1]
  57.         elif my_move == moves[1]:
  58.             self.Cmove = moves[2]
  59.         else:
  60.             self.Cmove = moves[0]
  61.    
  62.  
  63. class Game:
  64.     score = 0
  65.     def __init__(self, p1, p2):
  66.         self.p1 = p1
  67.         self.p2 = p2
  68.  
  69.     def beats(one, two):
  70.         return ((one == 'rock' and two == 'scissors') or
  71.                 (one == 'scissors' and two == 'paper') or
  72.                 (one == 'paper' and two == 'rock'))
  73.    
  74.     def play_round(self):
  75.         move1 = self.p1.move()
  76.         move2 = self.p2.move()
  77.         print(f"Player 1: {move1}  Player 2: {move2}")
  78.         #print winner here
  79.         self.p1.learn(move1, move2)
  80.         self.p2.learn(move2, move1)
  81.  
  82.     def points(self):
  83.         self.p1.points = score()
  84.         self.p2.points = score()
  85.         if beats(one == two):
  86.             print("Its's a tie.")
  87.         elif beats(two == one or two - one == 2):
  88.             print("wins.", self.points + 1)
  89.         else:
  90.             print("wins.", self.points + 1)
  91.  
  92.     def play_game(self):
  93.         print("Game start!")
  94.         print("Current Score: ", self.score)
  95.         for round in range(1, 6):
  96.             print(f"Round {round}:")
  97.             self.play_round()
  98.             print("Current Score: ", self.score)
  99.         print("Game over!")
  100.  
  101.  
  102. if __name__ == '__main__':
  103.     game = Game(Human(), Player())
  104.     game.play_game()
Advertisement
Add Comment
Please, Sign In to add comment