From 7ba015f6e4bb9dff9572733a27892e7e28c12b41 Mon Sep 17 00:00:00 2001 From: jessicasyu <15913767+jessicasyu@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:57:09 -0500 Subject: [PATCH] Update voxel update order to random selection --- src/arcade/potts/sim/Potts.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) 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);