Я создал код для игры в пикапы, в которую можно играть в двух режимах:
- Одиночная игра (против компьютера)
- Многопользовательская игра (локальная игра)
У меня, похоже, проблема с программой в режиме одиночной игры.Компьютер выводит отрицательные числа там, где это логически невозможно, и я хотел бы предотвратить это. Вот код:
import random
sticks = 27
choice = input("Do you wanna play multiplayer or against the computer? Type M for multiplayer and S for against the computer: ")
if choice == "M":
while sticks > 0:
i = int(input("Between 1 and 3, how many sticks do you want to pick : "))
while i < 1 or i > 3:
print("It has to be between 1 and 3! You NOOB!")
i = int(input("Between 1 and 3, how many sticks do you want to pick : "))
sticks = sticks - i
print(sticks," stick(s) left...")
print("You lost! hahaha...")
elif choice == "S":
while sticks > 0:
i = int(input("Between 1 and 3, how many sticks do you want to pick : "))
while i < 1 or i > 3:
print("It has to be between 1 and 3! You NOOB!")
i = int(input("Between 1 and 3, how many sticks do you want to pick : "))
sticks = sticks - i
print(sticks," stick(s) left...")
if sticks == 0:
print("You lost! hahaha...")
break
else:
num = random.randint(1,3)
print("Computer's Turn...")
print("The computer picked ",num, " stick(s)...")
sticks = sticks - num
if sticks < 1:
print("You won... Damn you are good!")
print(sticks," stick(s) left...")
И это вывод:
Do you wanna play multiplayer or against the computer? Type M for multiplayer and S for against the computer: S
Between 1 and 3, how many sticks do you want to pick : 3
24 stick(s) left...
Computer's Turn...
The computer picked 2 stick(s)...
22 stick(s) left...
Between 1 and 3, how many sticks do you want to pick : 3
19 stick(s) left...
Computer's Turn...
The computer picked 1 stick(s)...
18 stick(s) left...
Between 1 and 3, how many sticks do you want to pick : 3
15 stick(s) left...
Computer's Turn...
The computer picked 1 stick(s)...
14 stick(s) left...
Between 1 and 3, how many sticks do you want to pick : 3
11 stick(s) left...
Computer's Turn...
The computer picked 2 stick(s)...
9 stick(s) left...
Between 1 and 3, how many sticks do you want to pick : 3
6 stick(s) left...
Computer's Turn...
The computer picked 2 stick(s)...
4 stick(s) left...
Between 1 and 3, how many sticks do you want to pick : 2
2 stick(s) left...
Computer's Turn...
The computer picked 3 stick(s)...
You won... Damn you are good!
-1 stick(s) left...
Как видите, игра отображаетотрицательное число, где оно должно либо просто закончиться и сказать, что вы выиграли, либо компьютер не сможет перейти в отрицательные числа.Может кто-нибудь сказать мне, что я делаю не так?