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

Improve IV Calculation #260

Merged
merged 2 commits into from
Aug 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions src/me/corriekay/pokegoutil/utils/ConfigKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public enum ConfigKey {
TRANSFER_AFTER_EVOLVE("settings.transferAfterEvolve", false, Boolean.class),
SHOW_BULK_POPUP("settings.popupAfterBulk", true, Boolean.class),
INCLUDE_FAMILY("settings.includeFamily", true, Boolean.class),
ALTERNATIVE_IV_CALCULATION("settings.alternativeIvCalculation", false, Boolean.class),

LANGUAGE("options.lang", "en", String.class),
FONT_SIZE("options.fontsize", 0, Integer.class),
Expand Down
12 changes: 3 additions & 9 deletions src/me/corriekay/pokegoutil/utils/pokemon/PokeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,7 @@ public String get(Pokemon p) {
IV_RATING("IV Rating in two digits (XX for 100%)") {
@Override
public String get(Pokemon p) {
return Utilities.percentageWithTwoCharacters(p.getIvRatio());
}
},
IV_RATING_LONG("IV Rating") {
@Override
public String get(Pokemon p) {
return String.valueOf(Utilities.percentage(p.getIvRatio()));
return Utilities.percentageWithTwoCharacters(PokemonUtils.ivRating(p));
}
},
IV_HEX("IV Values in hexadecimal, like \"9FA\" (F = 15)") {
Expand Down Expand Up @@ -350,13 +344,13 @@ public String get(Pokemon p) {
DPS_1_RATING("Rating for Move 1 (Percentage of max possible) in two digits (XX for 100%)") {
@Override
public String get(Pokemon p) {
return Utilities.percentageWithTwoCharacters(PokemonUtils.moveRating(p, true));
return PokemonUtils.moveRating(p, true);
}
},
DPS_2_RATING("Rating for Move 2 (Percentage of max possible) in two digits (XX for 100%)") {
@Override
public String get(Pokemon p) {
return Utilities.percentageWithTwoCharacters(PokemonUtils.moveRating(p, false));
return PokemonUtils.moveRating(p, false);
}
},
TYPE_1("Pokémon Type 1 abbreviated (Ghost = Gh)") {
Expand Down
38 changes: 26 additions & 12 deletions src/me/corriekay/pokegoutil/utils/pokemon/PokemonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import POGOProtos.Enums.PokemonMoveOuterClass.PokemonMove;
import com.pokegoapi.api.player.Team;
import com.pokegoapi.api.pokemon.*;
import me.corriekay.pokegoutil.utils.ConfigKey;
import me.corriekay.pokegoutil.utils.ConfigNew;
import me.corriekay.pokegoutil.utils.Utilities;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -13,6 +15,18 @@ private PokemonUtils() { /* Prevent initializing this class */ }
public static final long GYM_OFFENSE_MAX = 510_419L;
public static final long GYM_DEFENSE_MAX = 9_530_079_725L;

public static double ivRating(Pokemon p) {
if (ConfigNew.getConfig().getBool(ConfigKey.ALTERNATIVE_IV_CALCULATION)) {
PokemonMeta meta = p.getMeta();
double cpMax = (meta.getBaseAttack() + 15) * Math.pow(meta.getBaseDefense() + 15, 0.5) * Math.pow(meta.getBaseStamina() + 15, 0.5);
double cpMin = meta.getBaseAttack() * Math.pow(meta.getBaseDefense(), 0.5) * Math.pow(meta.getBaseStamina(), 0.5);
double cpIv = (meta.getBaseAttack() + p.getIndividualAttack()) * Math.pow(meta.getBaseDefense() + p.getIndividualDefense(), 0.5) * Math.pow(meta.getBaseStamina() + p.getIndividualStamina(), 0.5);
return (cpIv - cpMin) / (cpMax - cpMin);
} else {
return (p.getIndividualAttack() + p.getIndividualDefense() + p.getIndividualStamina()) / 45.0;
}
}

public static String convertTeamColorToName(int teamValue) {
Team[] teams = Team.values();

Expand All @@ -24,7 +38,7 @@ public static String convertTeamColorToName(int teamValue) {
return "UNKNOWN_TEAM";
}

public static double moveRating(Pokemon p, boolean primary) {
public static String moveRating(Pokemon p, boolean primary) {
PokemonMeta pMeta = p.getMeta();

double highestDps = 0;
Expand All @@ -36,7 +50,7 @@ public static double moveRating(Pokemon p, boolean primary) {

// Now rate it
double currentDps = dpsForMove(p, primary);
return Utilities.percentage(currentDps / highestDps);
return Utilities.percentageWithTwoCharacters(currentDps, highestDps);
}

public static double dpsForMove(Pokemon p, boolean primary) {
Expand Down Expand Up @@ -65,8 +79,8 @@ private static double dpsForMove(Pokemon p, PokemonMove move, boolean primary) {
*
* @param p A Pokemon object
* @return Rating of a Pokemon's overall attacking power considering damage, health & defense
* @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @see i607ch00
* @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @link i607ch00
*/
public static long duelAbility(Pokemon p) {
return PokemonUtils.gymOffense(p) * PokemonUtils.tankiness(p);
Expand All @@ -78,8 +92,8 @@ public static long duelAbility(Pokemon p) {
*
* @param p A Pokemon object
* @return Rating of a Pokemon's pure offensive ability over time considering move set
* @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @see i607ch00
* @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @link i607ch00
*/
public static long gymOffense(Pokemon p) {
double gymOffense = Math.max(PokemonUtils.dpsForMove(p, true) * 100, PokemonUtils.weaveDPS(p, 0)) * (p.getMeta().getBaseAttack() + p.getIndividualAttack());
Expand All @@ -92,8 +106,8 @@ public static long gymOffense(Pokemon p) {
*
* @param p A Pokemon object
* @return Rating of a Pokemon's AI controlled gym defense over time considering move set
* @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @see i607ch00
* @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @link i607ch00
*/
public static long gymDefense(Pokemon p) {
double gymDefense = PokemonUtils.weaveDPS(p, 2000) * (p.getMeta().getBaseAttack() + p.getIndividualAttack()) * PokemonUtils.tankiness(p);
Expand All @@ -108,8 +122,8 @@ public static long gymDefense(Pokemon p) {
*
* @param p A Pokemon object
* @return Rating of a Pokemon's tankiness :)
* @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @see i607ch00
* @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @link i607ch00
*/
public static long tankiness(Pokemon p) {
return (p.getMeta().getBaseStamina() + p.getIndividualStamina()) * (p.getMeta().getBaseDefense() + p.getIndividualDefense());
Expand All @@ -124,8 +138,8 @@ public static long tankiness(Pokemon p) {
* @param p A Pokemon object
* @param additionalDelay Allow a delay in milliseconds for gym offense (0ms) vs gym defense (2000ms)
* @return Damage over 100 seconds for a Pokemon's moveset
* @see https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @see i607ch00
* @link https://www.reddit.com/r/TheSilphRoad/comments/4vcobt/posthotfix_pokemon_go_full_moveset_rankings/
* @link i607ch00
*/
public static double weaveDPS(Pokemon p, Integer additionalDelay) {
double critDamageBonus = 0.5;
Expand Down
17 changes: 15 additions & 2 deletions src/me/corriekay/pokegoutil/windows/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class MenuBar extends JMenuBar {
private final PokemonGo go;
private ConfigNew config = ConfigNew.getConfig();

public MenuBar(PokemonGo go) {
public MenuBar(PokemonGo go, PokemonTab pokemonTab) {
this.go = go;

JMenu file, settings, help;
Expand Down Expand Up @@ -63,9 +63,22 @@ public MenuBar(PokemonGo go) {

JCheckBoxMenuItem includeFamily = new JCheckBoxMenuItem("Include Family On Searchbar");
includeFamily.setSelected(config.getBool(ConfigKey.INCLUDE_FAMILY));
includeFamily.addItemListener(e -> config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected()));
includeFamily.addItemListener(e -> {
config.setBool(ConfigKey.INCLUDE_FAMILY, includeFamily.isSelected());
if (!pokemonTab.getSelectedPokemon().isEmpty()) {
SwingUtilities.invokeLater(pokemonTab::refreshList);
}
});
settings.add(includeFamily);

JCheckBoxMenuItem alternativeIVCalculation = new JCheckBoxMenuItem("Use Alternative IV Calculation (weighted stats)");
alternativeIVCalculation.setSelected(config.getBool(ConfigKey.ALTERNATIVE_IV_CALCULATION));
alternativeIVCalculation.addItemListener(e -> {
config.setBool(ConfigKey.ALTERNATIVE_IV_CALCULATION, alternativeIVCalculation.isSelected());
SwingUtilities.invokeLater(pokemonTab::refreshList);
});
settings.add(alternativeIVCalculation);

add(settings);

// Help menu
Expand Down
5 changes: 3 additions & 2 deletions src/me/corriekay/pokegoutil/windows/PokemonGoMainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public void componentMoved(ComponentEvent e) {
int posy = config.getInt(ConfigKey.WINDOW_POS_Y, pt.y);
setLocation(posx, posy);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setJMenuBar(new MenuBar(go));
tab.add("Pokémon", new PokemonTab(go));
PokemonTab pokemonTab = new PokemonTab(go);
setJMenuBar(new MenuBar(go, pokemonTab));
tab.add("Pokémon", pokemonTab);

add(tab, BorderLayout.CENTER);

Expand Down
35 changes: 20 additions & 15 deletions src/me/corriekay/pokegoutil/windows/PokemonTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ private JPanel _buildPanelForOperation(String operation, ArrayList<Pokemon> poke

pokes.forEach(p -> {
String str = PokeHandler.getLocalPokeName(p) + " - CP: " + p.getCp() + ", IV: "
+ Utilities.percentage(p.getIvRatio()) + "%";
+ Utilities.percentageWithTwoCharacters(PokemonUtils.ivRating(p)) + "%";
switch (operation) {
case "Evolve":
str += " Cost: " + p.getCandiesToEvolve();
Expand All @@ -597,7 +597,7 @@ private JPanel _buildPanelForOperation(String operation, ArrayList<Pokemon> poke
return panel;
}

private ArrayList<Pokemon> getSelectedPokemon() {
public ArrayList<Pokemon> getSelectedPokemon() {
ArrayList<Pokemon> pokes = new ArrayList<>();
PokemonTableModel model = (PokemonTableModel) pt.getModel();
for (int i : pt.getSelectedRows()) {
Expand All @@ -609,7 +609,7 @@ private ArrayList<Pokemon> getSelectedPokemon() {
return pokes;
}

private void refreshList() {
public void refreshList() {
List<Pokemon> pokes = new ArrayList<>();
String search = searchBar.getText().replaceAll(" ", "").replaceAll("_", "").replaceAll("snek", "ekans").toLowerCase();
String[] terms = search.split(";");
Expand Down Expand Up @@ -700,7 +700,7 @@ private static class PokemonTable extends JTable {
* 0 String - Nickname
* 1 Integer - Pokemon Number
* 2 String - Type / Pokemon
* 3 Double - IV %
* 3 String(Percentage) - IV Rating
* 4 Double - Level
* 5 Integer - Attack
* 6 Integer - Defense
Expand All @@ -724,8 +724,8 @@ private static class PokemonTable extends JTable {
* 24 Long - duelAbility
* 25 Integer - gymOffense
* 26 Integer - gymDefense
* 27 Double - Move 1 Rating
* 28 Double - Move 2 Rating
* 27 String(Percentage) - Move 1 Rating
* 28 String(Percentage) - Move 2 Rating
*/
ConfigNew config = ConfigNew.getConfig();

Expand Down Expand Up @@ -753,7 +753,7 @@ private void constructNewTableModel(PokemonGo go, List<Pokemon> pokes) {
PokemonTableModel ptm = new PokemonTableModel(go, pokes, this);
setModel(ptm);
TableRowSorter<TableModel> trs = new TableRowSorter<>(getModel());
Comparator<Integer> c = (i1, i2) -> Math.round(i1 - i2);
Comparator<Integer> c = (i1, i2) -> i1 - i2;
Comparator<Double> cDouble = (d1, d2) -> (int) (d1 - d2);
Comparator<String> cDate = (date1, date2) -> DateHelper.fromString(date1).compareTo(DateHelper.fromString(date2));
Comparator<String> cNullableInt = (s1, s2) -> {
Expand All @@ -763,9 +763,14 @@ private void constructNewTableModel(PokemonGo go, List<Pokemon> pokes) {
s2 = "0";
return Integer.parseInt(s1) - Integer.parseInt(s2);
};
Comparator<String> cPercentageWithTwoCharacters = (s1, s2) -> {
int i1 = ("XX".equals(s1)) ? 100 : Integer.parseInt(s1);
int i2 = ("XX".equals(s2)) ? 100 : Integer.parseInt(s2);
return i1 - i2;
};
Comparator<Long> cLong = (l1, l2) -> l2.compareTo(l1);
trs.setComparator(0, c);
trs.setComparator(3, cDouble);
trs.setComparator(3, cPercentageWithTwoCharacters);
trs.setComparator(4, cDouble);
trs.setComparator(5, c);
trs.setComparator(6, c);
Expand All @@ -783,8 +788,8 @@ private void constructNewTableModel(PokemonGo go, List<Pokemon> pokes) {
trs.setComparator(24, cLong);
trs.setComparator(25, cLong);
trs.setComparator(26, cLong);
trs.setComparator(27, cDouble);
trs.setComparator(28, cDouble);
trs.setComparator(27, cPercentageWithTwoCharacters);
trs.setComparator(28, cPercentageWithTwoCharacters);
setRowSorter(trs);
List<SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new SortKey(sortColIndex1, sortOrder1));
Expand Down Expand Up @@ -827,9 +832,9 @@ private static class PokemonTableModel extends AbstractTableModel {
private final ArrayList<Pokemon> pokeCol = new ArrayList<>();
private final ArrayList<Integer> numIdCol = new ArrayList<>();//0
private final ArrayList<String> nickCol = new ArrayList<>(),//1
speciesCol = new ArrayList<>();//2
private final ArrayList<Double> ivCol = new ArrayList<>(),//3
levelCol = new ArrayList<>();//4
speciesCol = new ArrayList<>(),//2
ivCol = new ArrayList<>();//3
private final ArrayList<Double> levelCol = new ArrayList<>();//4
private final ArrayList<Integer> atkCol = new ArrayList<>(),//5
defCol = new ArrayList<>(),//6
stamCol = new ArrayList<>();//7
Expand All @@ -852,7 +857,7 @@ private static class PokemonTableModel extends AbstractTableModel {
private final ArrayList<Long> duelAbilityCol = new ArrayList<>();//24
private final ArrayList<Long> gymOffenseCol = new ArrayList<>();//25
private final ArrayList<Long> gymDefenseCol = new ArrayList<>();//26
private final ArrayList<Double> move1RatingCol = new ArrayList<>(),//27
private final ArrayList<String> move1RatingCol = new ArrayList<>(),//27
move2RatingCol = new ArrayList<>();//28

@Deprecated
Expand All @@ -866,7 +871,7 @@ private PokemonTableModel(PokemonGo go, List<Pokemon> pokes, PokemonTable pt) {
speciesCol.add(i.getValue(),
PokeHandler.getLocalPokeName(p));
levelCol.add(i.getValue(), (double) p.getLevel());
ivCol.add(i.getValue(), Utilities.percentage(p.getIvRatio()));
ivCol.add(i.getValue(), Utilities.percentageWithTwoCharacters(PokemonUtils.ivRating(p)));
cpCol.add(i.getValue(), p.getCp());
atkCol.add(i.getValue(), p.getIndividualAttack());
defCol.add(i.getValue(), p.getIndividualDefense());
Expand Down