Skip to content

Commit

Permalink
Use compareBeats instead of reimpelement #307 (#308)
Browse files Browse the repository at this point in the history
* Use compareBeats instead of reimpelement #307
  • Loading branch information
valentinbujdoso authored and magwas committed Apr 11, 2019
1 parent 1a5b5ed commit 9d5b181
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 25 deletions.
28 changes: 8 additions & 20 deletions src/main/java/org/rulez/demokracia/pdengine/Normalizable.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,26 @@

import java.util.Collection;

import org.rulez.demokracia.pdengine.BeatTable.Direction;
import org.rulez.demokracia.pdengine.dataobjects.Pair;

public interface Normalizable extends ContainingBeats {

long serialVersionUID = 1L;

default void normalize() {
for (String key : getKeyCollection()) {
setElement(key, key, new Pair(0, 0));
}

Collection<String> keys = getKeyCollection();

for (String key1 : keys) {
for (String key2 : keys) {
int key1Win = beatInformation(key1, key2, Direction.DIRECTION_FORWARD);
int key2Win = beatInformation(key2, key1, Direction.DIRECTION_FORWARD);

if (key1Win > key2Win)
Pair beats1 = getPair(key1, key2);
Pair beats2 = getPair(key2, key1);
Pair pair = compareBeats(beats1, beats2);

if(pair.equals(beats1))
setElement(key2, key1, new Pair(0, 0));
if (key1Win == key2Win) {
int key1Los = beatInformation(key1, key2, Direction.DIRECTION_BACKWARD);
int key2Los = beatInformation(key2, key1, Direction.DIRECTION_BACKWARD);

if (key1Los == key2Los) {
setElement(key2, key1, new Pair(0, 0));
setElement(key1, key2, new Pair(0, 0));
}
}
if(pair.equals(beats2))
setElement(key1, key2, new Pair(0, 0));
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ protected void createNewBeatTableWithComplexData() {
}

protected void createNewBeatTableWithEqualData() {
List<String> list = new ArrayList<String>();
list.add(choice1);
list.add(choice2);
list.add(choice3);
beatTable = new BeatTable(list);
createNewBeatTableWithData();
beatTable.setElement(choice1, choice2, new Pair(2, 2));
beatTable.setElement(choice2, choice1, new Pair(2, 2));
beatTable.setElement(choice1, choice3, new Pair(4, 1));
Expand Down

0 comments on commit 9d5b181

Please sign in to comment.