(current_position, player_name)
| 33 | |
| 34 | # Function to simulate a single turn |
| 35 | def take_turn(current_position, player_name): |
| 36 | # Roll the die |
| 37 | roll_result = roll_die() |
| 38 | print(f"{player_name} rolled a {roll_result}!") |
| 39 | |
| 40 | # Calculate the new position after the roll |
| 41 | new_position = current_position + roll_result |
| 42 | |
| 43 | # Check if the new position is a ladder or a snake |
| 44 | if new_position in snakes_and_ladders: |
| 45 | new_position = snakes_and_ladders[new_position] |
| 46 | if new_position > current_position: |
| 47 | print("Ladder! Climb up!") |
| 48 | else: |
| 49 | print("Snake! Slide down!") |
| 50 | |
| 51 | # Check if the new position exceeds the board size |
| 52 | if new_position >= 100: |
| 53 | new_position = 100 |
| 54 | print(f"Congratulations, {player_name} reached the final square!") |
| 55 | |
| 56 | return new_position |
| 57 | |
| 58 | |
| 59 | # Main game loop |
no test coverage detected