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

Add support for counting Tera Types #1

Merged
merged 8 commits into from
Aug 26, 2024
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
6 changes: 6 additions & 0 deletions stats/src/display.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export interface DisplayUsageStatistics {

abilities: {[name: string]: number};
items: {[name: string]: number};
teraTypes: {[name: string]: number};
stats: {[stats: string]: number};
moves: {[name: string]: number};
teammates: {[name: string]: number};
Expand Down Expand Up @@ -65,6 +66,7 @@ export interface DetailedMovesetStatistics {
'Viability Ceiling': [number, number, number, number];
Abilities: {[ability: string]: number};
Items: {[item: string]: number};
'Tera Types': {[teraType: string]: number};
Spreads: {[spread: string]: number};
Happiness?: {[happiness: string]: number};
Moves: {[move: string]: number};
Expand Down Expand Up @@ -127,6 +129,8 @@ export const Display = new class {
const o = gen.items.get(item);
return (o?.name) ?? item;
}),
teraTypes: toDisplayObject(p.teraTypes, p.raw.weight,
teraType => teraType[0].toUpperCase() + teraType.slice(1)),
stats: toDisplayObject(p.stats, p.raw.weight),
moves: toDisplayObject(p.moves, p.raw.weight, move => {
if (move === '') return 'Nothing';
Expand Down Expand Up @@ -239,6 +243,8 @@ export const Display = new class {
const o = gen.items.get(item);
return (o?.name) ?? item;
}),
teraTypes: toDisplayObject(p['Tera Types'], rawWeight,
teraType => teraType[0].toUpperCase() + teraType.slice(1)),
happinesses: p.Happiness ? toDisplayObject(p.Happiness, rawWeight) : undefined,
spreads: toDisplayObject(p.Spreads, rawWeight),
moves: toDisplayObject(p.Moves, rawWeight, move => {
Expand Down
3 changes: 3 additions & 0 deletions stats/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ export const Parser = new class {
pokemon.ability = ability ? ability.id : 'unknown';
pokemon.species =
util.getSpecies(gen, util.fromAlias(pokemon.species || pokemon.name), legacy).id;
pokemon.teraType = pokemon.teraType || 'nothing';
if (mray && pokemon.species === 'rayquaza' && pokemon.moves.includes('dragonascent')) {
pokemon.species = 'rayquazamega';
pokemon.ability = 'deltastream';
Expand All @@ -340,6 +341,8 @@ export const Parser = new class {
const FORMES = new Set([
'greninjaash', 'zygardecomplete', 'mimikyubusted', 'mimikyubustedtotem',
'shayminsky', 'necrozmaultra', 'zaciancrowned', 'zamazentacrowned', 'palafinhero',
'ogerpontealtera', 'ogerponhearthflametera', 'ogerponwellspringtera',
'ogerponcornerstonetera', 'terapagosterastal', 'terapagosstellar',
]);

function identify(
Expand Down
15 changes: 15 additions & 0 deletions stats/src/reports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface MovesetStatistics {
'Viability Ceiling': [number, number, number, number];
Abilities: {[key: string]: number};
Items: {[key: string]: number};
'Tera Types': {[key: string]: number};
Spreads: {[key: string]: number};
Happiness: {[key: string]: number};
Moves: {[key: string]: number};
Expand Down Expand Up @@ -214,6 +215,18 @@ export const Reports = new class {
}
s += sep;
total = 0;
s += heading('Tera Types');
for (const teraType of Object.keys(moveset['Tera Types'])) {
if (total > 0.95) {
s += other(total);
break;
}
const weight = moveset['Tera Types'][teraType] / p.raw.weight;
s += display(teraType[0].toUpperCase() + teraType.slice(1), weight);
total += weight;
}
s += sep;
total = 0;
s += heading('Spreads');
for (const [i, spread] of Object.keys(moveset['Spreads']).entries()) {
if (total > 0.95 || i > 5) {
Expand Down Expand Up @@ -677,6 +690,8 @@ function toMovesetStatistics(gen: Generation, format: ID, stats: Statistics, min
const o = gen.items.get(item);
return (o?.name) ?? item;
}),
'Tera Types': util.toDisplayObject(pokemon.teraTypes,
teraType => teraType[0].toUpperCase() + teraType.slice(1)),
Spreads: util.toDisplayObject(pokemon.spreads),
Happiness: util.toDisplayObject(pokemon.happinesses),
Moves: util.toDisplayObject(pokemon.moves, move => {
Expand Down
6 changes: 6 additions & 0 deletions stats/src/stats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface UsageStatistics {
spreads: {[spread: string]: number};
stats: {[stats: string]: number};
moves: {[id: string /* ID */]: number};
teraTypes: {[id: string]: number};

raw: {weight: number; count: number};
saved: {weight: number; count: number};
Expand Down Expand Up @@ -334,6 +335,10 @@ function updateStats(
const i = p.items[set.item];
p.items[set.item] = (i || 0) + weights.m;

set.teraType = set.teraType || 'nothing';
const t = p.teraTypes[set.teraType];
p.teraTypes[set.teraType] = (t || 0) + weights.m;

const nature =
gen.natures.get(!legacy && NEUTRAL.has(set.nature) ? 'hardy' as ID : set.nature)!;
const baseStats = util.getSpecies(gen, pokemon.species, legacy).baseStats;
Expand Down Expand Up @@ -559,6 +564,7 @@ function newUsageStatistics() {
win: newUsage(),
abilities: {},
items: {},
teraTypes: {},
happinesses: {},
spreads: {},
stats: {},
Expand Down
249 changes: 249 additions & 0 deletions stats/src/test/testdata/logs/gen9ubers/log.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
{
"winner": "test-player-b",
"seed": [
37006,
50871,
4805,
27651
],
"turns": 3,
"p1": "test-player-a",
"p2": "test-player-b",
"p1team": [
{
"name": "Ogerpon",
"species": "Ogerpon-Cornerstone",
"item": "Cornerstone Mask",
"ability": "Sturdy",
"moves": [
"Ivy Cudgel",
"Swords Dance",
"Encore",
"Spiky Shield"
],
"nature": "Impish",
"evs": {
"hp": 252,
"atk": 4,
"def": 252,
"spa": 0,
"spd": 0,
"spe": 0
},
"gender": "F",
"happiness": 255,
"hpType": "Poison",
"pokeball": "",
"gigantamax": false,
"dynamaxLevel": 10,
"teraType": "Rock",
"level": 100,
"ivs": {
"hp": 31,
"atk": 31,
"def": 31,
"spa": 31,
"spd": 31,
"spe": 31
}
},
{
"name": "Kingambit",
"species": "Kingambit",
"item": "Heavy-Duty Boots",
"ability": "Supreme Overlord",
"moves": [
"Kowtow Cleave",
"Sucker Punch",
"Swords Dance",
"Low Kick"
],
"nature": "Adamant",
"evs": {
"hp": 252,
"atk": 252,
"def": 0,
"spa": 0,
"spd": 4,
"spe": 0
},
"gender": "F",
"happiness": 255,
"hpType": "",
"pokeball": "",
"gigantamax": false,
"dynamaxLevel": 10,
"teraType": "Fighting",
"level": 100,
"ivs": {
"hp": 31,
"atk": 31,
"def": 31,
"spa": 31,
"spd": 31,
"spe": 31
}
}
],
"p2team": [
{
"name": "Ogerpon",
"species": "Ogerpon",
"item": "Heavy-Duty Boots",
"ability": "Defiant",
"moves": [
"Ivy Cudgel",
"Swords Dance",
"Encore",
"Spiky Shield"
],
"nature": "Bold",
"evs": {
"hp": 252,
"atk": 4,
"def": 252,
"spa": 0,
"spd": 0,
"spe": 0
},
"gender": "F",
"happiness": 255,
"hpType": "Poison",
"pokeball": "",
"gigantamax": false,
"dynamaxLevel": 10,
"teraType": "Grass",
"level": 100,
"ivs": {
"hp": 31,
"atk": 31,
"def": 31,
"spa": 31,
"spd": 31,
"spe": 31
}
},
{
"name": "Kingambit",
"species": "Kingambit",
"item": "Heavy-Duty Boots",
"ability": "Supreme Overlord",
"moves": [
"Kowtow Cleave",
"Sucker Punch",
"Swords Dance",
"Iron Head"
],
"nature": "Adamant",
"evs": {
"hp": 252,
"atk": 252,
"def": 0,
"spa": 0,
"spd": 4,
"spe": 0
},
"gender": "M",
"happiness": 255,
"hpType": "",
"pokeball": "",
"gigantamax": false,
"dynamaxLevel": 10,
"teraType": "Fairy",
"level": 100,
"ivs": {
"hp": 31,
"atk": 31,
"def": 31,
"spa": 31,
"spd": 31,
"spe": 31
}
}
],
"score": [
2,
2
],
"inputLog": [
">version 3ecb8b760fc3ebeb9daddd16ea209d5e63ca4f4b",
">start {\"formatid\":\"gen9ubers\",\"seed\":[37006,50871,4805,27651]}",
">player p1 {\"name\":\"test-player-a\",\"avatar\":\"1\",\"team\":\"Ogerpon|OgerponCornerstone|CornerstoneMask|Sturdy|IvyCudgel,SwordsDance,Encore,SpikyShield|Impish|252,4,252,,,|F||||,Poison,,,,Rock]Kingambit||HeavyDutyBoots|SupremeOverlord|KowtowCleave,SuckerPunch,SwordsDance,LowKick|Adamant|252,252,,,4,|F||||,,,,,Fighting\",\"rating\":0}",
">player p2 {\"name\":\"test-player-b\",\"avatar\":\"1\",\"team\":\"Ogerpon||HeavyDutyBoots|Defiant|IvyCudgel,SwordsDance,Encore,SpikyShield|Bold|252,4,252,,,|F||||,Poison,,,,Grass]Kingambit||HeavyDutyBoots|SupremeOverlord|KowtowCleave,SuckerPunch,SwordsDance,IronHead|Adamant|252,252,,,4,|M||||,,,,,Fairy\",\"rating\":0}",
">p1 team 1, 2",
">p2 team 1, 2",
">p1 move ivycudgel",
">p2 move ivycudgel",
">p1 move spikyshield terastallize",
">p2 move ivycudgel terastallize",
">forcelose p1"
],
"log": [
"|j|☆test-player-a",
"|j|☆test-player-b",
"|t:|1724655277",
"|gametype|singles",
"|player|p1|test-player-a|1|",
"|player|p2|test-player-b|1|",
"|teamsize|p1|2",
"|teamsize|p2|2",
"|gen|9",
"|tier|[Gen 9] Ubers",
"|rule|Sleep Clause Mod: Limit one foe put to sleep",
"|rule|Species Clause: Limit one of each Pokémon",
"|rule|OHKO Clause: OHKO moves are banned",
"|rule|Evasion Items Clause: Evasion items are banned",
"|rule|Evasion Moves Clause: Evasion moves are banned",
"|rule|Endless Battle Clause: Forcing endless battles is banned",
"|rule|HP Percentage Mod: HP is shown in percentages",
"|clearpoke",
"|poke|p1|Ogerpon-Cornerstone, F|",
"|poke|p1|Kingambit, F|",
"|poke|p2|Ogerpon, F|",
"|poke|p2|Kingambit, M|",
"|teampreview",
"|",
"|t:|1724655281",
"|start",
"|switch|p1a: Ogerpon|Ogerpon-Cornerstone, F|364/364",
"|switch|p2a: Ogerpon|Ogerpon, F|364/364",
"|turn|1",
"|",
"|t:|1724655291",
"|move|p2a: Ogerpon|Ivy Cudgel|p1a: Ogerpon",
"|-damage|p1a: Ogerpon|262/364",
"|move|p1a: Ogerpon|Ivy Cudgel|p2a: Ogerpon|[anim] Ivy Cudgel Rock",
"|-damage|p2a: Ogerpon|219/364",
"|",
"|upkeep",
"|turn|2",
"|",
"|t:|1724655305",
"|-terastallize|p1a: Ogerpon|Rock",
"|detailschange|p1a: Ogerpon|Ogerpon-Cornerstone-Tera, F, tera:Rock",
"|-ability|p1a: Ogerpon|Embody Aspect (Cornerstone)|boost",
"|-boost|p1a: Ogerpon|def|1",
"|-terastallize|p2a: Ogerpon|Grass",
"|detailschange|p2a: Ogerpon|Ogerpon-Teal-Tera, F, tera:Grass",
"|-ability|p2a: Ogerpon|Embody Aspect (Teal)|boost",
"|-boost|p2a: Ogerpon|spe|1",
"|move|p1a: Ogerpon|Spiky Shield|p1a: Ogerpon",
"|-singleturn|p1a: Ogerpon|move: Protect",
"|move|p2a: Ogerpon|Ivy Cudgel|p1a: Ogerpon",
"|-activate|p1a: Ogerpon|move: Protect",
"|",
"|upkeep",
"|turn|3",
"|-message|test-player-a forfeited.",
"|",
"|win|test-player-b",
""
],
"p1rating": {"rpr": 1900, "rprd": 50},
"p2rating": {"rpr": 1750, "rprd": 100},
"endType": "forfeit",
"ladderError": true,
"timestamp": "Mon Aug 26 2024 02:55:18 GMT-0400 (Eastern Daylight Time)",
"roomid": "battle-gen9ubers-11478",
"format": "gen9ubers"
}
Loading