-
Notifications
You must be signed in to change notification settings - Fork 8
/
monopoly_driver.py
71 lines (53 loc) · 2.03 KB
/
monopoly_driver.py
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
"""
@author: Aleph Aseffa
Date created: 7/14/2019
"""
from classes import player_definitions as p_def
from game import information as info
from ai import ai
board = info.initialize_cards_and_board()
Aleph = p_def.Player("Aleph", 1500, [], 0, False, 0, 0, 0, False)
Yah = p_def.Player("Yah", 1500, [], 0, False, 0, 0, 0, False)
Computer = p_def.Player("AI", 1500, [], 0, False, 0, 0, 0, False)
player_list = [Aleph, Yah, Computer]
def count_bankrupt_players(players):
"""
Counts how many players have been bankrupted.
:param players: list, players that are playing the game.
:return: int, number of players that are bankrupt.
"""
counter = 0
for player in players:
if player.bankruptcy_status:
counter += 1
return counter
def display_winner(players):
"""
Prints out which player has won.
:param players: list, players that are playing the game.
:return: None.
"""
for player in players:
if player.bankruptcy_status == False:
return player.name
if __name__ == "__main__":
print("Beginning game!")
info.display_instructions()
i = 0
# continue running while there is more than one non-bankrupt player remaining.
while count_bankrupt_players(player_list) != len(player_list)-1:
i = i % len(player_list)
print()
print(f"{player_list[i].name}'s turn:")
if player_list[i].name == "AI":
ai.move(Computer, board)
else:
user_choice = input("What do you want to do? ")
result = player_list[i].player_action(user_choice, player_list, Computer, board)
while result == -1: # keep asking the user until they choose to roll the dice.
user_choice = input("What do you want to do? ")
result = player_list[i].player_action(user_choice, player_list, Computer, board)
new_pos = player_list[i].move_player(result)
player_list[i].check_pos(board)
i += 1
print(f"Game over! {display_winner(player_list)} has won!")