forked from georgelid06/Marvel-Snap-Simulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocation.py
163 lines (137 loc) · 5.43 KB
/
location.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
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
160
161
162
163
from enums import PLAYER1_ID, PLAYER2_ID
class Location:
def __init__(
self,
name,
effect_description,
effect=None,
on_reveal_effect=None,
no_destroy=None,
can_play_card=None,
end_of_turn_effect=None,
position=None,
):
self.name = name
self.effect_description = effect_description
self.effect = effect
self.on_reveal_effect = on_reveal_effect
self.no_destroy = no_destroy
self.can_play_card = can_play_card
self.end_of_turn_effect = end_of_turn_effect
self.cards = []
self.player1_played_card = False
self.player2_played_card = False
self.revealed = False
self.position = position
self.powers = {PLAYER1_ID: 0, PLAYER2_ID: 0}
def __str__(self):
return f"{self.name} (Effect: {self.effect_description})"
def __repr__(self):
return f"{self.name} (Effect: {self.effect_description})"
def calculate_total_power(self, player_id):
total_power = sum(
card.power for card in self.cards if card.owner_id == player_id
)
card_list = [
(card.name, card.power) for card in self.cards if card.owner_id == player_id
]
card_list.clear()
return total_power
def determine_winner(self):
player_powers = [0, 0]
for card in self.cards:
power = card.power
player_powers[card.owner_id] += power
if player_powers[0] > player_powers[1]:
return 0
elif player_powers[1] > player_powers[0]:
return 1
else:
return None
def can_play_card_at_location(self, card, location, current_turn, player_energy):
# Check if the card's energy cost is less than or equal to the player's energy
if card.energy_cost > player_energy:
return False
# Check if the location has a specific rule that prevents the card from being played
if location.name == "The Vault":
if current_turn == 6:
return False
elif location.name == "The Big House":
if card.energy_cost in [4, 5, 6]:
return False
# Check if the location has a general rule that prevents the card from being played
if location.can_play_card and not location.can_play_card(
location, current_turn
):
return False
# Check if the location already has 4 cards from the player
if sum(1 for c in location.cards if c.owner_id == card.owner_id) >= 4:
return False
return True
def apply_location_effect(self, game):
if self.name == "Tinkerer's Workshop":
game.players[0].energy += 1
game.players[1].energy += 1
def generate_all_locations():
# Define location effects here
def xandar_effect(card, player, location):
card.power += 1
def throne_room_effect(card, player, location_index):
location = player.game.locations[location_index]
# Find the card(s) with the highest power
highest_power = max(location.cards, key=lambda c: c.base_power).base_power
highest_power_cards = [
c for c in location.cards if c.base_power == highest_power
]
# Double the power of the highest power card(s)
for c in highest_power_cards:
if c.base_power == highest_power:
c.power = c.base_power * 2
# Undo the doubling of the power for the other cards
for c in location.cards:
if c not in highest_power_cards and c.power > c.base_power:
c.power = c.base_power
def negative_zone_effect(card, player, location):
card.power -= 3
def wakanda_no_destroy(location):
pass # Do not destroy cards in this location
def stark_tower_end_of_turn_five(location_index, game, current_turn):
if current_turn == 5:
location = game.locations[location_index]
for card in location.cards:
card.power += 2
def murderworld_end_of_turn_three(location_index, game, current_turn):
if current_turn == 3:
location = game.locations[location_index]
location.cards.clear()
# Generate all locations
all_locations = [
Location("Xandar", "Cards here have +1 Power.", xandar_effect),
Location(
"Wakanda", "Cards here can't be destroyed.", no_destroy=wakanda_no_destroy
),
Location("Tinkerer's Workshop", "+1 Energy this turn."),
Location(
"Throne Room",
"Card(s) here with the highest Power have their Power doubled.",
effect=throne_room_effect,
),
Location("The Vault", "On turn 6, cards can't be played here."),
Location("The Big House", "4, 5, and 6-Cost cards can't be played here."),
Location(
"Stark Tower",
"At the end of turn 5, give all cards here +2 Power.",
end_of_turn_effect=stark_tower_end_of_turn_five,
),
Location(
"Negative Zone", "Cards here have -3 Power.", effect=negative_zone_effect
),
Location(
"Murderworld",
"At the end of turn 3, destroy all cards here.",
end_of_turn_effect=murderworld_end_of_turn_three,
),
# Add the remaining locations with their respective effects
# ...
]
return all_locations