MCPcopy Create free account
hub / github.com/geekcomputers/Python / main

Function main

Tic-Tac-Toe Games/tic-tac-toe2.py:86–124  ·  view source on GitHub ↗

Run the Tic-Tac-Toe game in the console.

()

Source from the content-addressed store, hash-verified

84
85
86def 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
127if __name__ == "__main__":

Callers 1

tic-tac-toe2.pyFile · 0.70

Calls 3

check_positionFunction · 0.85
draw_boardFunction · 0.70
check_winFunction · 0.70

Tested by

no test coverage detected