From 841b49caec1d955e10e702e9225f0f85fdd94957 Mon Sep 17 00:00:00 2001 From: "DESKTOP-FTAUB53\\handg" Date: Sun, 22 Jan 2023 11:12:57 +0100 Subject: [PATCH] first commit --- econ/agents/autoproduction.py | 29 +++++++++++++++++++++++++++++ econ/agents/base_agent.py | 5 +++++ econ/business.py | 22 ++++++++++++++++++++++ main.py | 0 4 files changed, 56 insertions(+) create mode 100644 econ/agents/autoproduction.py create mode 100644 econ/agents/base_agent.py create mode 100644 econ/business.py create mode 100644 main.py diff --git a/econ/agents/autoproduction.py b/econ/agents/autoproduction.py new file mode 100644 index 0000000..1c62e4b --- /dev/null +++ b/econ/agents/autoproduction.py @@ -0,0 +1,29 @@ +from base_agent import BaseAgent +class AutoProductionAgent(BaseAgent): + """ + Automaticaly produces commodity if in business inventory + """ + + + def __init__(self,business) -> None: + super().__init__() + self.business=business + self.prod=business.production + + + + def can_produce(self): + # If can produce item + for k,cost in self.prod.items(): + if cost > self.business.inventory[k]: + return False + return True + + def tick(self): + if not self.can_produce(): + return + # remove cost from inventory + for k,cost in self.prod.items(): + self.business.inventory[k]-=cost + # add commodity + self.business.inventory[self.prod['name']]+=self.prod["amount"] diff --git a/econ/agents/base_agent.py b/econ/agents/base_agent.py new file mode 100644 index 0000000..20c7884 --- /dev/null +++ b/econ/agents/base_agent.py @@ -0,0 +1,5 @@ +class BaseAgent(): + def tick(): + """ + Tick method for simulation to call to execute selected action + """ \ No newline at end of file diff --git a/econ/business.py b/econ/business.py new file mode 100644 index 0000000..9006b93 --- /dev/null +++ b/econ/business.py @@ -0,0 +1,22 @@ +class Business(): + def __init__(self,production,balance) -> None: + """production (dict): { + name: 'Gem', + amount: 4, + craft: { + 'Raw_Gem': 4, + 'Tool_Gem': 0.2, + } + } + balance (int): Starting Balance + """ + self.production=production + self.balance=balance + #Setup Inventory + self.inventory={production["name"]: 0} + for k in production["craft"].items(): + self.inventory[k]=0 + + pass + + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..e69de29