LilasCorner / jlootbox

Other
1 stars 0 forks source link

Consider recording time of purchase instead of incrementing time count #8

Open JohnTMurphy-NIU opened 2 years ago

JohnTMurphy-NIU commented 2 years ago

Another strategy for determining how much time has passed since the last purchase is to record the tick when a purchase is made. Then the method can look like this:

getTimeSinceLastPurchased(){ return RunEnvironment.getInstance().getCurrentSchedule().getTickCount() - timeOfLastPurchase; }

The 'RunEnvironments.getInstance().getCurrentScheduled().getTickCount()' gives the current tick.

An advantage of this strategy is that you do not need to update the timeSinceLastPurchase for all agents every tick. If some agents are 'dormant' for long periods, you can avoid the overhead of looping through all of them and increment this every tick. This may not apply in your case, but it's something to think about if you every consider changing the scheduling mechanism so that not every agent acts in every turn (which is an advanced technique but useful sometimes).