Во-первых, я все еще новичок в программировании, поэтому, пожалуйста, не ругайте меня за то, что я что-то делаю неправильно. Все в коде — это то, чему я научился на уроках.
Итак, я создал игру «Крестики-нолики», и, как сказано в названии, ход второго игрока пропускается, если весь строка заполняется на доске.
Основная часть кода:
print("This is Tic-Tac-Toe, play this with a friend")
TicTacToe = [["-", "-", "-"],
["-", "-", "-"],
["-", "-", "-"]]
for row in TicTacToe:
print(row[0],row[1],row[2])
while True:
Player = input("Which row do you want to go; T = top, M = middle, or B = bottom?\n")
if Player not in ["top", "Top", "T", "t", "middle", "Middle", "M", "m", "bottom", "Bottom", "B", "b"]:
print("Wrong input, I'm afraid you are going to have to actually write what you were told to.")
continue
# These are the moves of the player, starting with Player One.
if Player == "top" or Player == "Top" or Player == "T" or Player == "t":
while True:
Movement = input("Where do you want to go, L = left, M = middle or R = right?\n")
# Checks if the movement after the player chose their option is in check
if Movement not in ["left", "Left", "L", "l", "Middle", "middle", "M", "m", "right", "Right", "R", "r"]:
print("That is not one of the options you are allowed to write, please write the options listed.")
continue
if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l":
if TicTacToe[0][0] == "-":
TicTacToe[0][0] = "X"
break
else:
print("A move has already been placed there!")
# Now it is the beginning of Player Two's turn
while True:
Player2 = input("Now it's your turn Player Two; T = top, M = middle, or B = bottom?\n")
# This is what happens if Player Two does not input the options originally listed
if Player2 not in ["top", "Top", "T", "t", "middle", "Middle", "M", "m", "bottom", "Bottom", "B", "b"]:
print("Wrong input, I'm afraid you are going to have to actually write what you were told to.")
continue
# Moves of Player Two
if Player2 == "top" or Player2 == "Top" or Player2 == "T" or Player2 == "t":
while True:
Movement = input("Where do you want to go, L = left, M = middle or R = right?\n")
# Checks if the movement after the player chose their option is in check
if Movement not in ["left", "Left", "L", "l", "Middle", "middle", "M", "m", "right", "Right", "R", "r"]:
print("That is not one of the options you are allowed to write, please write the options listed.")
continue
if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l":
if TicTacToe[0][0] == "-":
TicTacToe[0][0] = "O"
break
else:
print("A move has already been placed there!")
break
Итак, в этом блоке кода для второго игрока, а также других подобных ему, я вместо этого попытался заменить разрыв под тегом else на оператор continue, думая, что он будет зацикливаться на исходный вопрос: «Теперь твоя очередь, второй игрок; T = верхний, M = средний или B = нижний?».
Блок кода:
if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l":
if TicTacToe[0][0] == "-":
TicTacToe[0][0] = "O"
break
else:
print("A move has already been placed there!")
break
if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l":
if TicTacToe[0][0] == "-":
TicTacToe[0][0] = "O"
break
else:
print("A move has already been placed there!")
continue
Вместо этого он возвращается к переменной «Движение», которая мягко блокирует второго игрока, поскольку строка полностью заполнена.
Если кто-нибудь знает, как это сделать чтобы это исправить, пожалуйста, объясните, почему мой метод не работает, а также как работает новый метод.
Во-первых, я все еще новичок в программировании, поэтому, пожалуйста, не ругайте меня за то, что я что-то делаю неправильно. Все в коде — это то, чему я научился на уроках. Итак, я создал игру «Крестики-нолики», и, как сказано в названии, ход второго игрока пропускается, если весь строка заполняется на доске. Основная часть кода: [code]print("This is Tic-Tac-Toe, play this with a friend") TicTacToe = [["-", "-", "-"], ["-", "-", "-"], ["-", "-", "-"]]
for row in TicTacToe: print(row[0],row[1],row[2])
while True: Player = input("Which row do you want to go; T = top, M = middle, or B = bottom?\n")
if Player not in ["top", "Top", "T", "t", "middle", "Middle", "M", "m", "bottom", "Bottom", "B", "b"]: print("Wrong input, I'm afraid you are going to have to actually write what you were told to.") continue
# These are the moves of the player, starting with Player One.
if Player == "top" or Player == "Top" or Player == "T" or Player == "t": while True: Movement = input("Where do you want to go, L = left, M = middle or R = right?\n") # Checks if the movement after the player chose their option is in check if Movement not in ["left", "Left", "L", "l", "Middle", "middle", "M", "m", "right", "Right", "R", "r"]: print("That is not one of the options you are allowed to write, please write the options listed.") continue
if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l": if TicTacToe[0][0] == "-": TicTacToe[0][0] = "X" break else: print("A move has already been placed there!")
# Now it is the beginning of Player Two's turn
while True: Player2 = input("Now it's your turn Player Two; T = top, M = middle, or B = bottom?\n")
# This is what happens if Player Two does not input the options originally listed
if Player2 not in ["top", "Top", "T", "t", "middle", "Middle", "M", "m", "bottom", "Bottom", "B", "b"]: print("Wrong input, I'm afraid you are going to have to actually write what you were told to.") continue
# Moves of Player Two
if Player2 == "top" or Player2 == "Top" or Player2 == "T" or Player2 == "t": while True: Movement = input("Where do you want to go, L = left, M = middle or R = right?\n") # Checks if the movement after the player chose their option is in check if Movement not in ["left", "Left", "L", "l", "Middle", "middle", "M", "m", "right", "Right", "R", "r"]: print("That is not one of the options you are allowed to write, please write the options listed.") continue
if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l": if TicTacToe[0][0] == "-": TicTacToe[0][0] = "O" break else: print("A move has already been placed there!") break [/code] Итак, в этом блоке кода для второго игрока, а также других подобных ему, я вместо этого попытался заменить разрыв под тегом else на оператор continue, думая, что он будет зацикливаться на исходный вопрос: «Теперь твоя очередь, второй игрок; T = верхний, M = средний или B = нижний?». Блок кода: [code] if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l": if TicTacToe[0][0] == "-": TicTacToe[0][0] = "O" break else: print("A move has already been placed there!") break [/code] Измененный блок кода: [code] if Movement == "left" or Movement == "Left" or Movement == "L" or Movement == "l": if TicTacToe[0][0] == "-": TicTacToe[0][0] = "O" break else: print("A move has already been placed there!") continue [/code] Вместо этого он возвращается к переменной «Движение», которая мягко блокирует второго игрока, поскольку строка полностью заполнена. Если кто-нибудь знает, как это сделать чтобы это исправить, пожалуйста, объясните, почему мой метод не работает, а также как работает новый метод.
Как я только что сказал, я пишу игру «Крестики-нолики», и произошла ошибка, которую я до сих пор не могу исправить. Сама ошибка включает в себя проверку того, выиграл ли игрок. Он не показывает явного сообщения об ошибке, но работает не так, как я...
У меня есть готовая игровая доска «крестики-нолики». Это 3 x 3. На самом деле я не прошу кода (хотя это помогло бы), но какие алгоритмы лучше всего подходят для определения того, кто победил? Другими словами, какие алгоритмы мне следует изучить,...
У меня есть готовая игровая доска «крестики-нолики». Это 3 x 3. На самом деле я не прошу кода (хотя это помогло бы), но какие алгоритмы лучше всего подходят для определения того, кто победил? Другими словами, какие алгоритмы мне следует изучить,...
В настоящее время я разрабатываю приложение на основе Swift для игры в крестики-нолики, и столкнулся с проблемой правильного расчета выигрышей при игре против компьютера.
В своем приложении я реализовал логику, позволяющую отслеживать количество...
Я работаю над игрой в крестики-нолики и столкнулся с проблемой, из-за которой знак «X» не отображается при первом щелчке на любом поле. После первого клика все работает корректно.