Tic Tac Toe Game
Tic Tac Toe Game
def display_board(board):
print("-----------")
print("|".join(row))
print("-----------")
for i in range(3):
return True
return True
return True
return False
def is_draw(board):
return all([cell != " " for row in board for cell in row])
# Main game loop
def play_game():
board = [[" " for _ in range(3)] for _ in range(3)] # 3x3 Tic Tac Toe board
while True:
display_board(board)
print(f"Player {current_player}, make your move (row and column from 1 to 3):")
try:
row, col = map(int, input("Enter row and column (e.g., '1 3'): ").split())
if row < 1 or row > 3 or col < 1 or col > 3 or board[row - 1][col - 1] != " ":
continue
except ValueError:
continue
if check_winner(board, current_player):
display_board(board)
break
elif is_draw(board):
display_board(board)
print("It's a draw!")
break
# Switch player
play_game()