From 82fc636d18181abcad0c1261ba46547094ac3ac9 Mon Sep 17 00:00:00 2001 From: tiera3 <87589219+tiera3@users.noreply.github.com> Date: Wed, 2 Oct 2024 11:27:37 +1000 Subject: [PATCH] Enable Striped Collation Uses stripe widths of 2-5 inclusive with equal chances for each. If data can be obtained, a later improvement would be to give different weightings to different stripe widths. --- .../src/main/java/mage/collation/Rotater.java | 45 +++++++++++++++++-- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/Mage/src/main/java/mage/collation/Rotater.java b/Mage/src/main/java/mage/collation/Rotater.java index 0af5fa77497..67242631909 100644 --- a/Mage/src/main/java/mage/collation/Rotater.java +++ b/Mage/src/main/java/mage/collation/Rotater.java @@ -15,7 +15,7 @@ import java.util.List; public class Rotater { private final List items; - private int position; + private int position, stripeLen = 0, stripeWidth, stripeDepth; public Rotater(T item) { this(true, item); @@ -37,10 +37,49 @@ public class Rotater { } } +// for striped collation + public Main(int sLen, String... items) { +// should there be an error check? +// assert ( items.size() % sLen ) == 0; + this.stripeLen = sLen; + this.items = Arrays.asList(items); + this.position = RandomUtil.nextInt(this.items.size()); + this.stripeWidth= this.nextWidth(); + this.stripeDepth= 1+ RandomUtil.nextInt(this.stripeWidth); + } + +// choose a stripe width between 2 & 5 inclusive +// ToDo when data available: enable different widths to have different likelihoods + public int nextWidth() { + return 2+ RandomUtil.nextInt(4); + } + public int iterate() { int i = position; - position++; - position %= items.size(); + if( stripeLen >0 ){ + if( stripeDepth < stripeWidth ){ + ++stripeDepth; + position -= 10; + if (position <0 ){ + position += items.size(); + } + }else{ + stripeDepth= 1; + if( (position % stripeLen) >0 ){ + position += stripeLen * (stripeWidth-1); + position %= items.size(); + }else{ + this.stripeWidth= this.nextWidth(); + } + position -= 1; + if (position <0 ){ + position += items.size(); + } + } + }else{ + position++; + position %= items.size(); + } return i; }