Python Basit Çubuk Oyunu Yazma

Merhaba,
ortada 7 çubuk var. iki oyunculu bir oyun. her oyuncu 1 veya 2 çubuk alabilir. 1 veya 2 den farklı çubuk alınması geçersiz işlem.
en son 1 çubuk kimin sırasında kalıyorsa o oyuncu kaybediyor. Proje ödevimdir, Python kodu konusunda yardımcı olabilecek var mı ?

ekleme: ben aşağıdaki gibi yazdım ama oyun başa dönmüyor. bir de oyuncu1 oyuncu 2 sırasını ekleyemedim.

def oyun(hamle):

while True:
    sticks = 7


    if hamle<sticks and hamle==1 :
        sticks=sticks-1
        print("Kalan Sticks",sticks)
        break
    elif hamle<sticks and hamle==2 :
        sticks=sticks-2
        print("Kalan Sticks",sticks)
        break
    else:
        print("Geçersiz hamle girdiniz")
        break

hamle = int(input(“1 veya 2 çubuk alınız”))
oyun(hamle)

Son durumum :slight_smile:

player=1
sticks=7
print(“Çubuk sayısı”,sticks)

while True:
sticks = 7
print(“Player”,player)
hamle = int(input(“1 veya 2 çubuk alınız”))
sticks=sticks-hamle
print(“Kalan Çubuk Sayısı”,sticks)
if sticks==1:
print(“Ups, lost”)
break
if player==1:
player=2
else:
player=1
print(“Game over”)

sıkıntı her seferinde sticks=7 den başlıyor- kalan sayı üzerinden devam edemiyorum :frowning:

çünkü sürekli sticks = 7 değerini döndürüyorsun

from random import choice

# config
user1 = "test"
user2 = "computer"
sticks = 10
moves = [1, 2] # computer's moves

def game(sticks):
    i = 1
    print(f"Sticks: {sticks}")
    while True:
        print(f"-- {i}. Round --")
        i += 1
        user1_move = int(input(f"{user1}: "))
        if user1_move < 3:
            user1_score = sticks - user1_move
            if user1_score < 2:
                print(f"{user1} Lost!")
                break
            if user1_move == 1:
                sticks -= 1
                print(f"Left sticks: {sticks}")
            elif user1_move == 2:
                sticks -= 2
                print(f"Left sticks: {sticks}")
        else:
            print("Invalid move!")
            continue


        user2_move = choice(moves)
        if user2_move < 3:
            print(f"{user2}: {user2_move}")
            
            # user2_move = int(input(f"{user2}: "))
            user2_score = sticks - user2_move
            if user2_score < 2:
                print(f"{user2} Lost!")
                break
            if user2_move == 1:
                sticks -= 1
                print(f"Left sticks: {sticks}")
            elif user2_move == 2:
                sticks -= 2
                print(f"Left sticks: {sticks}")
        else:
            print("Invalid move!")
            continue
        print()

game(sticks)
2 Beğeni