Skip to content

Instantly share code, notes, and snippets.

@Coldsp33d
Created March 24, 2023 10:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Coldsp33d/18f65a990069ae98744b8cd829e70ebb to your computer and use it in GitHub Desktop.
Save Coldsp33d/18f65a990069ae98744b8cd829e70ebb to your computer and use it in GitHub Desktop.
Calculate optimal battles per training account to achieve perfect exp on TPPCRPG. Assumes all exp values in wiki are accurate
import requests
import pandas as pd
import numpy as np
import datetime
import pytz
def is_east_coast_daytime():
# Get the current time in the Eastern timezone
eastern = pytz.timezone('US/Eastern')
current_time = datetime.datetime.now(eastern)
# Check if the current time is between 6AM and 6PM EST
return current_time.hour >= 6 and current_time.hour < 18
def find_optimal_trainers(current_exp, desired_exp, table, use_exp_night=False, include_id=False):
"""
Finds the optimal trainers to fight and the amount of times to fight them to get as close to desired_exp as possible
without exceeding it, given starting exp current_exp and desired exp desired_exp, and a table of trainers and their exp gains.
The table has the following columns: "name", "expDay" (i.e., exp earned per battle during the day), and "expNight"
(i.e., exp earned per battled during the night). If use_exp_night is True, uses only expNight to calculate the final result;
otherwise, use only expDay.
Returns a dictionary of trainer names and non-zero battle counts.
"""
# Compute the exp difference and filter out trainers with negative exp gains
exp_gain = np.where(use_exp_night, table['expNight'], table['expDay']) # Use expNight if use_exp_night is True; expDay otherwise
table_filtered = table.loc[exp_gain <= (desired_exp - current_exp)].copy() # Filter out trainers with negative exp gains
# Sort the table by exp gains in descending order
exp_gain_sorted = np.where(use_exp_night, table_filtered['expNight'], table_filtered['expDay'])
table_sorted = table_filtered.iloc[np.argsort(exp_gain_sorted)[::-1]]
# Initialize the result dictionary and compute the remaining exp to gain
trainers = {}
remaining_exp = desired_exp - current_exp
current_exp2 = current_exp
# Iterate over the trainers in the sorted table and compute the number of battles for each
for index, row in table_sorted.iterrows():
exp_gain = row['expNight'] if use_exp_night else row['expDay']
exp_diff = exp_gain - remaining_exp
if exp_diff > 0:
continue
num_battles = int(remaining_exp / exp_gain)
if num_battles > 0:
trainers[row['name'] + (f' ({row["number"]})' if include_id else '')] = num_battles
remaining_exp -= num_battles * exp_gain
current_exp2 += num_battles * exp_gain
if remaining_exp <= 0:
break
return trainers
def get_perfect_exp(level, ceil=True):
if ceil:
return ((level + 1) ** 3) - 1
return (level ** 3) + 1
def main():
X = 15_606_381_712
Y = get_perfect_exp(2499) # perfect exp for 2499
disable_gratzmatt_gym = True
# Define the URL to scrape
url = 'https://wiki.tppc.info/Training_Accounts'
# Make a GET request to the URL and get the response
response = requests.get(url)
# Use pandas to read the HTML table from the response content
table_list = pd.read_html(response.text)
# Extract the first table from the list (which should be the training accounts table)
table = table_list[1]
# Print the table data to the console
print(table)
# Drop the unwanted columns by their column names
table = table[['Trainer Name', 'Number', 'Exp. (Day)', 'Exp. (Night)']]
if disable_gratzmatt_gym:
table = table.iloc[:-1]
# Rename the remaining columns
table.columns = ['name', 'number', 'expDay', 'expNight']
table = table.append({'name': 'illuzion lv5 MILOTIC ONLY', 'number': 24659, 'expDay': 300, 'expNight' : 300}, ignore_index=True)
table = table.append({'name': 'shedinja SINGLE', 'number': 2380615, 'expDay': 3, 'expNight' : 3}, ignore_index=True)
table = table.append({'name': 'shedinja SINGLE EXP SHARE', 'number': 2380615, 'expDay': 1, 'expNight' : 1}, ignore_index=True)
trainers = find_optimal_trainers(X, Y, table, use_exp_night=not is_east_coast_daytime(), include_id=True)
print(trainers)
def test():
current_exp = 1
desired_exp = 103
data = {'name': ['trainerA', 'trainerB', 'trainerC'],
'expDay': [1, 10, 100],
'expNight': [1, 10, 100]}
table = pd.DataFrame(data)
# Example usage
trainers = find_optimal_trainers(current_exp, desired_exp, table, use_exp_night=True)
if trainers != {'trainerC': 1, 'trainerA': 2}: # replace with assert. Too lazy
raise Exception
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment