Advertisement
DrunkenToad

Untitled

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