Bladeren bron

first commit

Tum 1 jaar geleden
commit
170b677778
10 gewijzigde bestanden met toevoegingen van 401 en 0 verwijderingen
  1. BIN
      __pycache__/actions.cpython-37.pyc
  2. BIN
      __pycache__/events.cpython-37.pyc
  3. BIN
      __pycache__/game.cpython-37.pyc
  4. BIN
      __pycache__/supporters.cpython-37.pyc
  5. 198 0
      actions.py
  6. 32 0
      events.py
  7. 145 0
      game.py
  8. 6 0
      main.py
  9. 19 0
      supporters.py
  10. 1 0
      utils.py

BIN
__pycache__/actions.cpython-37.pyc


BIN
__pycache__/events.cpython-37.pyc


BIN
__pycache__/game.cpython-37.pyc


BIN
__pycache__/supporters.cpython-37.pyc


+ 198 - 0
actions.py

@@ -0,0 +1,198 @@
1
+import random
2
+
3
+class Actions:
4
+    def __init__(self, game):
5
+        self.game = game
6
+
7
+    def _perform_action(self, action_name, description, cost, success_effect, failure_effect, success_chance, influence_required=0, success_policy=None):
8
+        print(f"Scenario: {description}")
9
+        if self.game.money < cost:
10
+            print(f"Not enough money to {action_name.lower()}.")
11
+            return
12
+        if self.game.influence < influence_required:
13
+            print(f"Not enough influence to {action_name.lower()}.")
14
+            return
15
+
16
+        self.game.money -= cost
17
+        if random.randint(1, 100) <= success_chance:
18
+            for key, value in success_effect.items():
19
+                setattr(self.game, key, getattr(self.game, key) + value)
20
+            if success_policy:
21
+                self.game.policies.append(success_policy)
22
+            print(f"Success! {description} was successful.")
23
+        else:
24
+            for key, value in failure_effect.items():
25
+                setattr(self.game, key, getattr(self.game, key) + value)
26
+            print(f"Failure! {description} was unsuccessful.")
27
+
28
+    def campaign(self):
29
+        self._perform_action(
30
+            action_name="Campaign",
31
+            description="Door-to-Door Campaigning",
32
+            cost=10,
33
+            success_effect={"public_support": 10},
34
+            failure_effect={"public_support": -5},
35
+            success_chance=60
36
+        )
37
+
38
+    def pass_legislation(self):
39
+        self._perform_action(
40
+            action_name="Pass Legislation",
41
+            description="Healthcare Reform Bill",
42
+            cost=20,
43
+            influence_required=30,
44
+            success_effect={"public_support": 20},
45
+            success_policy="Healthcare Reform Bill",
46
+            failure_effect={},
47
+            success_chance=100
48
+        )
49
+
50
+    def hold_rally(self):
51
+        self._perform_action(
52
+            action_name="Hold Rally",
53
+            description="Community Unity Rally",
54
+            cost=15,
55
+            success_effect={"public_support": 15},
56
+            failure_effect={"public_support": -5},
57
+            success_chance=70
58
+        )
59
+
60
+    def media_campaign(self):
61
+        print("Scenario: Media Campaign")
62
+        print("Choose the type of media campaign:")
63
+        print("1. Online (Facebook)")
64
+        print("2. Online (TikTok)")
65
+        print("3. Online (Twitter)")
66
+        print("4. Online (Instagram)")
67
+        print("5. Offline (TV, Radio, Newspapers)")
68
+        choice = input("Enter the number of your choice: ")
69
+
70
+        demographics_effect = {
71
+            "1": {"age": "young", "gender": "female", "education": "medium"},
72
+            "2": {"age": "young", "gender": "female", "education": "low"},
73
+            "3": {"age": "middle-aged", "gender": "male", "education": "high"},
74
+            "4": {"age": "young", "gender": "female", "education": "high"},
75
+            "5": {"age": "senior", "gender": "male", "education": "low"}
76
+        }
77
+
78
+        if choice in demographics_effect:
79
+            cost = 25
80
+            success_chance = random.randint(1, 100)
81
+
82
+            if self.game.money < cost:
83
+                print("Not enough money to launch a media campaign.")
84
+                return
85
+
86
+            self.game.money -= cost
87
+            if success_chance <= 80:
88
+                self.game.public_support += 25
89
+                dem = demographics_effect[choice]
90
+                self.game.supporters.increase_support(dem)
91
+                print(f"The {choice} campaign resonates with the public, increasing support by 25% and boosting support among {dem}.")
92
+            else:
93
+                self.game.public_support -= 10
94
+                print(f"The {choice} campaign backfires, leading to a decrease in support by 10%.")
95
+        else:
96
+            print("Invalid choice. Please try again.")
97
+
98
+    def fundraise(self):
99
+        print("Scenario: High-Profile Fundraiser Dinner")
100
+        print("You host an exclusive fundraiser dinner with influential donors and supporters.")
101
+        success_chance = random.randint(1, 100)
102
+
103
+        if success_chance <= 50:
104
+            funds_raised = random.randint(20, 50)
105
+            self.game.money += funds_raised
106
+            print(f"The event is a success, raising ${funds_raised}.")
107
+        else:
108
+            print("Poor attendance results in no funds being raised.")
109
+
110
+    def debate(self):
111
+        print("Scenario: Televised Debate with Opponent")
112
+        print("You participate in a live televised debate against a key opponent, addressing critical issues and defending your policies.")
113
+        opponent = random.choice(self.game.opponents)
114
+        success_chance = random.randint(1, 100)
115
+
116
+        if success_chance <= 50:
117
+            self.game.influence += 20
118
+            self.game.public_support += 10
119
+            print(f"You outshine your opponent, increasing influence by 20 and public support by 10%.")
120
+        else:
121
+            self.game.influence -= 10
122
+            self.game.public_support -= 5
123
+            print(f"The debate goes poorly, decreasing influence by 10 and public support by 5% as voters favor {opponent}'s arguments.")
124
+
125
+    def set_tax_policy(self):
126
+        print("Scenario: Set Tax Policy")
127
+        new_tax_rate = int(input("Enter the new tax rate (0-100): "))
128
+        if 0 <= new_tax_rate <= 100:
129
+            self.game.tax_rate = new_tax_rate
130
+            print(f"Tax rate set to {self.game.tax_rate}%.")
131
+            if new_tax_rate > 30:
132
+                self.game.public_support -= 10
133
+                print("High tax rate decreases public support by 10%.")
134
+            elif new_tax_rate < 10:
135
+                self.game.public_support += 10
136
+                print("Low tax rate increases public support by 10%.")
137
+        else:
138
+            print("Invalid tax rate. Please enter a value between 0 and 100.")
139
+
140
+    def invest_in_sector(self):
141
+        print("Scenario: Invest in a Sector")
142
+        sectors = ["Infrastructure", "Education", "Healthcare"]
143
+        print(f"Sectors available for investment: {', '.join(sectors)}")
144
+        sector_choice = input("Enter the sector you want to invest in: ")
145
+
146
+        if sector_choice in sectors:
147
+            investment_amount = int(input("Enter the amount you want to invest: "))
148
+            if self.game.money >= investment_amount:
149
+                self.game.money -= investment_amount
150
+                self.game.gdp += investment_amount * 1.5  # Example multiplier
151
+                self.game.unemployment_rate -= 1  # Reduce unemployment
152
+                print(f"Invested ${investment_amount} in {sector_choice}. GDP increased by ${investment_amount * 1.5} and unemployment rate decreased.")
153
+            else:
154
+                print("Not enough money to invest.")
155
+        else:
156
+            print("Invalid sector choice.")
157
+
158
+    def allocate_military_budget(self):
159
+        print("Scenario: Allocate Military Budget")
160
+        additional_budget = int(input("Enter the additional military budget (0-100): "))
161
+        if 0 <= additional_budget <= self.game.money:
162
+            self.game.money -= additional_budget
163
+            self.game.military_budget += additional_budget
164
+            self.game.military_strength += additional_budget // 2  # Example conversion rate
165
+            print(f"Allocated an additional ${additional_budget} to the military budget. Military strength increased by {additional_budget // 2}.")
166
+        else:
167
+            print("Invalid budget allocation. Please enter a value within your available money.")
168
+
169
+    def opponent_friction(self):
170
+        actions = [
171
+            ("Negative Campaign", "Your opponent launches a negative campaign against you. Public support decreases by 10%.", -10, 0, 0),
172
+            ("Political Sabotage", "Your opponent sabotages your fundraising event. You raise no money.", 0, 0, -1),
173
+            ("Influence Loss", "Your opponent spreads rumors, reducing your influence. Influence decreases by 15%.", 0, -15, 0)
174
+        ]
175
+        action = random.choice(actions)
176
+        print(f"Opponent Action: {action[0]}")
177
+        print(f"{action[1]}")
178
+        self.game.public_support += action[2]
179
+        self.game.influence += action[3]
180
+        if action[0] == "Political Sabotage":
181
+            return False  # Indicate that fundraising failed due to sabotage
182
+        return True
183
+
184
+    def foreign_interference(self):
185
+        actions = [
186
+            ("Russia", "Russia interferes with your campaign, spreading disinformation and causing distrust among voters. Public support decreases by 15%.", -15, 0, 0),
187
+            ("China", "China launches a cyber-attack on your campaign infrastructure, reducing your influence. Influence decreases by 20%.", 0, -20, 0),
188
+            ("Foreign Sabotage", "Opposition countries collaborate to sabotage your fundraising event. You raise no money.", 0, 0, -1)
189
+        ]
190
+        action = random.choice(actions)
191
+        print(f"Foreign Interference: {action[0]}")
192
+        print(f"{action[1]}")
193
+        self.game.public_support += action[2]
194
+        self.game.influence += action[3]
195
+        if action[0] == "Foreign Sabotage":
196
+            return False  # Indicate that fundraising failed due to sabotage
197
+        return True
198
+

+ 32 - 0
events.py

@@ -0,0 +1,32 @@
1
+import random
2
+
3
+class Events:
4
+    def __init__(self, game):
5
+        self.game = game
6
+
7
+    def random_event(self):
8
+        events = [
9
+            ("Economic Boom", "Your country experiences an economic boom. Public support increases by 10%.", 10, 0, 10, 200, -1),
10
+            ("Scandal", "A scandal erupts involving your campaign. Public support decreases by 15%.", -15, 0, -15, 0, 0),
11
+            ("Foreign Policy Win", "You achieve a major foreign policy victory. Influence increases by 20%.", 0, 20, 0, 0, 0),
12
+            ("Natural Disaster", "A natural disaster strikes. You lose $30 in relief efforts.", -30, 0, -10, -100, 1),
13
+            ("Military Conflict", "A military conflict arises requiring immediate attention.", 0, 0, -20, 0, 0),
14
+            ("Opponent Friction", "An opponent takes action against you.", 0, 0, -10, 0, 0),
15
+            ("Foreign Interference", "A foreign country interferes with your campaign.", 0, 0, -10, 0, 0)
16
+        ]
17
+        event = random.choice(events)
18
+        print(f"Random Event: {event[0]}")
19
+        print(f"{event[1]}")
20
+        self.game.money += event[2]
21
+        self.game.influence += event[3]
22
+        self.game.public_support += event[4]
23
+        self.game.gdp += event[5]
24
+        self.game.unemployment_rate += event[6]
25
+
26
+        if event[0] == "Military Conflict":
27
+            self.game.handle_conflict()
28
+        elif event[0] == "Opponent Friction":
29
+            self.game.opponent_friction()
30
+        elif event[0] == "Foreign Interference":
31
+            self.game.foreign_interference()
32
+

+ 145 - 0
game.py

@@ -0,0 +1,145 @@
1
+import random
2
+from actions import Actions
3
+from events import Events
4
+from supporters import Supporters
5
+
6
+class PoliticalSimulationGame:
7
+    def __init__(self):
8
+        self.money = 100
9
+        self.influence = 50
10
+        self.public_support = 50
11
+        self.day = 1
12
+        self.policies = []
13
+        self.opponents = ["Opponent 1", "Opponent 2", "Opponent 3"]
14
+        self.gdp = 1000  # Gross Domestic Product
15
+        self.unemployment_rate = 5  # Unemployment rate in percentage
16
+        self.tax_rate = 20  # Tax rate in percentage
17
+        self.military_budget = 50  # Initial military budget
18
+        self.military_strength = 100  # Initial military strength
19
+        self.actions_per_day = 3  # Number of actions allowed per day
20
+        self.post_election = False
21
+
22
+        self.supporters = Supporters()
23
+
24
+    def display_status(self):
25
+        print(f"\n*****************************")
26
+        print(f"Day {self.day}")
27
+        print(f"Money: ${self.money}")
28
+        print(f"Influence: {self.influence}")
29
+        print(f"Public Support: {self.public_support}%")
30
+        print(f"Policies: {', '.join(self.policies) if self.policies else 'None'}")
31
+        print(f"GDP: ${self.gdp}")
32
+        print(f"Unemployment Rate: {self.unemployment_rate}%")
33
+        print(f"Tax Rate: {self.tax_rate}%")
34
+        print(f"Military Budget: ${self.military_budget}")
35
+        print(f"Military Strength: {self.military_strength}")
36
+        self.supporters.display()
37
+        print(f"\n*****************************")
38
+
39
+    def take_action(self, action_number):
40
+        actions = Actions(self)
41
+        if action_number == "1":
42
+            actions.campaign()
43
+        elif action_number == "2":
44
+            actions.pass_legislation()
45
+        elif action_number == "3":
46
+            actions.hold_rally()
47
+        elif action_number == "4":
48
+            actions.media_campaign()
49
+        elif action_number == "5":
50
+            if not actions.opponent_friction() or not actions.foreign_interference():
51
+                return False  # Skip fundraising if sabotaged
52
+            actions.fundraise()
53
+        elif action_number == "6":
54
+            actions.debate()
55
+        elif action_number == "7":
56
+            actions.set_tax_policy()
57
+        elif action_number == "8":
58
+            actions.invest_in_sector()
59
+        elif action_number == "9":
60
+            actions.allocate_military_budget()
61
+        self.display_status()  # Show status after each action
62
+        return True
63
+
64
+    def end_day(self):
65
+        self.day += 1
66
+        self.money += self.tax_rate * 10  # Example revenue generation
67
+        print(f"Day ended. You earned ${self.tax_rate * 10} from taxes.")
68
+        self.display_status()  # Show status at end of day
69
+
70
+    def check_win_condition(self):
71
+        if self.public_support >= 100:
72
+            print("Congratulations! You've won the election!")
73
+            self.post_election = True
74
+            return True
75
+        elif self.public_support <= 0:
76
+            print("You've lost the election. Better luck next time.")
77
+            return True
78
+        return False
79
+
80
+    def post_election_actions(self):
81
+        print("Congratulations on winning the election! Now you need to maintain your approval ratings and pass significant legislation.")
82
+        self.actions_per_day = 2  # Fewer actions per day post-election to increase difficulty
83
+        while True:
84
+            self.display_status()
85
+            actions_left = self.actions_per_day
86
+            while actions_left > 0:
87
+                print("Choose an action:")
88
+                print("1. Pass Legislation")
89
+                print("2. Hold Rally")
90
+                print("3. Media Campaign")
91
+                print("4. Allocate Military Budget")
92
+                choice = input("Enter the number of your choice: ")
93
+
94
+                if not self.take_action(choice):
95
+                    continue
96
+
97
+                actions_left -= 1
98
+                if random.randint(1, 100) <= 30:
99
+                    self.random_event()
100
+
101
+                if self.check_win_condition():
102
+                    return
103
+
104
+            self.end_day()
105
+
106
+    def play(self):
107
+        print("Welcome to the Enhanced Political Simulation Game with Economic, Military, Opponent Friction, and Demographic Elements!")
108
+        while True:
109
+            if self.post_election:
110
+                self.post_election_actions()
111
+                break
112
+
113
+            self.display_status()
114
+            actions_left = self.actions_per_day
115
+            while actions_left > 0:
116
+                print("Choose an action:")
117
+                print("1. Campaign")
118
+                print("2. Pass Legislation")
119
+                print("3. Hold Rally")
120
+                print("4. Media Campaign")
121
+                print("5. Fundraise")
122
+                print("6. Debate")
123
+                print("7. Set Tax Policy")
124
+                print("8. Invest in a Sector")
125
+                print("9. Allocate Military Budget")
126
+                choice = input("Enter the number of your choice: ")
127
+
128
+                if not self.take_action(choice):
129
+                    continue
130
+
131
+                actions_left -= 1
132
+                if random.randint(1, 100) <= 30:
133
+                    self.random_event()
134
+
135
+                if self.check_win_condition():
136
+                    break
137
+
138
+            self.end_day()
139
+
140
+    def random_event(self):
141
+        events = Events(self)
142
+        events.random_event()
143
+        self.display_status()  # Show status after random event
144
+
145
+

+ 6 - 0
main.py

@@ -0,0 +1,6 @@
1
+from game import PoliticalSimulationGame
2
+
3
+if __name__ == "__main__":
4
+    game = PoliticalSimulationGame()
5
+    game.play()
6
+

+ 19 - 0
supporters.py

@@ -0,0 +1,19 @@
1
+class Supporters:
2
+    def __init__(self):
3
+        self.supporters = {
4
+            "age": {"young": 30, "middle-aged": 40, "senior": 30},
5
+            "gender": {"male": 50, "female": 50},
6
+            "education": {"low": 30, "medium": 40, "high": 30}
7
+        }
8
+
9
+    def display(self):
10
+        print("Supporters Demographics:")
11
+        print(f"  Age: {self.supporters['age']}")
12
+        print(f"  Gender: {self.supporters['gender']}")
13
+        print(f"  Education: {self.supporters['education']}")
14
+
15
+    def increase_support(self, dem):
16
+        self.supporters["age"][dem["age"]] += 5
17
+        self.supporters["gender"][dem["gender"]] += 5
18
+        self.supporters["education"][dem["education"]] += 5
19
+

+ 1 - 0
utils.py

@@ -0,0 +1 @@
1
+# Add any utility functions here, if needed.