- # Define the game state
- current_player = 1
- game_over = False
- # Define the game loop
- while not game_over:
- # Display the game board
- for row in board:
- print("|".join(str(cell) for cell in row))
- print("-" * (size * 2 + 1))
- # Get the user input
- row = int(input("Player {}: Enter the row (0-2): ".format(current_player)))
- col = int(input("Player {}: Enter the column (0-2): ".format(current_player)))
- # Check if the cell is empty
- if board[row][col] == 0:
- # Place the piece
- board[row][col] = current_player
- # Check for winning condition
- if check_win(current_player, board):
- print("Player {} wins!".format(current_player))
- game_over = True
- # Switch to the next player
- current_player = 2 if current_player == 1 else 1
- # Check for a tie
- if not any(0 in row for row in board):
- print("It's a tie!")
- game_over = True
- else:
- print("Cell already occupied. Try again.")
[text] 1
Viewer
Editor
You can edit this paste and save as new: