У меня проблемы с исправлением вывода для этого кода:
print('--------')
print('|'+board[7]+ '|' +board[8] +'|' +board[9]+'|')
print('--------')
print('|' +board[4]+ '|'+board[5]+'|' +board[6]+'|')
print('--------')
print('|' +board[1]+ '|'+board[2]+'|' +board[3]+'|')
print('--------')
real_board=['#','#','#','#','#','#','#','#','#','#']
def xchecker_tool(board, mark):
vertical=print(f'congratulations player {mark}! you have won by lining up vertically on the board!')
horizontal=print(f'congratulations player {mark}! you have won by lining up horizontally on the board!')
diagonal= print(f'congratulations player {mark}! you have won by lining up diagonally!')
if board[1]==mark and board[2]==mark and board[3]==mark:
horizontal
elif board[4]==mark and board[5]==mark and board[6]==mark:
horizontal
elif board[7]==mark and board[8]==mark and board[9]==mark:
horizontal
if board[1]==mark and board[4]==mark and board[7]==mark:
vertical
elif board[2]==mark and board[5]==mark and board[8]==mark:
vertical
elif board[3]==mark and board[6]==mark and board[9]==mark:
vertical
if board[1]==mark and board[5]==mark and board[9]==mark:
diagonal
elif board[3]==mark and board[5]==mark and board[7]==mark:
diagonal
def game_rounds(round):
player_moves=int(input('choose a number from 1 to 9: '))
while True:
if (player_moves)<1 or (player_moves)>9:
print('unacceptable range')
elif (player_moves)==1:
real_board[1]='X'
elif (player_moves)==2:
real_board[2]='X'
elif (player_moves)==3:
real_board[3]='X'
elif (player_moves)==4:
real_board[4]='X'
elif (player_moves)==5:
real_board[5]='X'
elif (player_moves)==6:
real_board[6]='X'
elif (player_moves)==7:
real_board[7]='X'
elif (player_moves)==8:
real_board[8]='X'
else:
real_board[9]='X'
break
display_board(real_board)
def y_rounds(round):
y_moves=int(input('choose a number from 1 to 9: '))
while True:
if (y_moves)<1 or (y_moves)>9:
print('unacceptable range')
elif (y_moves)==1:
real_board[1]='O'
elif (y_moves)==2:
real_board[2]='O'
elif (y_moves)==3:
real_board[3]='O'
elif (y_moves)==4:
real_board[4]='O'
elif (y_moves)==5:
real_board[5]='O'
elif (y_moves)==6:
real_board[6]='O'
elif (y_moves)==7:
real_board[7]='O'
elif (y_moves)==8:
real_board[8]='O'
else:
real_board[9]='O'
break
display_board(real_board)
def run_game(full):
game_on=True
game_off=False
t=0
while game_on:
game_rounds(1)
t+=1
if t==5:
break
y_rounds(1)
xchecker_tool(real_board, 'X')
xchecker_tool(real_board, 'O')
run_game(1)
Я получаю этот вывод. Насколько я понимаю, функция xchecker_tool не определена правильно, поэтому она печатает сообщение «поздравляю» каждые два оборота, даже если «x» или «o» не выстроены в очередь. Мне также нужна помощь в очистке скрипта, так как он очень скучный, но я не могу сделать это на моем текущем уровне из-за повторяющихся ошибок.
choose a number from 1 to 9: 3
--------
|#|#|#|
--------
|#|#|#|
--------
|#|#|X|
--------
choose a number from 1 to 9: 5
--------
|#|#|#|
--------
|#|O|#|
--------
|#|#|X|
--------
congratulations player X! you have won by lining up vertically on the board!
congratulations player X! you have won by lining up horizontally on the board!
congratulations player X! you have won by lining up diagonally!
congratulations player O! you have won by lining up vertically on the board!
congratulations player O! you have won by lining up horizontally on the board!
congratulations player O! you have won by lining up diagonally!