Archive

Archive for the ‘Code’ Category

Wowhead Talent Calculator URL Codegolf

July 31st, 2009
Comments Off

EDIT: Now with extra linebreaks so you can actually read it in my awful layout.

It’s been ages since I’ve done any codegolf, so when I stumbled across Gizzmo’s blog post about the Wowhead talent calculator URL algorithm, I figured it might be fun to dust off the old “text editor” and see how it goes.

So, the proposal: given a variable c which contains a World of Warcraft class name (in lower case) and a variable i which contains the talent string in blizzard format, print the wowhead-ified URL to standard output. Note that while you can simply use the blizzard calculator strings directly on Wowhead, that wouldn’t be very interesting code ;]

Mine’s ruby, as usual. Here’s what I’ve came up with so far:

i='30530310500210252210320100000500000000000000000000000005320232030002120000000000000'
c='rogue'

t=0xa031812e3becf8e6cadb9.to_s(7).split(//).map{|v|v.to_i+25}
k='0zMcmVokRsaqbdrfwihuGINALpTjnyxtgevElBCDFHJKOPQSUWXYZ123456789'
d=%w(id er ge in st ue an ck or ht).index(c[-2,2])*3
r=k[d,1]+t[d,3].map{|e|i.slice!(0,e)}.map{|x|x.gsub(/0+$/,'').scan(/(.)(.)?/
).map{|a,b|k[a.to_i*6+b.to_i,1]}*''+(x[/0+$/]?'Z':'')}.join.gsub(/Z+$/,'')
puts'http://www.wowhead.com/?talent#'+r

The r and t variables aren’t strictly necessary (they are only used once each) but that line was getting long enough already, I’d give my editor an aneurism. In case it isn’t obvious, the t= line represents the sizes of the talent trees (since classes have different numbers of talents), the d= line represents the class indices (by the last two characters of each class name since if you do it from the front you need 4 to be unique, I blame warlocks) and the k= line is wowhead’s crazy encoding constant.

chronic Ruby, World of Warcraft , ,