Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement distributePlayersPerTeam function #1

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.tiagofar78.prisonescape.game;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.bukkit.Bukkit;
Expand Down Expand Up @@ -103,29 +104,39 @@ private boolean isPlayerOnGame(String playerName) {
return false;
}

private void distributePlayersPerTeams() {
int preferPrisioner = 0;
int preferPolice = 0;
int noPreference = 0;
private void distributePlayersPerTeam() {
int requiredPrisioners = _settings.getRequiredPrisioners(_players.size());
int requiredOfficers = _settings.getRequiredOfficers(_players.size());
List<PrisonEscapePlayer> remainingPlayers = new ArrayList<>();

for (int i = 0; i < _players.size(); i++) {
TeamPreference preference = _players.get(i).getPreference();
if (preference == TeamPreference.POLICE) {
preferPolice++;
// Shuffle the list of players to assign randomly
Collections.shuffle(_players);

for (PrisonEscapePlayer player : _players) {
TeamPreference preference = player.getPreference();

if (preference == TeamPreference.POLICE && requiredOfficers != 0) {
_policeTeam.add(player); // Assign to police
requiredOfficers--;
} else if (preference == TeamPreference.PRISIONERS && requiredPrisioners != 0) {
_prisionersTeam.add(player); // Assing to prisioner
requiredPrisioners--;
} else {
remainingPlayers.add(player);
}
else if (preference == TeamPreference.PRISIONERS) {
preferPrisioner++;
}

// Assign the players with no preference and players that did not get their pick
for(PrisonEscapePlayer player : remainingPlayers) {
iquelli marked this conversation as resolved.
Show resolved Hide resolved
if (requiredPrisioners != 0) {
_prisionersTeam.add(player); // Assign to prisioner
requiredPrisioners--;
}
else if (preference == TeamPreference.RANDOM) {
noPreference++;
else {
_policeTeam.add(player); // Assign to poline
requiredOfficers--;
}
}

if (preferPrisioner <= _settings.getMaxPrisioners()) {
//TODO finish this method
}


}

// ########################################
Expand All @@ -137,7 +148,7 @@ private void startWaitingPhase() {
}

private void startOngoingPhase() {
distributePlayersPerTeams();
distributePlayersPerTeam();

_phase.next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ public PrisonEscapeTeam(String name) {
public String getName() {
return _name;
}

public void add(PrisonEscapePlayer player) {
iquelli marked this conversation as resolved.
Show resolved Hide resolved
_players.add(player);
}

public boolean isOnTeam(PrisonEscapePlayer player) {
return _players.contains(player);
Expand Down
17 changes: 10 additions & 7 deletions src/main/java/net/tiagofar78/prisonescape/game/Settings.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
package net.tiagofar78.prisonescape.game;

public class Settings {


private static final double PRISIONERS_RATIO = 0.64;
iquelli marked this conversation as resolved.
Show resolved Hide resolved
private static final double GUARDS_RATIO = 0.36;
iquelli marked this conversation as resolved.
Show resolved Hide resolved

public Settings() {

}
public int getMaxPrisioners() {
return 0; // TODO

public int getRequiredPrisioners(int numberOfPlayers) {
return (int) Math.round(numberOfPlayers * PRISIONERS_RATIO);
iquelli marked this conversation as resolved.
Show resolved Hide resolved
}
public int getMaxPoliceOfficers() {
return 0; // TODO

public int getRequiredOfficers(int numberOfPlayers) {
return (int) Math.round(numberOfPlayers * GUARDS_RATIO);
iquelli marked this conversation as resolved.
Show resolved Hide resolved
}

public int getSecondsInSolitary() {
Expand Down