mirror of
https://github.com/coding-horror/basic-computer-games.git
synced 2025-12-30 06:31:46 -08:00
Python: Make code testable
Avoid executing code on module level as this prevents importing the module for testing. Especially infinite loops are evil.
This commit is contained in:
@@ -489,36 +489,36 @@ def execute_turn(turn):
|
||||
#
|
||||
######################################
|
||||
|
||||
######################
|
||||
#
|
||||
# main game flow
|
||||
#
|
||||
######################
|
||||
|
||||
# initialize the player and computer
|
||||
# boards
|
||||
initialize_game()
|
||||
def main():
|
||||
# initialize the player and computer
|
||||
# boards
|
||||
initialize_game()
|
||||
|
||||
# execute turns until someone wins or we run
|
||||
# out of squares to shoot
|
||||
# execute turns until someone wins or we run
|
||||
# out of squares to shoot
|
||||
|
||||
game_over = False
|
||||
while not game_over:
|
||||
game_over = False
|
||||
while not game_over:
|
||||
|
||||
# increment the turn
|
||||
current_turn = current_turn + 1
|
||||
# increment the turn
|
||||
current_turn = current_turn + 1
|
||||
|
||||
print("\n")
|
||||
print("TURN", current_turn)
|
||||
print("\n")
|
||||
print("TURN", current_turn)
|
||||
|
||||
# print("computer")
|
||||
# print_board(computer_board)
|
||||
# print("player")
|
||||
# print_board(player_board)
|
||||
# print("computer")
|
||||
# print_board(computer_board)
|
||||
# print("player")
|
||||
# print_board(player_board)
|
||||
|
||||
if execute_turn(first_turn) == 0:
|
||||
game_over = True
|
||||
continue
|
||||
if execute_turn(second_turn) == 0:
|
||||
game_over = True
|
||||
continue
|
||||
if execute_turn(first_turn) == 0:
|
||||
game_over = True
|
||||
continue
|
||||
if execute_turn(second_turn) == 0:
|
||||
game_over = True
|
||||
continue
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user