Skip to content

Instantly share code, notes, and snippets.

@RobiPoire
Created December 8, 2022 09:23
Show Gist options
  • Save RobiPoire/4311b7bbeff0e4ee43b853f955b640ee to your computer and use it in GitHub Desktop.
Save RobiPoire/4311b7bbeff0e4ee43b853f955b640ee to your computer and use it in GitHub Desktop.
Jeu du chifoumi
"""
Chifoumi - Pierre Feuille Ciseaux
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Le jeu du chifoumi est un jeu de hasard dans lequel deux joueurs choisissent
l'un des trois symboles suivants : pierre, feuille ou ciseaux. Le but du jeu est
de faire apparaître un des trois symboles gagnants par rapport aux deux autres
symboles. Le symbole gagnant est déterminé par les règles suivantes :
- La pierre bat les ciseaux (en les écrasant)
- La feuille bat la pierre (en l'enveloppant)
- Les ciseaux battent la feuille (en la coupant)
Le joueur qui a fait apparaître le symbole gagnant remporte la partie.
Le deuxième joueur est un ordinateur qui choisit un symbole au hasard.
Avec un système de points, le premier joueur à atteindre 3 points remporte la
partie.
"""
from random import randint
def chifoumi(points_pour_gagner: int = 3) -> None:
"""Jeu du chifoumi
Args:
points_pour_gagner (int, optional): Nombre de points pour gagner. Defaults to 3.
"""
# Initialisation des variables
points_joueur = 0
points_ordi = 0
choix = ["pierre", "feuille", "ciseaux"]
# Boucle de jeu
while points_joueur < points_pour_gagner and points_ordi < points_pour_gagner:
# Demande du choix du joueur
choix_joueur = input(
"Choisissez un symbole (pierre, feuille, ciseaux) : ").lower()
# Vérification du choix du joueur
while choix_joueur not in choix:
print("Choix invalide !")
choix_joueur = input(
"Choisissez un symbole (pierre, feuille, ciseaux) : ").lower()
# Choix aléatoire de l'ordinateur
choix_ordi = choix[randint(0, 2)]
# Affichage des choix
print("Vous avez choisi {} et l'ordinateur a choisi {}".format(
choix_joueur, choix_ordi))
# Détermination du vainqueur
if choix_joueur == choix_ordi:
print("Egalité !")
elif choix_joueur == "pierre":
if choix_ordi == "ciseaux":
print("Vous avez gagné !")
points_joueur += 1
else:
print("Vous avez perdu !")
points_ordi += 1
elif choix_joueur == "feuille":
if choix_ordi == "pierre":
print("Vous avez gagné !")
points_joueur += 1
else:
print("Vous avez perdu !")
points_ordi += 1
elif choix_joueur == "ciseaux":
if choix_ordi == "feuille":
print("Vous avez gagné !")
points_joueur += 1
else:
print("Vous avez perdu !")
points_ordi += 1
# Affichage des points
print(
f"Vous avez {points_joueur} points et l'ordinateur a {points_ordi} points, il vous en faut {points_pour_gagner} pour gagner.")
# Affichage du vainqueur
if points_joueur == 3:
print("Vous avez gagné !")
else:
print("Vous avez perdu !")
if __name__ == "__main__":
while True:
chifoumi()
# Demande si on veut rejouer
rejouer = input("Voulez-vous rejouer (o/n) ? ").lower()
while rejouer not in ["o", "n"]:
print("Choix invalide !")
rejouer = input("Voulez-vous rejouer (o/n) ? ").lower()
if rejouer == "n":
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment