Ikariam Ally Sorter

By oberon Last update Oct 19, 2008 — Installed 6,092 times.

Archived Comments (locked)

in
Subscribe to Archived Comments 8 posts, 6 voices



Jesse Andrews Admin

The following is an archive of comments made before threaded discussions was implemented (November 16th, 2008)

 
oberon Script's Author

GBoz, strangely enough my ally doesn't get sorted in version 0.2.8, hope it won't disappoint you either

 
GBoz Scriptwright

I am sorry to disapoint you, but on 0.2.8 version the allies are already sorted. An ally sorter is not needed.

 
oberon Script's Author

Hi there,
I've made the changes necessary to be compatible with version 0.2.8 of ikariam.
I've also implemented Luca's suggestion (thanks Luca) to avoid firefox errors.
I've left one line commented out ready to adapt the script to Ally's Leaders as suggested by jerzeeg, which I thank, but I must warn you I haven't tried it yet.

I know the sorting algorithm is nothing more than a selection sort, which is quite inefficient on large lists, but I thought this wasn't the case. If somebody experiences a considerable delay please advice me and I'll improve the code's execution speed.

Thanks everybody for your kind comments and help ;)

 
GBoz Scriptwright

This is mine , takes less than a sec for 100 players, much much faster.
Oh and is uses floats not ints, cause it happen sometime that player have scores like 100,233 and 100,133
and they will not get sorted correctly.
Courtesy of ika-core.org

//sort the allies by score, this is how its done, small fast and accurate, it takes less than a second for 100 rows

sortallies();

function XX(xpath, xpres, startnode, myhtml){
if (!startnode) {startnode=document;}
var ret = document.evaluate(xpath, startnode, null, xpres, null);
if (myhtml) ret.singleNodeValue.innerHTML=myhtml;
return xpres == XPFirst ? ret.singleNodeValue : ret;
}

function forallrows(tbl,startrow,call){
for (var i=startrow; i<tbl>
call(tbl,i);
}

function mswap(a,b) {
bufa = a.innerHTML; a.innerHTML = b.innerHTML; b.innerHTML = bufa;
}

function sortAllies() {
var table = XX('//table[@id="memberList"]',XPFirst);
if (table) {
var lastcell=table.rows[i].cells.length-2;
forallrows(table,1,function(tbl,i){ var cell=tbl.rows[i].cells[4]; cell.innerHTML=cell.innerHTML.replace(',','.');});
forallrows(table,1,function(tbl,i){
var max;
max = findmax(i, tbl);
mswap(tbl.rows[i],tbl.rows[max]);
tbl.rows[i].cells[0].innerHTML=i+tbl.rows[i].cells[0].innerHTML;
});
}
}

function findmax(index, mTable) {
var Max = index;
forallrows(mTable,index, function(tbl,i){ if (parseFloat(tbl.rows[i].cells[4].innerHTML)> parseFloat(tbl.rows[Max].cells[4].innerHTML) ) Max=i;});
return Max;
}

 
Luca Saba Scriptwright

Could I suggest to put this:
if(document.getElementById('memberList') == null) return;

on top of the script. With this the Firefox Errors and the browser work less

 
jerzeeg User

for script to be working also for Home Secretary/Interior Minister you need to make this change:

function getPos(row) {
// Return the score value
return parseInt(row.cells[4].innerHTML.replace(/,/,""));
}

line with return change to ->
return parseInt(row.cells[(row.cells.length - 3)].innerHTML.replace(/,/,""));

 
immedja User

ty

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel