#include "simulator.h" simulator::simulator(class decider* decider, double money, unsigned stock) : decider(decider), money(money), start_money(money), stock(stock), start_stock(stock) { decider->start_money = money; decider->start_stock = stock; initialized = false; } double simulator::proceed(double price) { if (!initialized) { initialized = true; start_price = price; decider->reset(price); } auto decision = decider->decide(price, money, stock); auto current = price * stock + money; auto max_credit = std::max(current * this->credit_ratio, -this->max_credit); if (decision < 0) { decision = std::max(decision, -stock); // cannot sell more than we actually have } else if (decision > 0) { decision = std::min(floor((money + max_credit) / price), decision); } money -= price * decision; stock += decision; return decision; } std::vector simulator::proceed(std::vector prices) { std::vector result; for(auto price : prices) { result.push_back(proceed(price)); } return result; }