first commit
This commit is contained in:
29
econ/agents/autoproduction.py
Normal file
29
econ/agents/autoproduction.py
Normal file
@@ -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"]
|
||||
5
econ/agents/base_agent.py
Normal file
5
econ/agents/base_agent.py
Normal file
@@ -0,0 +1,5 @@
|
||||
class BaseAgent():
|
||||
def tick():
|
||||
"""
|
||||
Tick method for simulation to call to execute selected action
|
||||
"""
|
||||
22
econ/business.py
Normal file
22
econ/business.py
Normal file
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user