Created
October 22, 2023 03:25
-
-
Save sumanchapai/f5248cf08bc50d050ac17937826421ef to your computer and use it in GitHub Desktop.
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
from typing import List | |
class Player: | |
def __init__(self, name:str): | |
self.name = name | |
self.earnings = {} | |
def earn_from(self, p, amount): | |
current_earning_from_p = self.earnings.get(p, 0) | |
self.earnings[p] = current_earning_from_p + amount | |
to_pay = p.earnings.get(self, 0) | |
p.earnings[self] = to_pay - amount | |
def total(self): | |
return sum(self.earnings.values()) | |
def __repr__(self): | |
return f"{self.name}-Total:{self.total()}" | |
def __str__(self): | |
return str(self) | |
class Round: | |
def __init__(self, players:List[Player], bot:int): | |
self.players = players | |
self.round = 1 | |
self.bot = bot | |
self._done = False | |
def kitti(self): | |
if not self._done: | |
self.round += 1 | |
else: | |
print("Game is already done") | |
def winner(self, p): | |
if not self._done: | |
for i in filter(lambda x: not x is p, self.players): | |
amount_to_earn = self.bot * self.round | |
p.earn_from(i, amount_to_earn) | |
self._done = True | |
else: | |
print("Game is already done") | |
def __repr__(self): | |
return f"Round:{self.round}----Total:{len(self.players) * self.round * self.bot}" | |
def __str__(self): | |
return str(self) | |
supreme = Player("supreme") | |
suman = Player("suman") | |
nis = Player("nis") | |
nipun = Player("nipun") | |
shan = Player("shan") | |
players = [supreme, suman, nis, nipun, shan] | |
bot = 1 | |
def create(): | |
global r | |
r = Round(players, bot) | |
return r |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment