Skip to content

Instantly share code, notes, and snippets.

@indriApollo
Last active February 6, 2021 02:12
Show Gist options
  • Save indriApollo/a8ce843f7c9ed8374d8d529407bc7372 to your computer and use it in GitHub Desktop.
Save indriApollo/a8ce843f7c9ed8374d8d529407bc7372 to your computer and use it in GitHub Desktop.
pierre papier ciseaux bodeux
#!/usr/bin/env python3
# pierre - papier - ciseau
# 2 joueurs
# input des noms
# n parties jouées
import random
choices = ["paper", "rock", "scissor"]
# -1 = lost, 0 = draw, 1 = win
choiceLookup = [
[0, 1, -1], # paper
[-1, 0, 1], # rock
[1, -1, 0] # scissor
]
class Player:
name = ""
choice = 0
victories = 0
defeats = 0
def __init__(self, n):
self.name = n
def choose(self):
self.choice = random.randrange(0,len(choices))
print(self.name + " chose " + choices[self.choice])
def gameLoop():
p1.choose()
p2.choose()
r = choiceLookup[p1.choice][p2.choice]
if r == -1:
print(p2.name + " won")
p2.victories += 1
p1.defeats += 1
elif r == 0:
print("draw")
elif r == 1:
print(p1.name + " won")
p1.victories += 1
p2.defeats += 1
def pScoreboard(p):
print("Player : " + p.name)
print("Victories : " + str(p.victories))
print("Defeats : " + str(p.defeats))
print("Player 1: ", end="")
p1 = Player(input())
print("Player 2: ", end="")
p2 = Player(input())
print("Ready ? Let's go !")
while True:
gameLoop()
print("Another round ? (y/n)", end="")
if input() != "y":
break
print("SCOREBOARD")
print("==========")
pScoreboard(p1)
pScoreboard(p2)
print("Total Games : " + str(p1.victories + p2.victories))
print("Thanks for playing !")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment