diff --git a/src/arcade/potts/sim/Potts.java b/src/arcade/potts/sim/Potts.java index 48b95e62..e225b295 100644 --- a/src/arcade/potts/sim/Potts.java +++ b/src/arcade/potts/sim/Potts.java @@ -159,13 +159,19 @@ public void step(SimState simstate) { HashSet uniqueIDTargets = getUniqueIDs(x, y, z); HashSet uniqueRegionTargets = getUniqueRegions(x, y, z); - // Select unique ID (if there is one), otherwise select unique - // region (if there is one). If there are neither, then skip. - if (uniqueIDTargets.size() > 0) { + // Check if there are valid unique targets. + boolean hasIDTargets = uniqueIDTargets.size() > 0; + boolean hasRegionTargets = uniqueRegionTargets.size() > 0; + boolean check = simstate.random.nextDouble() < 0.5; + + // Select unique ID or unique region (if they exist). If there is + // a unique ID and unique region target, then randomly select. If + // there are neither, then skip. + if (hasIDTargets && (!hasRegionsCell || !hasRegionTargets || check)) { int i = simstate.random.nextInt(uniqueIDTargets.size()); int targetID = (int) uniqueIDTargets.toArray()[i]; flip(ids[z][x][y], targetID, x, y, z, r); - } else if (hasRegionsCell && uniqueRegionTargets.size() > 0) { + } else if (hasRegionsCell && hasRegionTargets) { int i = simstate.random.nextInt(uniqueRegionTargets.size()); int targetRegion = (int) uniqueRegionTargets.toArray()[i]; flip(ids[z][x][y], regions[z][x][y], targetRegion, x, y, z, r);