Таким образом, я сделал игру ti c ta c toe и сделал функцию marker_change()
, чтобы менять игрока после каждого хода, но когда я запускаю игру, маркер не меняется, он остается прежним после каждого хода. Вот мой код, извините, если мой код беспорядок, ребята, но я буквально много чего пытался решить:
board = [" "]*10
marker = None
def display_board(board):
print("""
▀█▀ █ █▀▀ ▀█▀ ▄▀█ █▀▀ ▀█▀ █▀█ █▀▀
░█░ █ █▄▄ ░█░ █▀█ █▄▄ ░█░ █▄█ ██▄
█▀▀ ▄▀█ █▀▄▀█ █▀▀
█▄█ █▀█ █░▀░█ ██▄""")
print("\n"*1)
print(board[7]+"|"+board[8]+"|"+board[9])
print("-----")
print(board[4]+"|"+board[5]+"|"+board[6])
print("-----")
print(board[1]+"|"+board[2]+"|"+board[3])
def place_marker(board):
global marker
marker = " "
while marker != "x" and marker != "o":
marker = input("Player 1, choose x or o: ")
player1 = marker
if player1 == "x":
player2 = "o"
print("""
|------------------------------------|
| Player 1 is now X and player 2 is O|
|------------------------------------|
""")
else:
player2 = "x"
print("""
|------------------------------------|
| Player 1 is now O and player 2 is X|
|------------------------------------|
""")
#Input of the player
count = 0
for a in range(10):
count += 1
display_board(board)
position = int(input("Choose a number between 1-9: "))
board[position] = marker
if board[1] == board[2] == board[3] != ' ':
win_check = str(board[1] + " HAS WON !!!")
print(win_check)
break
elif board[1] == board[5] == board[9] != ' ':
variabila1 = str(board[1] + " HAS WON !!!")
print(variabila1)
break
elif board[7] == board[8] == board[9] != ' ':
variabila2 = str(board[7] + " HAS WON !!!")
print(variabila2)
break
elif board[7] == board[5] == board[3] != ' ':
variabila3 = str(board[7] + " HAS WON !!!")
print(variabila3)
break
elif board[1] == board[4] == board[7] != ' ':
variabila4 = str(board[1] + " HAS WON !!!")
print(variabila4)
break
elif board[3] == board[6] == board[9] != ' ':
variabila5 = str(board[3] + " HAS WON !!!")
print(variabila5)
break
elif count == 9:
print("THIS IS A TIE")
return(a)
return (player1,player2)
place_marker(board)
def marker_change():
global marker
if marker == "x":
marker = "o"
print("Now it's o's turn")
else:
print("Now it's x's turn")
marker_change()
#restart function
def clear_board(board):
restart = input("Would you like to play again?:\nyes/no: ")
if restart == "yes":
board = [" "]*10
place_marker(board)
clear_board(board)
else:
restart == "no"
print("\n"*100)
print("""
▀▀█▀▀ █──█ █▀▀█ █▀▀▄ █─█ █▀▀ ░█▀▀▀ █▀▀█ █▀▀█ ░█▀▀█ █── █▀▀█ █──█ ─▀─ █▀▀▄ █▀▀▀
─░█── █▀▀█ █▄▄█ █──█ █▀▄ ▀▀█ ░█▀▀▀ █──█ █▄▄▀ ░█▄▄█ █── █▄▄█ █▄▄█ ▀█▀ █──█ █─▀█
─░█── ▀──▀ ▀──▀ ▀──▀ ▀─▀ ▀▀▀ ░█─── ▀▀▀▀ ▀─▀▀ ░█─── ▀▀▀ ▀──▀ ▄▄▄█ ▀▀▀ ▀──▀ ▀▀▀▀""")
if __name__ == "__main__":
clear_board(board)