-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfootsteps.py
More file actions
159 lines (124 loc) · 4.5 KB
/
footsteps.py
File metadata and controls
159 lines (124 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
"""
FOOTSTEPS GAME
--------------
A two-player bidding game inspired by classic programming puzzles.
Players secretly bid points each round to move a shared token
toward their side of the board. The player closest to the token
at the end of the game wins.
"""
# =========================
# CONSTANTS
# =========================
BOARD_SIZE = 9 # Total number of board spaces
START_POSITION = BOARD_SIZE // 2
STARTING_POINTS = 50
print("hello")
# =========================
# DISPLAY FUNCTIONS
# =========================
def clear_screen():
"""Prints blank lines to visually clear the console."""
print("\n" * 50)
#code
def show_start_screen():
"""Displays the home/start screen with rules and credits."""
clear_screen()
print("===================================")
print(" FOOTSTEPS")
print("===================================\n")
print("GAME DESCRIPTION:")
print("Two players sit at opposite ends of a row.")
print("A token starts in the center of the board.\n")
print("HOW TO PLAY:")
print("- Each player starts with 50 points")
print("- Every round, both players secretly bid points")
print("- The higher bid moves the token one space toward that player")
print("- BOTH players lose the points they bid")
print("- If bids are equal, the token does not move")
print("- If a player runs out of points, the other may continue bidding")
print("- The game ends when both players have no points")
print(" or when the token reaches the end of the board\n")
print("WINNING:")
print("- The player closest to the token at the end wins")
print("- Equal distance results in a draw\n")
print("CREDITS:")
print("Inspired by classic programming and game theory puzzles\n")
input("Press ENTER to start the game...")
def display_board(token_position):
"""Displays the board and the token location."""
board = ["." for _ in range(BOARD_SIZE)]
board[token_position] = "X"
print("\nA | " + " ".join(board) + " | B\n")
# =========================
# INPUT FUNCTIONS
# =========================
def get_bid(player_name, remaining_points):
"""
Prompts a player to enter a valid bid.
Parameters:
player_name (str): Name of the player
remaining_points (int): Points the player has left
Returns:
int: Valid bid amount
"""
if remaining_points == 0:
print(f"{player_name} has no points left and bids 0.")
return 0
while True:
try:
bid = int(input(f"{player_name}, enter your bid (0–{remaining_points}): "))
if 0 <= bid <= remaining_points:
return bid
else:
print("Invalid bid. Try again.")
except ValueError:
print("Please enter a valid number.")
# =========================
# GAME LOGIC
# =========================
def play_game():
"""Main game loop."""
token_position = START_POSITION
points_a = STARTING_POINTS
points_b = STARTING_POINTS
while True:
clear_screen()
display_board(token_position)
print(f"Points — Player A: {points_a} | Player B: {points_b}\n")
# End condition: both players out of points
if points_a == 0 and points_b == 0:
break
bid_a = get_bid("Player A", points_a)
bid_b = get_bid("Player B", points_b)
points_a -= bid_a
points_b -= bid_b
# Determine movement
if bid_a > bid_b:
token_position -= 1
elif bid_b > bid_a:
token_position += 1
# End condition: token reaches either end
if token_position == 0 or token_position == BOARD_SIZE - 1:
break
show_end_screen(token_position, points_a, points_b)
def show_end_screen(token_position, points_a, points_b):
"""Displays the final results screen."""
clear_screen()
print("===================================")
print(" GAME OVER")
print("===================================\n")
display_board(token_position)
print(f"Final Points — Player A: {points_a} | Player B: {points_b}\n")
if token_position < START_POSITION:
print("🏆 Player A wins!")
elif token_position > START_POSITION:
print("🏆 Player B wins!")
else:
print("🤝 The game is a draw (half victory).")
print("\nThank you for playing Footsteps!")
# =========================
# PROGRAM ENTRY POINT
# =========================
if __name__ == "__main__":
show_start_screen()
play_game()