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

Function take_turn

BoardGame-CLI/python.py:35–56  ·  view source on GitHub ↗
(current_position, player_name)

Source from the content-addressed store, hash-verified

33
34# Function to simulate a single turn
35def 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

Callers 1

play_snakes_and_laddersFunction · 0.85

Calls 1

roll_dieFunction · 0.85

Tested by

no test coverage detected