Skip to content

Commit

Permalink
add shuffle method for scrambled odds
Browse files Browse the repository at this point in the history
This resolves src/utils/Shuffles.java:220 (which is now gone)
  • Loading branch information
Gaming32 committed Nov 22, 2020
1 parent a4180fc commit e11852c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/main/ArrayManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ of this software and associated documentation files (the "Software"), to deal
final public class ArrayManager {
private int[] presortedArray;
private utils.Shuffles[] shuffleTypes;
private String[] shuffleIDs = {"Randomly", "Backwards", "Few Unique", "Almost Sorted", "Already Sorted"};
private String[] shuffleIDs = {"Randomly", "Shuffled Odds", "Backwards", "Few Unique", "Almost Sorted", "Already Sorted"};

private volatile boolean MUTABLE;

Expand Down
5 changes: 4 additions & 1 deletion src/prompts/ShufflePrompt.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
.addComponent(this.jLabel1)
.addGap(5, 5, 5))
.addGroup(layout.createSequentialGroup()
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE))
.addComponent(this.jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
Expand Down Expand Up @@ -160,6 +160,9 @@ private void jList1ValueChanged(javax.swing.event.ListSelectionEvent evt) throws
case 4:
ArrayManager.setShuffle(ArrayManager.getShuffles()[4]);
break;
case 5:
ArrayManager.setShuffle(ArrayManager.getShuffles()[5]);
break;
default:
break;
}
Expand Down
24 changes: 13 additions & 11 deletions src/utils/Shuffles.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,19 @@ public void shuffleArray(int[] array, ArrayVisualizer ArrayVisualizer, Delays De
*/
}
},
SHUFFLED_ODDS {
@Override
public void shuffleArray(int[] array, ArrayVisualizer ArrayVisualizer, Delays Delays, Highlights Highlights, Writes Writes) {
int currentLen = ArrayVisualizer.getCurrentLength();

for(int i = 1; i < currentLen; i += 2){
int randomIndex = (((int) ((Math.random() * (currentLen - i)) / 2)) * 2) + i;
Writes.swap(array, i, randomIndex, 0, true, false);

if(ArrayVisualizer.shuffleEnabled()) Delays.sleep(2);
}
}
},
REVERSE {
@Override
public void shuffleArray(int[] array, ArrayVisualizer ArrayVisualizer, Delays Delays, Highlights Highlights, Writes Writes) {
Expand Down Expand Up @@ -138,7 +151,6 @@ public void shuffleArray(int[] array, ArrayVisualizer ArrayVisualizer, Delays De
}

/*
int currentLen = ArrayVisualizer.getCurrentLength();
Writes.write(array, 0, 0, 1, true, false);
for(int i = 1; i < currentLen; i++) {
int log = (int) (Math.log(i) / Math.log(2));
Expand Down Expand Up @@ -203,16 +215,6 @@ else if(k == n) {
else
return concat(circleGen(n-1, k, Writes), addToAll(circleGen(n-1, k-1, Writes), 1 << (n-1), Writes), Writes);
}
*/
/*
//TODO: Consider separate method
for(int i = 1; i < currentLen; i += 2){
int randomIndex = (((int) ((Math.random() * (currentLen - i)) / 2)) * 2) + i;
Writes.swap(array, i, randomIndex, 0, true, false);
if(ArrayVisualizer.shuffleEnabled()) Delays.sleep(2);
}
}
*/
/*
int j = 0, k = currentLen;
Expand Down

0 comments on commit e11852c

Please sign in to comment.