У меня задача максимально оптимизировать код и исправить проблему с ничьей. Если что код под крестики нолики. Если сможете помочь то прошу вас.
вот код:
import random
mss1 =
mss2 =
mss3 =
step_count = 0
def printP():
print(“ 1 2 3”)
print(“A”, mss1)
print(“ ”)
print(“B”, mss2)
print(“ ”)
print(“C”, mss3)
def win():
if mss1 == “X” and mss1 == “X” and mss1 == “X”:
print(“Win User”)
return True
elif mss2 == “X” and mss2 == “X” and mss2 == “X”:
print(“Win User”)
return True
elif mss3 == “X” and mss3 == “X” and mss3 == “X”:
print(“Win User”)
return True
elif mss1 == “X” and mss2 == “X” and mss3 == “X”:
print(“Win User”)
return True
elif mss1 == “X” and mss2 == “X” and mss3 == “X”:
print(“Win User”)
return True
elif mss1 == “X” and mss2 == “X” and mss3 == “X”:
print(“Win User”)
return True
elif mss1 == “X” and mss2 == “X” and mss3 == “X”:
print(“Win User”)
return True
elif mss3 == “X” and mss2 == “X” and mss1 == “X”:
print(“Win User”)
return True
elif mss1 == “0” and mss1 == “0” and mss1 == “0”:
print(“Win Comp”)
return True
elif mss2 == “0” and mss2 == “0” and mss2 == “0”:
print(“Win Comp”)
return True
elif mss3 == “0” and mss3 == “0” and mss3 == “0”:
print(“Win Comp”)
return True
elif mss1 == “0” and mss2 == “0” and mss3 == “0”:
print(“Win Comp”)
return True
elif mss1 == “0” and mss2 == “0” and mss3 == “0”:
print(“Win Comp”)
return True
elif mss1 == “0” and mss2 == “0” and mss3 == “0”:
print(“Win Comp”)
return True
elif mss1 == “0” and mss2 == “0” and mss3 == “0”:
print(“Win Comp”)
return True
elif mss3 == “0” and mss2 == “0” and mss1 == “0”:
print(“Win Comp”)
return True
def Bot():
step_count = 0
r = random.randint(1, 3)
if r == 1:
r = random.randint(0, 2)
if mss1 == “_”:
mss1 = “0”
step_count += 1
else:
Bot()
elif r == 2:
r = random.randint(0, 2)
if mss2 == “_”:
mss2 = “0”
step_count += 1
else:
Bot()
elif r == 3:
r = random.randint(0, 2)
if mss3 == “_”:
mss3 = “0”
step_count += 1
else:
Bot()
while True:
printP()
#if win():
# break
#else:
user = input(“-> ”)
if user == “A1” or user == “a1”:
if mss1 == “_”:
mss1 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “A2” or user == “a2”:
if mss1 == “_”:
mss1 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “A3” or user == “a3”:
if mss1 == “_”:
mss1 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “B1” or user == “b1”:
if mss2 == “_”:
mss2 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “B2” or user == “b2”:
if mss2 == “_”:
mss2 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “B3” or user == “b3”:
if mss2 == “_”:
mss2 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “C1” or user == “c1”:
if mss3 == “_”:
mss3 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “C2” or user == “c2”:
if mss3 == “_”:
mss3 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)
elif user == “C3” or user == “c3”:
if mss3 == “_”:
mss3 = “X”
step_count += 1
if step_count == 9:
print(“Ничья”)
break
else:
Bot()
else:
print(“No ”)