Created
March 13, 2016 23:02
-
-
Save raydog/fd15f30a4f032a5678a5 to your computer and use it in GitHub Desktop.
Scores ROMs based on the suffixes attached to them, and prints out ROMs that pass this test.
This file contains hidden or 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
var colors = require('colors'); | |
var _ = require('lodash'); | |
const DEBUG = false; | |
const CUTOFF = -500; | |
/** | |
* Basic util to select the "best" ROM from the ones provided. Grouped by stuff before (, or [ chars | |
*/ | |
function _score(name) { | |
var out = 0; | |
function _add(num) { | |
out += num; | |
} | |
// Parse parenthesis sections: | |
name.replace(/\(.*?\)/g, function (txt) { | |
var str = String(txt).slice(1,-1); | |
if (str === "beta") { return _add(-20); } // Beta version | |
if (/hack/i.test(str)) { return _add(-999); } // ROM hack | |
if (str[0] === "U") { return _add(50); } // USA release | |
if (str[0] === "E") { return _add(30); } // Europe release | |
if (str[0] === "J") { return _add(10); } // Japanese release | |
// Give very minor boosts to later revisions: | |
var m = str.match(/REV (\d+)/); | |
if (m) { return _add( parseInt(m[1], 10) ); } | |
}); | |
// Parse bracketted sections: | |
var brackets = 0; | |
name.replace(/\[.*?\]/g, function (txt) { | |
brackets ++; | |
var str = String(txt).slice(1,-1); | |
if (str === "!") { return _add(100); } // Preferred copy | |
if (str[0] === "h") { return _add(-20); } // ROM hack? | |
if (str[0] === "b") { return _add(-30); } // Broken ROM | |
if (str[0] === "p") { return _add(-20); } // Pirate copy | |
if (str[0] === "T") { return _add(-20); } // Fan translation | |
if (str[0] === "a") { return _add(-10); } // Alternate | |
}); | |
// No modifiers get a slight bonus: | |
if (brackets === 0) { _add(10); } | |
return out; | |
} | |
var groups = _.groupBy(process.argv.slice(2), name => String(name).replace(/[\[\(].*/, "").replace(/\.\w+$/, "")); | |
Object.keys(groups).forEach(function (key) { | |
var list = groups[key]; | |
DEBUG && console.log("===", key, "====="); | |
var with_scores = list.map(n => ({ name: n, score: _score(n) })); | |
var sorted = _.sortBy(with_scores, "score").reverse(); | |
sorted.forEach(function (item) { | |
var is_best = item.score === sorted[0].score; | |
var color = (is_best) ? "yellow" : "cyan"; | |
DEBUG && console.log(item.name[color], String(item.score).yellow); | |
if (!DEBUG && is_best && item.score >= CUTOFF) { | |
console.log(item.name); | |
} | |
}); | |
DEBUG && console.log(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment