Advertisement
DrunkenToad

Untitled

Oct 16th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.80 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.     def __init__(self, p1, p2):
  65.         self.p1 = p1
  66.         self.p2 = p2
  67.         self.wins = 0
  68.         self.loss = 0
  69.         self.score1 = 0
  70.         self.score2 = 0
  71.         move1 = self.p1.move()
  72.         move2 = self.p2.move()
  73.  
  74.     def beats(one, two):
  75.         return ((one == 'rock' and two == 'scissors') or
  76.                 (one == 'scissors' and two == 'paper') or
  77.                 (one == 'paper' and two == 'rock'))
  78.  
  79.     def score(self):
  80.         if beats(move1, move2):
  81.             return self.wins += 1
  82.             print("Winner!")
  83.         if p1.move == p2.move:
  84.             print("Tie!")
  85.         elif beats(move2, move1):
  86.             return self.loss += 1
  87.             print("Winner!")
  88.    
  89.     def play_round(self):
  90.         move1 = self.p1.move()
  91.         move2 = self.p2.move()
  92.         print(f"Player 1: {move1}  Player 2: {move2}")
  93.         self.p1.learn(move1, move2)
  94.         self.p2.learn(move2, move1)
  95.         self.score1 = self.wins
  96.         self.score2 = self.wins
  97.        
  98.  
  99.     def play_game(self):
  100.         print("Game start!")
  101.             for round in range(1, 6):
  102.             print(f"Round {round}:")
  103.             self.play_round()
  104.             print(f"Your Score: {self.score1} Computer Score: {self.score2}")
  105.             print("Game over!")
  106.  
  107.  
  108. if __name__ == '__main__':
  109.     game = Game(Human(), Player())
  110.     game.play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement