Last active
December 14, 2018 19:07
-
-
Save Pharaoh00/e8612a221c98852cab6abf8917dfee7b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
"""This program plays a game of Rock, Paper, Scissors between two Players, | |
and reports both Player's scores each round.""" | |
moves = ['rock', 'paper', 'scissors'] | |
"""The Player class is the parent class for all of the Players | |
in this game""" | |
class player: | |
move1 = input("rock, paper, or scissors? Mind your case, though") | |
move2 = random.choice(moves) | |
def learn(my_move, their_move): | |
# NEED to refer with self | |
# This is on the class | |
self.move2 = my_move | |
self.their_move = my_move | |
self.my_move = move2 | |
def randomPlayer(self): | |
choice = moves[random.randint(0, 2)] | |
# When you return something | |
# The after does mean nothing | |
# As a said... return is the last thing you pass | |
"""return choice""" # old | |
# self.choice does exist... | |
# Here you put "self.choice()"? | |
# And self.choice is a Function? or a Variable? | |
# When you pass () this mean | |
# "This thing is a function" | |
# So, self.choice() is a function | |
# self.choice is a variable | |
move1 = self.choice() | |
# You a returning nothing! | |
return self.choice | |
def humanPlayer(self): | |
move2 = input("rock, paper, or scissors? Mind your case, though.") | |
# Againg, THIS does exist | |
# return is the last thing you pass | |
"""return move2""" # old | |
"""if move2 != "rock" or move2 != "paper" or move2 != "scissors": | |
move2 = input("please try again, and be sure to mind your case") | |
move2 = self.move2""" # old | |
if(self.move2 != "rock" or | |
self.move2 != "paper" or | |
self.move2 != "scissors"): | |
self.move2 = input("please try again, and be sure to mind your case") | |
self.move2 = self.move2 | |
return self.move2 | |
# STOP refer 'self' | |
# THIS DOES EXIST | |
# self means nothing outside the class | |
"""one = player.humanPlayer('self') | |
two = player.randomPlayer('self')""" # gold | |
one = player.humanPlayer() | |
two = player.randomPlayer() | |
# This function does make sense at all. | |
def beats(self, one, two): | |
result = None | |
# if one == two: | |
# return "tie" | |
# elif one == "rock": | |
# if two == "paper": | |
# return f"{two} wins" | |
# if two == "scissors": | |
# return f"{one} wins" | |
# elif one == "paper": | |
# if two == "rock": | |
# return f"{one} wins" | |
# if two == "scissors": | |
# return f"{two} wins" | |
# elif one == "scissors": | |
# if two == "rock": | |
# return f"{two} wins" | |
# if two == "paper": | |
# return f"{one} wins" | |
# Why you keep returning something? | |
# return is the LAST thing. | |
# | |
# Use format() to parse whats you need | |
# this: | |
# f"{} wins" does mean nothing. | |
# format() is more readible | |
if one == two: | |
result = "tie" | |
# return "tie" | |
elif one == "rock": | |
if two == "paper": | |
result = "{} win".format(two) | |
# return f"{two} wins" | |
if two == "scissors": | |
result = "{} win".format(one) | |
# return f"{one} wins" | |
elif one == "paper": | |
if two == "rock": | |
result = "{} win".format(one) | |
# return f"{one} wins" | |
if two == "scissors": | |
result = "{} win".format(two) | |
# return f"{two} wins" | |
elif one == "scissors": | |
if two == "rock": | |
result = "{} win".format(two) | |
# return f"{two} wins" | |
if two == "paper": | |
result = "{} win".format(one) | |
# return f"{one} wins" | |
return result | |
class Game: | |
# Whats program you are using for programming? | |
# Your indentation is all wrong on this class | |
# ALLWAYS is 4 spaces | |
# NOT TABS | |
# 4 spaces | |
# score1 = 0 | |
# score2 = 0 | |
# def __init__(self, p1, p2): | |
# self.p1 = p1 | |
# self.p2 = p2 | |
# def play_round(self): | |
# move1 = player.humanPlayer('self') | |
# move2 = player.randomPlayer('self') | |
# print(f"Player 1: {move1} Player 2: {move2} {beats('self', move1, move2)}") | |
# beats('self', move1, move2) | |
# print(f"Score1: {score1},Score2: {score2}") | |
# self.p1.learn(move1, move2) | |
# self.p2.learn(move2, move1) | |
# def play_game(self): | |
# print("Game start!") | |
# for round in range(3): | |
# print(f"Round {round}:") | |
# self.play_round() | |
# print("Game over!") | |
score1 = 0 | |
score2 = 0 | |
# Why you have init here and not on Player class? | |
# Does make sense. | |
def __init__(self, p1, p2): | |
self.p1 = p1 | |
self.p2 = p2 | |
def play_round(self): | |
# here you initialize move1? or move 2? | |
# Self again... just stop! | |
# move1 = player.humanPlayer('self') | |
# move2 = player.randomPlayer('self') | |
move1 = player.humanPlayer() | |
move2 = player.randomPlayer() | |
# print(f"Player 1: {move1} Player 2: {move2} {beats('self', move1, move2)}") | |
print("Player 1: {} - Player2: {} - Beats: {}".format(move1, move2, "smothing?")) # Cant understand the final sorry | |
# Self again. | |
# beats('self', move1, move2) | |
beats(move1, move2) | |
# print(f"Score1: {score1},Score2: {score2}") | |
# Here you update your scores? | |
# Because now, is 0. | |
# You initialize the values on top. | |
print("Score1: {} - Score2: {}".format(score1, score2)) | |
# Whats is this? Does make sense. | |
self.p1.learn(move1, move2) | |
self.p2.learn(move2, move1) | |
# All this function does make sense. | |
def play_game(self): | |
print("Game start!") | |
for round in range(3): | |
print(f"Round {round}:") | |
self.play_round() | |
print("Game over!") | |
# If you don't understand why you use this... Dont use. | |
# This is a advance stuff. | |
# For you to learn, forget about it. | |
if __name__ == '__main__': | |
# self again. | |
# game = Game(player.humanPlayer('self'), player.randomPlayer('self')) | |
# | |
# You need to re-organize you code. | |
# When you are calling Game class and passing the player class | |
# Really, i can't understand whats you are trying to do. | |
# All you code is strange. You are trying to do something | |
# you don't fully understand. | |
# Need more reading. More research. | |
# Stop use classes. You don't know whats you are doing. | |
# | |
# Make functions returing something. | |
# And pick the value from return and make something. | |
game = Game(player.humanPlayer(), player.randomPlayer()) | |
game.play_game() | |
# Like this: | |
# The player need to choice rock scissors paper, right? | |
# So ask the user for this: | |
import random | |
user = input("Pick: ") | |
moves = ['rock', 'paper', 'scissors'] | |
def Game(userInput): | |
# This will choice between the choices | |
computer = random.choice(moves) | |
if userInput == computer: | |
print("is tie") | |
elif userInput != computer: | |
print("You move {} - Computer move {}".format(userInput, computer)) | |
# You need to figure out, how to make all the possibilites. | |
Game(user) | |
# You see? | |
# Need to make more simples things | |
# You can make this example more elagente, and stuff | |
# But this works. | |
# Just a proof of concept, but works. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment