daily pastebin goal
4%
SHARE
TWEET

Untitled

DrunkenToad Oct 16th, 2018 66 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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.             self.wins + 1
  82.             print(self.wins)
  83.         if p1.move == p2.move:
  84.             print("Tie")
  85.         elif beats(move2, move1):
  86.             self.loss + 1
  87.    
  88.     def play_round(self):
  89.         move1 = self.p1.move()
  90.         move2 = self.p2.move()
  91.         print(f"Player 1: {move1}  Player 2: {move2}")
  92.         self.p1.learn(move1, move2)
  93.         self.p2.learn(move2, move1)
  94.         self.score1 = self.wins
  95.         self.score2 = self.wins
  96.         print(f"Player 1: Score {self.score1} Player 2 Score: {self.score2}")  
  97.  
  98.     def play_game(self):
  99.         print("Game start!")
  100.         print("Current Score: ", self.score)
  101.         for round in range(1, 6):
  102.             print(f"Round {round}:")
  103.             self.play_round()
  104.             print("Game over!")
  105.  
  106.  
  107. if __name__ == '__main__':
  108.     game = Game(Human(), Player())
  109.     game.play_game()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top