Run the Tic-Tac-Toe game in the console.
()
| 84 | |
| 85 | |
| 86 | def main() -> None: |
| 87 | """Run the Tic-Tac-Toe game in the console.""" |
| 88 | global player |
| 89 | print("Tic-Tac-Toe Game Designed By Sourabh Somani") |
| 90 | print("Player 1 [X] --- Player 2 [O]\n\nPlease Wait...") |
| 91 | time.sleep(2) |
| 92 | |
| 93 | while Game == Running: |
| 94 | os.system("cls" if os.name == "nt" else "clear") |
| 95 | draw_board() |
| 96 | mark = "X" if player % 2 != 0 else "O" |
| 97 | print(f"Player {1 if mark == 'X' else 2}'s chance") |
| 98 | try: |
| 99 | choice = int(input("Enter position [1-9] to mark: ")) |
| 100 | except ValueError: |
| 101 | print("Invalid input! Enter an integer between 1-9.") |
| 102 | time.sleep(2) |
| 103 | continue |
| 104 | |
| 105 | if choice < 1 or choice > 9: |
| 106 | print("Invalid position! Choose between 1-9.") |
| 107 | time.sleep(2) |
| 108 | continue |
| 109 | |
| 110 | if check_position(board, choice): |
| 111 | board[choice] = mark |
| 112 | player += 1 |
| 113 | check_win() |
| 114 | else: |
| 115 | print("Position already taken! Try another.") |
| 116 | time.sleep(2) |
| 117 | |
| 118 | os.system("cls" if os.name == "nt" else "clear") |
| 119 | draw_board() |
| 120 | if Game == Draw: |
| 121 | print("Game Draw") |
| 122 | elif Game == Win: |
| 123 | player_won = 1 if (player - 1) % 2 != 0 else 2 |
| 124 | print(f"Player {player_won} Won!") |
| 125 | |
| 126 | |
| 127 | if __name__ == "__main__": |
no test coverage detected