Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import string
- moves = ['rock', 'paper', 'scissors']
- class Player:
- def move(self):
- return moves[0]
- def learn(self, my_move, their_move):
- pass
- class Random(Player):
- def move(self):
- return(random.choice(moves))
- def learn(self, my_move, their_move):
- pass
- class Human(Player):
- def move(self):
- self.Humanmove = []
- while self.Humanmove == []:
- self.Humanmove = str.lower(input("rock, paper, scissors: "))
- if self.Humanmove not in moves:
- print("Invalid move, try again")
- self.Humanmove = []
- else:
- return self.Humanmove
- class Reflect(Player):
- def __init__(self):
- self.Refmove = []
- def move(self):
- if self.Refmove == []:
- return moves[0]
- else:
- return self.Refmove
- def learn(self, my_move, their_move):
- self.Refmove = their_move
- class Cycle(Player):
- def __init__(self):
- self.Cmove = []
- def move(self):
- if self.Cmove == []:
- return moves [0]
- else:
- return self.Cmove
- def learn(self, my_move, their_move):
- if my_move == moves[0]:
- self.Cmove = moves[1]
- elif my_move == moves[1]:
- self.Cmove = moves[2]
- else:
- self.Cmove = moves[0]
- class Game:
- def __init__(self, p1, p2):
- self.p1 = p1
- self.p2 = p2
- self.wins = 0
- self.loss = 0
- self.score1 = 0
- self.score2 = 0
- move1 = self.p1.move()
- move2 = self.p2.move()
- def beats(one, two):
- return ((one == 'rock' and two == 'scissors') or
- (one == 'scissors' and two == 'paper') or
- (one == 'paper' and two == 'rock'))
- def score(self):
- if beats(move1, move2):
- return self.wins += 1
- print("Winner!")
- if p1.move == p2.move:
- print("Tie!")
- elif beats(move2, move1):
- return self.loss += 1
- print("Winner!")
- def play_round(self):
- move1 = self.p1.move()
- move2 = self.p2.move()
- print(f"Player 1: {move1} Player 2: {move2}")
- self.p1.learn(move1, move2)
- self.p2.learn(move2, move1)
- self.score1 = self.wins
- self.score2 = self.wins
- def play_game(self):
- print("Game start!")
- for round in range(1, 6):
- print(f"Round {round}:")
- self.play_round()
- print(f"Your Score: {self.score1} Computer Score: {self.score2}")
- print("Game over!")
- if __name__ == '__main__':
- game = Game(Human(), Player())
- game.play_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement