Skip to content

Commit

Permalink
Update voxel update order to random selection
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicasyu committed Feb 26, 2024
1 parent 73cc052 commit 7ba015f
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/arcade/potts/sim/Potts.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,19 @@ public void step(SimState simstate) {
HashSet<Integer> uniqueIDTargets = getUniqueIDs(x, y, z);
HashSet<Integer> 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);
Expand Down

0 comments on commit 7ba015f

Please sign in to comment.