Skip to content

Commit

Permalink
corrected player elimination resultPosition
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomis committed Aug 23, 2015
1 parent 2910928 commit b9b5944
Showing 1 changed file with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package com.cardshifter.modapi.base;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.*;

public class PlayerComponent extends Component {

Expand Down Expand Up @@ -48,22 +46,24 @@ private void eliminate(boolean winner) {

// if no one else has been eliminated, the player is at 1st place. Because the player itself has not been eliminated, it should get increased below.
int playerResultPosition = winner ? 0 : players.size() + 1;

boolean posTaken = false;

Set<Integer> takenPositions = new HashSet<>();
for (Entity pp : players) {
PlayerComponent playerComponent = pp.getComponent(PlayerComponent.class);
if (playerComponent.isEliminated()) {
takenPositions.add(playerComponent.getResultPosition());
}
}

boolean posTaken;
do {
posTaken = false;
playerResultPosition += winner ? -1 : +1;
for (Entity pp : players) {
PlayerComponent playerComponent = pp.getComponent(PlayerComponent.class);
if (playerComponent.isEliminated() && playerComponent.getResultPosition() == playerResultPosition) {
posTaken = true;
break;
}
}
}
while (posTaken);

this.eliminate(winner, playerResultPosition);
playerResultPosition += winner ? +1 : -1;
posTaken = takenPositions.contains(playerResultPosition);
} while (posTaken);

System.out.println("eliminating " + this + " as " + winner + ": taken positions is " + takenPositions + " ending up at " + playerResultPosition);

this.eliminate(winner, playerResultPosition);
}

private void eliminate(boolean winner, int resultPosition) {
Expand Down

0 comments on commit b9b5944

Please sign in to comment.