from lightmatchingengine.lightmatchingengine import LightMatchingEngine,Side,Trade,Order
from econ.exchange import Exchange
from econ.simulation import Simulation
from econ.business.Price_Believe_Business import Price_Believe_Business
from econ.commoditys import commoditys
from econ.cells import db, cell
import log
from tqdm import tqdm
db.load_world("db/world.json")

commoditys.search_yaml_files()

cell_realm=[]

for c in db.world["cells"]["cells"]:
    if c["province"]==187:
        cell_realm.append(c)

cells=cell.create_cells_from_world_cells(cell_realm)


w="world"
cx=Exchange()
cxs=[cx]
# Init World

# Create Demand
#cx.submit_order(w,"Wood",0,1000,Side.BUY)
#cx.submit_order(2,"Gem",1,10,Side.SELL)

sim=Simulation()
sim.seed(55)
sim.set_cells(cells[:10])
sim.reset()
#sim.tick(1)
# create info
while len(sim.get_underutelized_prods(2))>0:
    sim.create_bussiness(2)
#sim.reset()
for a in tqdm(range(50)):
    for i in range(100):
        sim.tick(100)
    sim.reset()
    sim.create_bussiness(2)
log.writeEXData()
log.writeBusinessData()

print("help")