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

Function main

Tic-Tac-Toe Games/tic-tac-toe5.py:174–216  ·  view source on GitHub ↗

Main game loop.

()

Source from the content-addressed store, hash-verified

172
173
174def main() -> None:
175 """Main game loop."""
176 introduction()
177 while True:
178 the_board: List[str] = [" "] * 10
179 player_letter, computer_letter = input_player_letter()
180 turn = first_player()
181 print(f"{turn} goes first.")
182 game_is_playing = True
183
184 while game_is_playing:
185 if turn.lower() == "player":
186 draw_board(the_board)
187 move = get_player_move(the_board)
188 make_move(the_board, player_letter, move)
189
190 if is_winner(the_board, player_letter):
191 draw_board(the_board)
192 print("Hooray! You have won the game!")
193 game_is_playing = False
194 elif is_board_full(the_board):
195 draw_board(the_board)
196 print("The game is a tie!")
197 break
198 else:
199 turn = "computer"
200 else:
201 move = get_computer_move(the_board, computer_letter)
202 make_move(the_board, computer_letter, move)
203
204 if is_winner(the_board, computer_letter):
205 draw_board(the_board)
206 print("Computer has won. You Lose.")
207 game_is_playing = False
208 elif is_board_full(the_board):
209 draw_board(the_board)
210 print("The game is a tie!")
211 break
212 else:
213 turn = "player"
214
215 if not play_again():
216 break
217
218
219if __name__ == "__main__":

Callers 1

tic-tac-toe5.pyFile · 0.70

Calls 10

introductionFunction · 0.85
input_player_letterFunction · 0.85
first_playerFunction · 0.85
get_player_moveFunction · 0.85
is_winnerFunction · 0.85
get_computer_moveFunction · 0.85
play_againFunction · 0.85
draw_boardFunction · 0.70
make_moveFunction · 0.70
is_board_fullFunction · 0.70

Tested by

no test coverage detected