Advertisement
DrunkenToad

Untitled

Oct 16th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 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 move(self):
  9.         return moves[0]
  10.  
  11.     def learn(self, my_move, their_move):
  12.         pass
  13.    
  14.  
  15. class Random(Player):
  16.     def move(self):
  17.         return(random.choice(moves))
  18.    
  19.     def learn(self, my_move, their_move):
  20.         pass
  21.  
  22. class Human(Player):
  23.     def move(self):
  24.         self.Humanmove = []
  25.         while self.Humanmove == []:
  26.             self.Humanmove = str.lower(input("rock, paper, scissors:  "))
  27.             if self.Humanmove not in moves:
  28.                 print("Invalid move, try again")
  29.                 self.Humanmove = []
  30.             else:
  31.                 return self.Humanmove
  32.  
  33.    
  34. class Reflect(Player):
  35.     def __init__(self):
  36.         self.Refmove = []
  37.     def move(self):
  38.         if self.Refmove == []:
  39.             return moves[0]
  40.         else:
  41.             return self.Refmove
  42.     def learn(self, my_move, their_move):
  43.         self.Refmove = their_move
  44.    
  45.    
  46.      
  47. class Cycle(Player):
  48.     def __init__(self):
  49.         self.Cmove = []
  50.     def move(self):
  51.         if self.Cmove == []:
  52.             return moves [0]
  53.         else:
  54.             return self.Cmove
  55.     def learn(self, my_move, their_move):
  56.         if my_move == moves[0]:
  57.             self.Cmove = moves[1]
  58.         elif my_move == moves[1]:
  59.             self.Cmove = moves[2]
  60.         else:
  61.             self.Cmove = moves[0]
  62.    
  63.  
  64. class Game:
  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.         if beats(move1, move2):
  84.             self.p1.score += 1
  85.             print("Winner!")
  86.         if beats(move2, move1):
  87.             self.p2.score += 1
  88.         else:
  89.             print("TIE")
  90.  
  91.     def play_game(self):
  92.         print("Game start!")
  93.         print("Current Score: ", score)
  94.         for round in range(1, 6):
  95.             print(f"Round {round}:")
  96.             self.play_round()
  97.             print("Current Score: ", score)
  98.         print("Game over!")
  99.  
  100.  
  101. if __name__ == '__main__':
  102.     game = Game(Human(), Player())
  103.     game.play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement