Created
January 8, 2019 22:13
-
-
Save dwbapst/d1e878ecad766be2ecd1f0b308e96ab8 to your computer and use it in GitHub Desktop.
Code for maybe getting best combo of IVs/level for each pokemon, given CP limitations of the three leagues 01-08-19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setwd("D:\\dave\\fun\\Pokemon\\analyses of pokemon stuff\\PvP Analysis") | |
# CP_multiplier | |
CP_multiplier<-c(0.094, 0.135137432, 0.16639787, 0.192650919, 0.21573247, 0.236572661, | |
0.25572005, 0.273530381, 0.29024988, 0.306057377, 0.3210876, 0.335445036, 0.34921268, | |
0.362457751, 0.37523559, 0.387592406, 0.39956728, 0.411193551, 0.42250001, 0.432926419, | |
0.44310755, 0.453059958, 0.46279839, 0.472336083, 0.48168495, 0.4908558, 0.49985844, | |
0.508701765, 0.51739395, 0.525942511, 0.53435433, 0.542635767, 0.55079269, 0.558830576, | |
0.56675452, 0.574569153, 0.58227891, 0.589887917, 0.59740001, 0.604818814, 0.61215729, | |
0.619399365, 0.62656713, 0.633644533, 0.64065295, 0.647576426, 0.65443563, 0.661214806, | |
0.667934, 0.674577537, 0.68116492, 0.687680648, 0.69414365, 0.700538673, 0.70688421, | |
0.713164996, 0.71939909, 0.725571552, 0.7317, 0.734741009, 0.73776948, 0.740785574, | |
0.74378943, 0.746781211, 0.74976104, 0.752729087, 0.75568551, 0.758630378, 0.76156384, | |
0.764486065, 0.76739717, 0.770297266, 0.7731865, 0.776064962, 0.77893275, 0.781790055, | |
0.78463697, 0.787473578, 0.79030001) | |
names(CP_multiplier)<-seq(1,40,by=0.5) | |
getMaxProdCPLimit <- function(CPlimit, | |
CP, statProduct, Lev_IV, | |
CP_multiplier, baseStats | |
){ | |
######################################## | |
whichUnder <- which(CP <= CPlimit) | |
whichUnder <- whichUnder[ | |
max(statProduct[whichUnder]) == statProduct[whichUnder]] | |
# and just in case there are two with same stat product | |
# pick the one with the highest CP | |
# and if that doesn't work, pick the first one listed | |
whichUnder <- whichUnder[which.max(CP[whichUnder])][1] | |
Lev_IV_best <- Lev_IV[whichUnder,] | |
CPM <- CP_multiplier[Lev_IV_best[1] == names(CP_multiplier)] | |
coreSta <- (baseStats[1] + Lev_IV_best[2]) * CPM | |
coreAtk <- (baseStats[2] + Lev_IV_best[3]) * CPM | |
coreDef <- (baseStats[3] + Lev_IV_best[4]) * CPM | |
result <- data.frame( | |
CPbest = CP[whichUnder], | |
statProdBest = statProduct[whichUnder], | |
bestLevel = Lev_IV_best[1], | |
bestAtkIV = Lev_IV_best[3], | |
bestDefIV = Lev_IV_best[4], | |
bestStaIV = Lev_IV_best[2], | |
bestAtkInd = coreAtk, | |
bestDefInd = coreDef, | |
bestStaInd = coreSta | |
) | |
return(result) | |
} | |
IVfloor <- 0 | |
minLevel <- 1 | |
maxLevel <- 40 | |
Lev_IV<-expand.grid(level=seq(minLevel,maxLevel,by=0.5), | |
sta=IVfloor:15, atk=IVfloor:15, def=IVfloor:15) | |
##################### | |
# get base stats for each species | |
baseStatsAll <- read.csv("pokemon_base_stats_01-18-2019.csv") | |
GreatLeague <- matrix(NA,nrow(baseStatsAll),8) | |
colnames(GreatLeague) <- c("CPbest", "statProdBest", | |
"bestAtkIV", "bestDefIV", "bestStaIV", | |
"bestAtkInd", "bestDefInd", "bestStaInd") | |
UltraLeague <- MasterLeague <- GreatLeague | |
colnames(GreatLeague) <- paste0("Great.",colnames(GreatLeague)) | |
colnames(UltraLeague) <- paste0("Ultra.",colnames(UltraLeague)) | |
colnames(MasterLeague) <- paste0("Master.",colnames(MasterLeague)) | |
for (i in 1:nrow(baseStatsAll)){ | |
baseStats <- baseStatsAll[i,2:4] | |
# | |
CP <- unlist(apply(Lev_IV,1,function(x){ | |
staInd<-baseStats[1]+x[2] | |
atkInd<-baseStats[2]+x[3] | |
defInd<-baseStats[3]+x[4] | |
CPM<-CP_multiplier[x[1]==names(CP_multiplier)] | |
unname(floor((atkInd * defInd^0.5 * staInd^0.5 * CPM^2) / 10)) | |
})) | |
statProduct <- unlist(apply(Lev_IV,1,function(x){ | |
staInd<-baseStats[1]+x[2] | |
atkInd<-baseStats[2]+x[3] | |
defInd<-baseStats[3]+x[4] | |
unname(staInd * atkInd * defInd) | |
})) | |
############### | |
# find the one with the best statProduct at/under CP 1500 | |
GreatLeague[i,] <- getMaxProdCPLimit(CPlimit = 1500, | |
CP = CP, statProduct = statProduct, | |
Lev_IV = Lev_IV, CP_multiplier = CP_multiplier, | |
baseStats = baseStats) | |
# find the one with the best statProduct at/under CP 1500 | |
UltraLeague[i,] <- getMaxProdCPLimit(CPlimit = 2500, | |
CP = CP, statProduct = statProduct, | |
Lev_IV = Lev_IV, CP_multiplier = CP_multiplier, | |
baseStats = baseStats) | |
# find the one with the best statProduct at any CP | |
MasterLeague[i,] <- getMaxProdCPLimit(CPlimit = Inf, | |
CP = CP, statProduct = statProduct, | |
Lev_IV = Lev_IV, CP_multiplier = CP_multiplier, | |
baseStats = baseStats) | |
print(i/nrow(baseStatsAll)) | |
} | |
idealLeagueCPs <- cbind(baseStatsAll,GreatLeague,UltraLeague,MasterLeague) | |
write.csv(idealLeagueCPs, file = "idealLeagueCPs_stats_01-08-19.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment