LilasCorner / jlootbox

Other
1 stars 0 forks source link

Refactor Player Logic to make more modular #2

Open JohnTMurphy-NIU opened 2 years ago

JohnTMurphy-NIU commented 2 years ago

You can move some code around in the Player to make it easier to specify individual points in a Player's logic. Consider something like:


public void step(){ if(decide()){ buyNewLootbox();
infoDump(); recordNewLootboxInHistory(); updateThreshold(); move(); // Does this happen only when a box is purchased? Or every step? } }

protected boolean decide(){ // Decision logic here; return true if decide to buy, false if not }

protected Lootbox buyNewLootbox(){ // Create a new lootbox here; returning it is just a convenience/convention, not currently used }

protected void recordNewLootboxInHistory(){ // Do that here }

protected void updateThreshold(){ // This may not be in the correct place in my example... πŸ˜‰ }


In this kind of form it's easier to specify the individual logic points and alternatives, like:

protected boolean decide(){ switch(DECISION_PARAMETER){ case SIMPLE: return true; // Always buy! case COIN_FLIP: return coinFlip.nextInt() < buyThreshold case default: return false; // Never- should never happen... }