Created
December 27, 2019 18:22
-
-
Save tonetheman/88e9e2e170dc87d486b7387a67732775 to your computer and use it in GitHub Desktop.
See here not finished impl of http://www.hackerfactor.com/blog/index.php?/archives/860-The-Oligarchy-Game.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
class Person: | |
def __init__(self,id): | |
self.amount = 100 | |
self.id = id | |
def __repr__(self): | |
return str(self.id) + " :: " + str(self.amount) | |
# setup | |
COUNT = 20 | |
people = [] | |
for i in range(COUNT): | |
people.append(Person(i)) | |
def singleround(): | |
# start round | |
choosefrom = [] | |
for i in range(COUNT): | |
choosefrom.append(people[i]) | |
for i in range(int(COUNT/2)): | |
p1 = random.choice(choosefrom) | |
choosefrom.remove(p1) | |
p2 = random.choice(choosefrom) | |
choosefrom.remove(p2) | |
# now battle | |
betamount = 0 | |
if p1.amount<p2.amount: | |
betamount = int(p1.amount/2) | |
else: | |
betamount = int(p2.amount/2) | |
rnum = random.random() | |
if rnum>0.50: | |
# in this case p1 won | |
p1.amount = p1.amount+ betamount | |
p2.amount = p2.amount - betamount | |
else: | |
# p2 won | |
p2.amount = p2.amount + betamount | |
p1.amount = p1.amount - betamount | |
for i in range(10): | |
singleround() | |
print(people) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment