forked from radjavi/considition20
-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_state.py
154 lines (132 loc) 路 6.18 KB
/
game_state.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
from typing import List
class GameState:
def __init__(self, map_values):
self.game_id: str = map_values["gameId"]
self.map_name: str = map_values["mapName"]
self.max_turns: int = map_values["maxTurns"]
self.max_temp: float = map_values["maxTemp"]
self.min_temp: float = map_values["minTemp"]
self.map: List[List[int]] = map_values["map"]
self.energy_levels: List[EnergyLevel] = []
for level in map_values["energyLevels"]:
self.energy_levels.append(EnergyLevel(level))
self.available_residence_buildings: List[BlueprintResidenceBuilding] = []
for building in map_values["availableResidenceBuildings"]:
self.available_residence_buildings.append(
BlueprintResidenceBuilding(building)
)
self.available_utility_buildings: List[BlueprintUtilityBuilding] = []
for building in map_values["availableUtilityBuildings"]:
self.available_utility_buildings.append(BlueprintUtilityBuilding(building))
self.available_upgrades: List[Upgrade] = []
for upgrade in map_values["availableUpgrades"]:
self.available_upgrades.append(Upgrade(upgrade))
self.effects: List[Effect] = []
for effect in map_values["effects"]:
self.effects.append(Effect(effect))
self.turn: int = 0
self.funds: float = 0
self.total_co2: float = 0
self.total_happiness: float = 0
self.current_temp: float = 0
self.queue_happiness: float = 0
self.housing_queue: int = 0
self.residences: List[Residence] = []
self.utilities: List[Utility] = []
self.errors: List[str] = []
self.messages: List[str] = []
self.total_pop = 0
self.current_score = 0
self.max_score = 0
def update_state(self, state):
self.turn = state["turn"]
self.funds = state["funds"]
self.total_co2 = state["totalCo2"]
self.total_happiness = state["totalHappiness"]
self.current_temp = state["currentTemp"]
self.queue_happiness = state["queueHappiness"]
self.housing_queue = state["housingQueue"]
self.residences = []
for building in state["residenceBuildings"]:
self.residences.append(Residence(building))
self.utilities = []
for building in state["utilityBuildings"]:
self.utilities.append(Utility(building))
self.errors = state["errors"]
self.messages = state["messages"]
self.total_pop = sum(x.current_pop for x in self.residences)
self.current_score = max(
15 * self.total_pop + 0.1 * self.total_happiness - self.total_co2, 0
)
self.max_score = (
self.current_score
if self.current_score > self.max_score
else self.max_score
)
class EnergyLevel:
def __init__(self, level_values):
self.energy_threshold: int = level_values["energyThreshold"]
self.cost_per_mwh: float = level_values["costPerMwh"]
self.co2_per_mwh: float = level_values["tonCo2PerMwh"]
class Blueprint:
def __init__(self, blueprint):
self.building_name: str = blueprint["buildingName"]
self.cost: int = blueprint["cost"]
self.co2_cost: int = blueprint["co2Cost"]
self.base_energy_need: float = blueprint["baseEnergyNeed"]
self.build_speed: int = blueprint["buildSpeed"]
self.type: str = blueprint["type"]
self.release_tick: int = blueprint["releaseTick"]
class BlueprintUtilityBuilding(Blueprint):
def __init__(self, blueprint_building):
super().__init__(blueprint_building)
self.effects: [str] = blueprint_building["effects"]
self.queue_increase: float = blueprint_building["queueIncrease"]
class BlueprintResidenceBuilding(Blueprint):
def __init__(self, blueprint_building):
super().__init__(blueprint_building)
self.max_pop: int = blueprint_building["maxPop"]
self.income_per_pop: float = blueprint_building["incomePerPop"]
self.emissivity: float = blueprint_building["emissivity"]
self.maintenance_cost: int = blueprint_building["maintenanceCost"]
self.decay_rate: float = blueprint_building["decayRate"]
self.max_happiness = blueprint_building["maxHappiness"]
class Upgrade:
def __init__(self, upgrade):
self.name: str = upgrade["name"]
self.effect: str = upgrade["effect"]
self.cost: int = upgrade["cost"]
class Effect:
def __init__(self, effect):
self.name: str = effect["name"]
self.radius: int = effect["radius"]
self.emissivity_multiplier: float = effect["emissivityMultiplier"]
self.decay_multiplier: float = effect["decayMultiplier"]
self.building_income_increase: float = effect["buildingIncomeIncrease"]
self.max_happiness_increase: float = effect["maxHappinessIncrease"]
self.mwh_production: float = effect["mwhProduction"]
self.base_energy_mwh_increase: float = effect["baseEnergyMwhIncrease"]
self.co2_per_pop_increase: float = effect["co2PerPopIncrease"]
self.decay_increase: float = effect["decayIncrease"]
class Building:
def __init__(self, building):
self.building_name: str = building["buildingName"]
self.X: int = building["position"]["x"]
self.Y: int = building["position"]["y"]
self.effective_energy_in: float = building["effectiveEnergyIn"]
self.build_progress: int = building["buildProgress"]
self.can_be_demolished: bool = building["canBeDemolished"]
self.effects: List[str] = building["effects"]
class Residence(Building):
def __init__(self, residence):
super().__init__(residence)
self.current_pop: int = residence["currentPop"]
self.temperature: float = residence["temperature"]
self.requested_energy_in: float = residence["requestedEnergyIn"]
self.happiness_per_tick_per_pop: float = residence["happinessPerTickPerPop"]
self.health: int = residence["health"]
self.X = residence["position"]["x"]
self.Y = residence["position"]["y"]
class Utility(Building):
def __init__(self, utility):
super().__init__(utility)