0% ont trouvé ce document utile (0 vote)
32 vues6 pages

Projet Ens Maths s2

Le document présente un projet de jeu Pierre-Papier-Ciseaux, incluant les règles et les fonctionnalités du jeu. Il fournit un algorithme détaillé pour réaliser le jeu, ainsi qu'une traduction de cet algorithme en langage C. Le code C permet au joueur de choisir une option, compare le choix avec celui de l'ordinateur et affiche le résultat, avec la possibilité de rejouer.

Transféré par

amineboutahar199
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd
0% ont trouvé ce document utile (0 vote)
32 vues6 pages

Projet Ens Maths s2

Le document présente un projet de jeu Pierre-Papier-Ciseaux, incluant les règles et les fonctionnalités du jeu. Il fournit un algorithme détaillé pour réaliser le jeu, ainsi qu'une traduction de cet algorithme en langage C. Le code C permet au joueur de choisir une option, compare le choix avec celui de l'ordinateur et affiche le résultat, avec la possibilité de rejouer.

Transféré par

amineboutahar199
Copyright
© © All Rights Reserved
Nous prenons très au sérieux les droits relatifs au contenu. Si vous pensez qu’il s’agit de votre contenu, signalez une atteinte au droit d’auteur ici.
Formats disponibles
Téléchargez aux formats DOCX, PDF, TXT ou lisez en ligne sur Scribd

RESULTAT DE PROGRAMME :

Ecole normale supérieure


Université Mohammed V de Rabat
CLE-MATH S2
Informatique 2
Mohamed Amine Boutahar
PROJET:

*Jeu : Pierre - Papier - Ciseaux*


Règles :

- Pierre bat Ciseaux

- Ciseaux battent Papier

- Papier bat Pierre

Fonctionnalités :

1. Choix du joueur

2. Choix aléatoire de l’ordinateur

3. Affichage du résultat

4. Option pour rejouer

*Questions*

A. Ecrire un algorithme qui peut réaliser ce jeu.

B. Traduire cet algorithme en langage c.

[1]
RESULTAT DE PROGRAMME :

ALGORITHM PIERRE-PAPIER-CISEAUX :

Algorithme PierrePapierCiseaux

Début

InitialiserAleatoire()

Variable reponse : Caractère

Variable choix_ordi, choix_joueur : Entier

Variable num_ordi : Chaîne

Répéter

// Nouveaux choix aléatoire à chaque partie

choix_ordi ← NombreAléatoire(1, 3)

// Conversion choix ordinateur en texte

Si (choix_ordi = 1) Alors

num_ordi ← "Pierre"

Sinon Si (choix_ordi = 2) Alors

num_ordi ← "Papier"

Sinon

num_ordi ← "Ciseaux"

Fin Si

// Saisie joueur

Afficher ("Choisissez :") ;

Afficher ("1. Pierre") ;

Afficher ("2. Papier") ;

Afficher ("3. Ciseaux") ;

Afficher ("> ") ;

Lire (choix_joueur) ;

Afficher ("Ordinateur a choisi : ", num_ordi) ;

// Détermination gagnant

Si (choix_joueur = choix_ordi) Alors

Afficher ("Egalite !") ;

Sinon

[2]
RESULTAT DE PROGRAMME :
// Cas où le joueur gagne

Si (choix_joueur = 1 ET choix_ordi = 3) Alors

Afficher ("Vous gagnez ! ") ;

Sinon Si (choix_joueur = 3 ET choix_ordi = 2) Alors

Afficher ("Vous gagnez ! ") ;

Sinon Si (choix_joueur = 2 ET choix_ordi = 1) Alors

Afficher ("Vous gagnez ! ") ;

// Cas où l'ordinateur gagne

Sinon Si (choix_ordi = 1 ET choix_joueur = 3) Alors

Afficher ("L'ordinateur gagne ! ") ;

Sinon Si (choix_ordi = 3 ET choix_joueur = 2) Alors

Afficher ("L'ordinateur gagne ! ") ;

Sinon Si (choix_ordi = 2 ET choix_joueur = 1) Alors

Afficher ("L'ordinateur gagne ! ") ;

Fin Si

Fin Si

// Option rejouer

Afficher ("Rejouer ? : ") ;

Lire (reponse) ;

// Condition cohérente (quitter si réponse = 'O' ou 'o')

Jusqu'à (reponse = 'O' OU reponse = 'o')

Fin

[3]
RESULTAT DE PROGRAMME :

LANGUAGE C :

#include <stdio.h>

#include <stdlib.h>

#include <time.h>

int main() {

srand(time(NULL));

char reponse;

int choix_ordi, choix_joueur;

char* num_ordi;

do {

choix_ordi = rand() % 3 + 1;

if (choix_ordi == 1)

num_ordi = "Pierre";

else if (choix_ordi == 2)

num_ordi = "Papier";

else

num_ordi = "Ciseaux";

printf("Choisissez :\n");

printf("1. Pierre\n");

printf("2. Papier\n");

printf("3. Ciseaux\n");

printf("> ");

scanf("%d", &choix_joueur);

printf("Ordinateur a choisi : %s\n", num_ordi);

if (choix_joueur == choix_ordi) {

printf("Egalite !\n");

} else {

if (choix_joueur == 1 && choix_ordi == 3) {

[4]
RESULTAT DE PROGRAMME :
printf("Vous gagnez ! \n");

else if (choix_joueur == 3 && choix_ordi == 2) {

printf("Vous gagnez ! \n");

else if (choix_joueur == 2 && choix_ordi == 1) {

printf("Vous gagnez ! \n");

else if (choix_ordi == 1 && choix_joueur == 3) {

printf("L'ordinateur gagne ! \n");

else if (choix_ordi == 3 && choix_joueur == 2) {

printf("L'ordinateur gagne ! \n");

else if (choix_ordi == 2 && choix_joueur == 1) {

printf("L'ordinateur gagne ! \n");

printf("Rejouer ? : ");

scanf(" %c", &reponse);

} while (reponse == 'O' || reponse == 'o');

return 0;

[5]
RESULTAT DE PROGRAMME :

[6]

Vous aimerez peut-être aussi