Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <form id=form1 action = "">
<input type="checkbox" id="normal"> Normal <br>
<input type="checkbox" id="fire"> Fire <br>
<input type="checkbox" id="water"> Water <br>
<input type="checkbox" id="electric"> Electric <br>
<input type="checkbox" id="grass"> Grass <br>
<input type="checkbox" id="fighting"> Fighting <br>
<input type="checkbox" id="poison"> Poison <br>
<input type="checkbox" id="ground"> Ground <br>
<input type="checkbox" id="flying"> Flying <br>
<input type="checkbox" id="psychic"> Psychic <br>
<input type="checkbox" id="bug"> Bug <br>
<input type="button" value="Calculate best route" onclick="test(this.form)">

</form>

<p id="p1">Nothing has been calculated yet.</p>
              
            
!

CSS

              
                
              
            
!

JS

              
                function test(form) {
	// Compiled using the source code and Python. 'standard' is when you have no rod equipped, and rod is obviously with a rod
	var routeTypes = {1: {'rod': ['flying', 'normal'], 'standard': ['flying', 'normal']}, 2: {'rod': ['bug', 'bug', 'normal', 'poison', 'poison'], 'standard': ['bug', 'bug', 'normal', 'poison', 'poison']}, 3: {'rod': ['flying', 'normal', 'flying', 'ground', 'normal', 'fighting'], 'standard': ['flying', 'normal', 'flying', 'ground', 'normal', 'fighting']}, 4: {'rod': ['normal', 'flying', 'poison', 'ground', 'fighting', 'water', 'water', 'water', 'water', 'water'], 'standard': ['normal', 'flying', 'poison', 'ground', 'fighting']}, 5: {'rod': ['flying', 'flying', 'normal', 'normal', 'grass', 'normal', 'fighting', 'psychic', 'grass'], 'standard': ['flying', 'flying', 'normal', 'normal', 'grass', 'normal', 'fighting', 'psychic', 'grass']}, 6: {'rod': ['flying', 'flying', 'normal', 'normal', 'grass', 'normal', 'fighting', 'psychic', 'grass', 'water', 'water', 'water', 'water'], 'standard': ['flying', 'flying', 'normal', 'normal', 'grass', 'normal', 'fighting', 'psychic', 'grass']}, 7: {'rod': ['flying', 'flying', 'normal', 'fire', 'normal', 'grass', 'normal', 'fighting', 'fire', 'psychic', 'grass'], 'standard': ['flying', 'flying', 'normal', 'fire', 'normal', 'grass', 'normal', 'fighting', 'fire', 'psychic', 'grass']}, 8: {'rod': ['flying', 'flying', 'normal', 'poison', 'ground', 'fire', 'normal', 'normal', 'fighting', 'fire', 'psychic', 'psychic'], 'standard': ['flying', 'flying', 'normal', 'poison', 'ground', 'fire', 'normal', 'normal', 'fighting', 'fire', 'psychic', 'psychic']}, 9: {'rod': ['normal', 'normal', 'flying', 'flying', 'poison', 'ground', 'poison', 'poison', 'poison', 'poison'], 'standard': ['normal', 'normal', 'flying', 'flying', 'poison', 'ground', 'poison', 'poison', 'poison', 'poison']}, 10: {'rod': ['normal', 'normal', 'flying', 'poison', 'ground', 'poison', 'poison', 'fighting', 'electric', 'electric', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['normal', 'normal', 'flying', 'poison', 'ground', 'poison', 'poison', 'fighting', 'electric', 'electric']}, 11: {'rod': ['flying', 'flying', 'normal', 'normal', 'flying', 'poison', 'ground', 'psychic', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['flying', 'flying', 'normal', 'normal', 'flying', 'poison', 'ground', 'psychic']}, 12: {'rod': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal', 'normal', 'water', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal', 'normal']}, 13: {'rod': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal', 'normal', 'water', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal', 'normal']}, 14: {'rod': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal', 'water', 'water'], 'standard': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal']}, 15: {'rod': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal'], 'standard': ['flying', 'flying', 'grass', 'grass', 'grass', 'grass', 'grass', 'grass', 'normal']}, 16: {'rod': ['normal', 'normal', 'flying', 'flying', 'normal', 'normal'], 'standard': ['normal', 'normal', 'flying', 'flying', 'normal', 'normal']}, 17: {'rod': ['normal', 'flying', 'flying', 'fire', 'normal', 'normal', 'water', 'water', 'water', 'water', 'water'], 'standard': ['normal', 'flying', 'flying', 'fire', 'normal', 'normal']}, 18: {'rod': ['normal', 'normal', 'flying', 'flying', 'normal', 'water', 'water', 'water', 'water', 'water'], 'standard': ['normal', 'normal', 'flying', 'flying', 'normal']}, 19: {'rod': ['water', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['Rattata', 'Raticate', 'Spearow', 'Fearow', 'Doduo']}, 20: {'rod': ['water', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['Rattata', 'Raticate', 'Spearow', 'Fearow', 'Doduo']}, 21: {'rod': ['flying', 'flying', 'normal', 'normal', 'grass', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['flying', 'flying', 'normal', 'normal', 'grass']}, 22: {'rod': ['normal', 'flying', 'poison', 'poison', 'fighting', 'water', 'water', 'water'], 'standard': ['normal', 'flying', 'poison', 'poison', 'fighting']}, 23: {'rod': ['flying', 'flying', 'poison', 'poison', 'ground', 'ground', 'poison', 'poison', 'fighting', 'fighting', 'normal', 'water', 'water', 'water', 'water', 'water', 'water', 'water'], 'standard': ['flying', 'flying', 'poison', 'poison', 'ground', 'ground', 'poison', 'poison', 'fighting', 'fighting', 'normal']}, 24: {'rod': ['bug', 'bug', 'bug', 'bug', 'flying', 'flying', 'flying', 'grass', 'grass', 'psychic', 'grass', 'water', 'water', 'water', 'water', 'water'], 'standard': ['bug', 'bug', 'bug', 'bug', 'flying', 'flying', 'flying', 'grass', 'grass', 'psychic', 'grass']}, 25: {'rod': ['bug', 'bug', 'bug', 'bug', 'flying', 'flying', 'grass', 'grass', 'psychic', 'grass', 'water', 'water', 'water', 'water'], 'standard': ['bug', 'bug', 'bug', 'bug', 'flying', 'flying', 'grass', 'grass', 'psychic', 'grass']}}

	// Get a list of the selected types
	var allTypes = ["normal", "fire", "water", "electric", "grass", "fighting", "poison", "ground", "flying", "psychic", "bug"]
	var types = []
	for (var i in allTypes) {
		if (form[i].checked) {
			types.push(allTypes[i])
		}
	}
	if (types.length == 0){
		document.getElementById("p1").innerHTML = "No shard type selected."
		return
	}

	// For each route, count how many often a matching type will show up. For example, if the user picks Grass and Normal, the total number of grass and normal pokemon on each route.
	routeShards = []
	for (var id in routeTypes){
		route = routeTypes[id]
	
		// If you're going for water shards, you'll have the rod equipped. If not, you shouldn't.
		if (types.indexOf("water") != -1){
			shards = routeTypes[id]["rod"]
		}
		else{
			shards = routeTypes[id]["standard"]
		}
		
		// d = denominator (total number of shards in a route), n = numerator (number of matching shards)
		d = shards.length
		n = 0
		for (var type in types){
			n += shards.filter(function(x){return x==types[type]}).length	// get count of matching shards
		}
		
		/* The second element in the list is the number of hits it takes you to defeat a pokemon on that route. So like if you have 17k attack, it takes 1 hit to beat route 10, 2 for route 19, and 3 for 25. The last element is how much time there is, on average, between each enounter of the poke-type you're looking for. */
		routeShards.push([id, 1, n, d, calcTime(1, n, d)])
		routeShards.push([id, 2, n, d, calcTime(2, n, d)])
		routeShards.push([id, 3, n, d, calcTime(3, n, d)])
	}
	
	routeShards.sort(compareRoutes)

	// Print the 10 best routes. 
	s = "Best routes for "
	for (var i in types){
		s += types[i].capitalize() + ", "
	}
	s = s.slice(0, -2) + "<br>"
	for (var i = 0; i < 10; i++){
		route = routeShards[i]
		s += i+1 + ". Route " + route[0] + " (if you can " + route[1] + "-shot): "
		if (route[4] != 60){
			s += route[4].toFixed(3) + " seconds per shard<br>"
		}
		else{
			s += "Never!<br>"
		}
	}
	document.getElementById("p1").innerHTML = s
}

/* time per encounter / shards per encounter = time per shard
(.75 + 1*shots ) / (n/d)
(.75 + 1*shots) * d / n
(3+4*shots) * d / 4n
I did it this way to try and minimize any odd floating point errors. This way there's only one computation (the final one) that results in non-integer numbers. */
// return 60 if n is 0, ie that route has no pokemon of the right type. Also avoiding division by zero
function calcTime(shots, n, d){
	if (n == 0){
		return 60
	}
	return d*(3+4*shots) / (4*n)
}

// Sort by time per shard, ascending. If times are equal, sort by route # descending. The idea is that if two routes are equal, you should do the harder route for more money/tokens/exp. 
function compareRoutes(route1, route2){
	if (route1[4] == route2[4]){
		return route2[0] - route1[0]
	}
	return route1[4] - route2[4]
}

// Capitalize the first letter of a word
String.prototype.capitalize = function() {
    return this.charAt(0).toUpperCase() + this.slice(1);
}
              
            
!
999px

Console