import random def main(): player1_is_automated = False #CHANGE THIS TO True WHEN YOU WISH TO TEST STAGE 13 player2_is_automated = True number_of_games = 1 #CHANGE THIS NUMBER TO 500 AFTER YOU HAVE COMPLETED AND TESTED STAGE 13 #Only print details of the games if the number of games is less than 6 printing_is_on = True if number_of_games > 5: printing_is_on = False player1_name = "Adriana" player2_name = "AlwaysSaysNo" player1_wins = 0 player2_wins = 0 target_score = 50 if printing_is_on: welcome_to_game(player1_name, player2_name, target_score) for i in range(number_of_games): winner_name = play_a_game(player1_name, player2_name, target_score, player1_is_automated, player2_is_automated, printing_is_on) if winner_name == player1_name: player1_wins += 1 else: player2_wins += 1 if number_of_games > 1: print("After", number_of_games, "games:") print(" ", player1_name, "has won", player1_wins, "games") print(" ", player2_name, "has won", player2_wins, "games") print() print() #------------------------------------ # 1. welcome_to_game() #------------------------------------ def welcome_to_game(player1_name, player2_name, target_score): pass #------------------------------------ # 2. get_starting_player_number() #------------------------------------ def get_starting_player_number(): return 0 #------------------------------------ # 3. display_turn_info() #------------------------------------ def display_turn_info(player_name, total_score): pass #------------------------------------ # 4. get_dice_roll() #------------------------------------ def get_dice_roll(): return 0 #------------------------------------ # 5. display_dice() #------------------------------------ def display_dice(dice1, dice2): pass #------------------------------------ # 6. check_for_double_six() #------------------------------------ def check_for_double_six(dice1, dice2): return False #------------------------------------ # 7. check_for_a_single_six() #------------------------------------ def check_for_a_single_six(dice1, dice2): return False #------------------------------------ # 8. get_user_choice() #------------------------------------ def get_user_choice(prompt): return "n" #------------------------------------ # 9. game_has_finished() #------------------------------------ def game_has_finished(player1_score, player2_score, target_score): return True #------------------------------------ # 10. get_other_player_number() #------------------------------------ def get_other_player_number(player_num): return 0 #------------------------------------ # 11. get_winner_name() #------------------------------------ def get_winner_name(player1_name, player2_name, player1_score, player2_score, target_score): return "" #------------------------------------ # 12. display_game_results() #------------------------------------ def display_game_results(winner_name, player1_name, player2_name, player1_score, player2_score): pass #------------------------------------ # 13. get_automated_yes_no() #------------------------------------ def get_automated_yes_no(so_far_this_turn, total_score, other_player_total_score, number_of_rolls_so_far, target_score): return "" #------------------------------------ # have_a_turn() #------------------------------------ def have_a_turn(player_name, player_score, target_score, other_player_score, is_automated, always_says_no, printing_is_on): if printing_is_on: display_turn_info(player_name, player_score) score_this_turn = 0 turn_has_finished = False number_of_rolls_this_turn = 0 while not turn_has_finished: dice1 = get_dice_roll() dice2 = get_dice_roll() if printing_is_on: display_dice(dice1, dice2) number_of_rolls_this_turn += 1 if check_for_double_six(dice1, dice2): score_this_turn = -player_score turn_has_finished = True if printing_is_on: print("\n You rolled a double six.") print(" Your total score goes back to zero.", "(Total score: 0)") elif check_for_a_single_six(dice1, dice2): score_this_turn = 0 turn_has_finished = True if printing_is_on: print("\n You rolled a six,") print(" Your score this turn is zero.", "(Total score: " + str(player_score) + ")") else: score_this_turn = score_this_turn + dice1 + dice2 if printing_is_on: print(" So far, your score this turn is", score_this_turn) if is_automated and always_says_no: user_choice = "n" elif is_automated: user_choice = get_automated_yes_no(score_this_turn, player_score, other_player_score, number_of_rolls_this_turn, target_score) else: user_choice = get_user_choice(" Do you wish to roll again (y or n)? ") if user_choice == "n": turn_has_finished = True if printing_is_on: print("\n Your score this turn is", score_this_turn, "(Total score: " + str(player_score + score_this_turn) + ")") player_score = player_score + score_this_turn return player_score #------------------------------------ # play_a_game() #------------------------------------ def play_a_game(player1_name, player2_name, target_score, player1_is_automated, player2_is_automated, printing_is_on): player1_score = 0 player2_score = 0 game_has_ended = False current_player_num = get_starting_player_number() while not game_has_ended: if current_player_num == 1: player1_score = have_a_turn(player1_name, player1_score, target_score, player2_score, player1_is_automated, False, printing_is_on) else: player2_score = have_a_turn(player2_name, player2_score, target_score, player1_score, player2_is_automated, True, printing_is_on) if game_has_finished(player1_score, player2_score, target_score): game_has_ended = True else: current_player_num = get_other_player_number(current_player_num) winner_name = get_winner_name(player1_name, player2_name, player1_score, player2_score, target_score) if printing_is_on: display_game_results(winner_name, player1_name, player2_name, player1_score, player2_score) return winner_name main()