Algorithmus Schere Stein Papier?

2 Antworten

Hallo!

Du solltest uns auch mitteilen, in welcher Programmiersprache Du arbeitest.

Und dann kann man auch per Google problemlos fündig werden.

Z.B. mit der Sprache "Python":

https://www.google.com/search?q=python%20schere%20stein%20papier

https://infolab.cs.uni-saarland.de/portfolio-2/schere-stein-papier-mit-python/

https://www.youtube.com/results?search_query=python+schere+stein+papier

Wenn Du eine andere Sprache verwendest, musst Du die Suchbegriffe nur entsprechend abändern.

Gruß

Martin

Ein Paar mehr Infos wären nett, aber hier mal eine Version in Python:

import random

kvs={ 'r' :0, 'p':1 , 's':2}
while 1:
    player=input("Eneter choice (r)ock, (s)cissors, (p)aper, (q)uit: ")
    if player=='q':
        break
    if player not in kvs:
        print("Invalid input supplied")
        continue
    computer=random.choice([k for k in kvs.keys()])
    print(f"Your choice {player}, computer's choice: {computer}")
    if kvs[player]==(kvs[computer]+1)%3:
        print("You win!")
    elif player==computer:
        print("Draw!")
    else:
        print("Computer wins!")