EloDivision class created.

EloManager can now calculate division ranking (EloDivision can also do this once we are ready for it to)
This commit is contained in:
Joseph Prezioso Jr 2016-03-29 13:49:59 -04:00
parent 38a079846d
commit f496392c5a
3 changed files with 123 additions and 6 deletions

View File

@ -0,0 +1,55 @@
package mineplex.core.elo;
import org.bukkit.Material;
import org.bukkit.material.MaterialData;
public class EloDivision
{
private byte _divisionPercentile;
private String _divisionName;
//If I understand MaterialData objects correctly,
private Material _divisionMaterial;
private byte _divisionMaterialValue;
private MaterialData _divisionMaterialData;
public EloDivision(byte divPercent)
{
// TODO Auto-generated constructor stub
_divisionPercentile = divPercent;
_divisionName = CalculateDivision(divPercent);
}
public String CalculateDivision(double divPercent)
{
if (divPercent == 100) return "Diamond";
if (divPercent <= 99 && divPercent >= 81) return "Emerald";
if (divPercent <= 80 && divPercent >= 61) return "Lapis";
if (divPercent <= 60 && divPercent >= 41) return "Gold";
if (divPercent <= 40 && divPercent >= 21) return "Iron";
//if none of the above are true, a player is in the bottom 20%
return "Coal";
}
@SuppressWarnings("deprecation")
//method to set icon's material(since it will change with player's ELO)
public void setDivisionIcon(Material divMat, byte divData)
{
_divisionMaterial = divMat;
_divisionMaterialValue = divData;
_divisionMaterialData = new MaterialData(_divisionMaterial, _divisionMaterialValue);
}
public MaterialData getMaterialData()
{
return _divisionMaterialData;
}
public String getDivisionName()
{
return _divisionName;
}
}

View File

@ -3,6 +3,7 @@ package mineplex.core.elo;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.UUID;
import mineplex.core.MiniDbClientPlugin;
@ -50,23 +51,48 @@ public class EloManager extends MiniDbClientPlugin<EloClientData>
//get a player's Division
public String getPlayerDivision(UUID uuid, String gameType)
{
String updatedDivision = "";
//get playerElo for gametype (need to store this to check it against other Elo's)
//get playerElo for gameType (need to store this to check it against other Elo's)
int playerElo = getElo(uuid, gameType);
//this list will be filled with ELO's from other players (but only for the same game type
ArrayList otherElos = new ArrayList();
ArrayList<Integer> allElos = new ArrayList<Integer>();
for(int i = 0; i < _playerElos.size(); i++)
{
//we're only concerned with this Game Type
if(_playerElos.containsKey(gameType))
{
//add elo's to the list
allElos.add(_playerElos.get(uuid.toString()).get(gameType));
}
}
//sort list of Elos (needed for percentile calculations)
Collections.sort(allElos);
return updatedDivision;
//Calculate how much going up one spot is worth
double individualValue = (100/allElos.size());
/* lastIndexOf gets the last instance of player's Elo (possibly relevant near the top/bottom of divisions?)
* Consequently, it should be easier for rank to go up than down.
* To make it easier to go down in rank than up, use of Indexof is recommended.
*/
double percentile = allElos.lastIndexOf(playerElo) * individualValue;
return CalculateDivision(percentile);
}
//CalculateDivision copied from EloDivision for testing purposes
//will remove/alter one or both of them as needed
public String CalculateDivision(double divPercent)
{
if (divPercent == 100) return "Diamond";
if (divPercent <= 99 && divPercent >= 81) return "Emerald";
if (divPercent <= 80 && divPercent >= 61) return "Lapis";
if (divPercent <= 60 && divPercent >= 41) return "Gold";
if (divPercent <= 40 && divPercent >= 21) return "Iron";
//if none of the above are true, a player is in the bottom 20%
return "Coal";
}
public EloTeam getNewRatings(EloTeam teamA, EloTeam teamB, GameResult result)

View File

@ -0,0 +1,36 @@
package mineplex.core.elo;
public class EloSettings {
private boolean _fullElo = false;
private boolean _backendElo = false;
private boolean _eloDisabled = true;
public EloSettings(int setElo)
{
switch(setElo)
{
case 0:
_fullElo = false;
_backendElo = false;
_eloDisabled = true;
break;
case 1:
_fullElo = true;
_backendElo = false;
_eloDisabled = false;
break;
case 2:
_fullElo = false;
_backendElo = true;
_eloDisabled = false;
break;
default:
_fullElo = false;
_backendElo = false;
_eloDisabled = true;
}
}
}