Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package squashed.crunchit;
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintStream;
- import java.util.Arrays;
- import java.util.Collections;
- import java.util.HashMap;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Map;
- import java.util.Scanner;
- public class Crunchit {
- public static void main(String[] args) throws IOException {
- //You need to have this file.
- Scanner scanner = new Scanner(new File("december_ou.txt"));
- PrintStream out = System.out;
- List<Pokemon> allPokemon = new LinkedList<Pokemon>();
- Map<String, Pokemon> pokemonByName = new HashMap<String, Pokemon>();
- while(scanner.hasNextLine()) {
- Pokemon pok = new Pokemon(scanner);
- allPokemon.add(pok);
- pokemonByName.put(pok.name, pok);
- }
- for(Pokemon pok : allPokemon) {
- pok.weighCounters(pokemonByName);
- }
- //Change this to use different pokemon.
- //The size of the list doesn't matter.
- //Spell them the way they're spelled in the report,
- //it doesn't know that "Rotom-W" means "Rotom-Wash"
- List<Pokemon> team = Arrays.asList(
- pokemonByName.get("Breloom"),
- pokemonByName.get("Dragonite"),
- pokemonByName.get("Talonflame"),
- pokemonByName.get("Espeon"),
- pokemonByName.get("Excadrill")
- );
- //Crunch for counters
- Map<String, PokemonRef> teamCounters = new HashMap<String, PokemonRef>();
- for(Pokemon pok : team) {
- for(PokemonRef counter : pok.weighedCounters) {
- PokemonRef oldCount = teamCounters.get(counter.name);
- double c = oldCount == null ? 0 : oldCount.weight;
- c += counter.weight;
- teamCounters.put(counter.name, new PokemonRef(counter.name, c));
- }
- }
- List<PokemonRef> threatList = new LinkedList<PokemonRef>(teamCounters.values());
- //Uncrunch counters for team mates
- List<PokemonRef> uncrunchedThreats = new LinkedList<PokemonRef>();
- for(PokemonRef counter : threatList) {
- Pokemon counterPok = pokemonByName.get(counter.name);
- double uncounter = 0;
- for(PokemonRef cc : counterPok.counters) {
- if(team.contains(pokemonByName.get(cc.name))) {
- uncounter += cc.weight;
- }
- }
- double newWeight = counter.weight - uncounter;
- if(newWeight > 0) {
- uncrunchedThreats.add(new PokemonRef(counter.name, newWeight));
- }
- }
- Collections.sort(uncrunchedThreats);
- out.println("Threats to your team:");
- for(PokemonRef ref : uncrunchedThreats) {
- out.println(ref.name + "\t" + ref.weight);
- }
- //Find recommendations to take out threats
- out.println();
- out.println("Recommendations based on threats:");
- Map<String, PokemonRef> counterCounters = new HashMap<String, PokemonRef>();
- for(PokemonRef ref :uncrunchedThreats) {
- Pokemon pok = pokemonByName.get(ref.name);
- for(PokemonRef counter : pok.counters) {
- PokemonRef oldCount = counterCounters.get(counter.name);
- double c = oldCount == null ? 0 : oldCount.weight;
- c += counter.weight * pok.weight;
- counterCounters.put(counter.name, new PokemonRef(counter.name, c));
- }
- }
- List<PokemonRef> helperList = new LinkedList<PokemonRef>(counterCounters.values());
- Collections.sort(helperList);
- for(PokemonRef ref : helperList) {
- out.println(ref.name + "\t" + ref.weight);
- }
- }
- private static class Pokemon {
- private String name;
- private double weight;
- private List<PokemonRef> teammates = new LinkedList<PokemonRef>();
- private List<PokemonRef> counters = new LinkedList<PokemonRef>();
- private List<PokemonRef> weighedCounters = new LinkedList<PokemonRef>();
- //Teammates - "you have these pokemon on your team, maybe you'd like to have this"
- //Weighed Counters - "these are the most likely pokemon to rock your team"
- //Counters - "these pokemon kill whatever we specified n weighed counters"
- private Pokemon(Scanner source) {
- source.nextLine(); //Start of name block
- String nameLine = source.nextLine();
- name = nameLine.substring(" | ".length(), nameLine.length() - 3).trim();
- source.nextLine(); //End of name block
- source.nextLine(); //Raw count
- String weightLine = source.nextLine();
- weight = Double.valueOf(
- weightLine.substring(" | Avg. weight: ".length(), weightLine.length() - 3).trim()
- );
- source.nextLine(); //End of count block
- skipSection(source); //Abilities
- skipSection(source); //Items
- skipSection(source); //Spreads
- skipSection(source); //Moves
- source.nextLine(); //"Teammates" header
- String teamLine = source.nextLine();
- while(!teamLine.contains("--------")) {
- String teamName = teamLine.substring(" | ".length(), teamLine.indexOf("+")).trim();
- String teamStat = teamLine.substring(teamLine.indexOf("+")+1, teamLine.indexOf("%"));
- teammates.add(new PokemonRef(teamName, Double.valueOf(teamStat)));
- teamLine = source.nextLine();
- }
- source.nextLine(); //"Checks and Counters" header
- String checksLine = source.nextLine();
- while(!checksLine.contains("--------")) {
- String checkName = checksLine.substring(
- " | ".length(),
- checksLine.indexOf("(") - "91.522 ".length()
- ).trim();
- String checkStat = checksLine.substring(
- checksLine.indexOf("(") - "91.522 ".length(),
- checksLine.indexOf("(") - 1).trim();
- counters.add(new PokemonRef(checkName, Double.valueOf(checkStat)));
- source.nextLine(); //Ignore clarification KO/switch line
- checksLine = source.nextLine();
- }
- }
- public void weighCounters(Map<String, Pokemon> pokemonByName) {
- for(PokemonRef counter : counters) {
- Pokemon pok = pokemonByName.get(counter.name);
- if(pok != null) {
- double c = counter.weight;
- double p = pok.weight;
- weighedCounters.add(new PokemonRef(counter.name, c * p));
- }
- }
- }
- public void print(PrintStream out) {
- out.print("{");
- out.printf("name: \"%s\", ", name);
- out.printf("weight: %s, ", weight);
- out.print("team: [");
- for(PokemonRef ref : teammates) {
- out.print("{");
- out.printf("name: \"%s\", ", ref.name);
- out.printf("weight: %s", ref.weight);
- out.print("}, ");
- }
- out.print("], ");
- out.print("counters: [");
- for(PokemonRef ref : counters) {
- out.print("{");
- out.printf("name: \"%s\", ", ref.name);
- out.printf("weight: %s", ref.weight);
- out.print("}, ");
- }
- out.print("], ");
- out.print("weighedCounters: [");
- for(PokemonRef ref : weighedCounters) {
- out.print("{");
- out.printf("name: \"%s\", ", ref.name);
- out.printf("weight: %s", ref.weight);
- out.print("}, ");
- }
- out.print("]");
- out.print("},");
- out.println();
- }
- }
- private static class PokemonRef implements Comparable<PokemonRef> {
- private final String name;
- private final double weight;
- public PokemonRef(String name, double weight) {
- this.name = name;
- this.weight = weight;
- }
- @Override
- public int compareTo(PokemonRef b) {
- return (int) Math.signum(b.weight - weight);
- }
- }
- private static void skipSection(Scanner scanner) {
- String line = scanner.nextLine();
- while(!line.contains("--------")) {
- line = scanner.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement