Conquer Club

Dice analyzer 1.5.1a, 1.5.1b and 1.5.1c

Archival storage to keep things organized and uncluttered. Can't find what you need? Search for old topics here.

Moderator: Tech Team

Forum rules
Please read the Community Guidelines before posting.

Postby gdeangel on Sun Mar 02, 2008 11:57 pm

I also didn't want to have to read 24 pages... FIRST OFF, the tool is very impressive, but here's two questions:

1) I notice that under the first bar graph... it shows the number of 1's I've thrown, and then a blue bar for "won". Seems to me unless I missing something it is impossible to actually WIN with a "1", so this misleading. I'm assuming you are tallying based on the result of the total throw, i.e., a 1-1-6 thrown against a -1- is still a win... but then I think you need to add the yellow bar, because a 1-1-6 thrown against a 1-1 is a win1/lose1 result. It would be better if you just showed in the bar graph the actual outcome for that specific die (i.e., WIN/LOST/DIE NOT USED)

2) How can I reset the counter. I want to see the stats for a specific game, no so much to see if the dice are "rigged", but to know if I can truley say, well... that game I had good dice and still lost, I was outclassed - or, as seems more usually the case - damn dice cost me that game for sure!

Thanks
User avatar
Sergeant gdeangel
 
Posts: 779
Joined: Mon Jan 14, 2008 11:48 pm
Location: In the Basement

Postby lancehoch on Mon Mar 03, 2008 2:02 pm

cyberdaniel, would it be possible to have an expected results overall down near the bottom right? A formula similar to:
expected wins = (2890/7776)*3v2 + (855/1296)*3v1 + (295/1296)*2v2 + (125/216)*2v1 + (55/216)*1v2 + (15/36)*1v1

expected win % = expected wins/(3v2 + 3v1 + 2v2 + 2v1 + 1v2 + 1v1)

where 3v2, etc. represent the number of times you threw 3v2, etc.

and similarly for ties and losses

I do not know how much programming this would be, but it seems that this would be the next progression for this plugin.

gdeangel, the blue bar in the first graph represents the fraction of times that the number, ie 1, was thrown. The blue plus red that you see is only 25%. So if you were to throw a 1 on every fourth dice, the entire bar would be blue.
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Postby Stoney229 on Mon Mar 03, 2008 2:36 pm

can there be a tab that tells you the stats for the specific game you're in??
Score: 1739
Games: 88 Completed, 52 (59%) Won
#1302/21963
User avatar
Lieutenant Stoney229
 
Posts: 303
Joined: Fri Mar 03, 2006 10:46 am

Postby lancehoch on Sat Mar 08, 2008 2:35 am

Since the guy who created this seems to have left the site, does anyone have the code for the dice analyzer? I am unsure if I have the time to make some changes, but if someone could that would be great. I would definitely offer to help with some of the coding too.
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Postby Stoney229 on Sat Mar 08, 2008 4:35 am

lancehoch wrote:Since the guy who created this seems to have left the site, does anyone have the code for the dice analyzer? I am unsure if I have the time to make some changes, but if someone could that would be great. I would definitely offer to help with some of the coding too.

Is this what you are looking for?
Code: Select all
//----------------------------------------------------------------------
// Conquer Club - Dice Analyzer
// version 1.5a
//----------------------------------------------------------------------
// Description
//----------------------------------------------------------------------
// * Adds a table with dice statistics that the attacker and the
//   defender throw
// * Simulates dice rolls
//----------------------------------------------------------------------
// Meta Data
//----------------------------------------------------------------------
// ==UserScript==
// @name      Dice Analyzer
// @namespace   http://cyberdaniel.50webs.com/diceanalyzer/
// @description   Dice statistics and simulator
// @include      http://*conquerclub.com/*
// ==/UserScript==
//----------------------------------------------------------------------
// User Settings
//----------------------------------------------------------------------
var OPTIONS = new Object();
OPTIONS['defaultCookie'] = "conquerclub";
OPTIONS['storageCookie'] = "gamedatabase";
//----------------------------------------------------------------------

function myCookie()
{
private:
   var cookieInfo="";
   var cookieName="";
   var days = 50;   
public:
   this.open = function(name)
   {
      var nameEQ = name + "=";
      cookieName = name;
      var ca = document.cookie.split(';');
      for(var i=0;i < ca.length;i++) {
         var c = ca[i];
         while (c.charAt(0)==' ') c = c.substring(1,c.length);
         if (c.indexOf(nameEQ) == 0) cookieInfo = c.substring(nameEQ.length,c.length);
      }
      return "";   
   }
   
   this.eof = function()
   {
      if (cookieInfo.length == 0)
         return true;
      return false;
   }

   this.erase = function()
   {
      document.cookie = cookieName+"="+"; path=/";
   }

   this.write = function(info)
   {
      var date = new Date();
      date.setTime(date.getTime()+(days*24*60*60*1000));
      var expires = "; expires="+date.toGMTString();
      this.erase();
      document.cookie = cookieName+"="+info+expires+"; path=/";
      this.open(cookieName);
   }

   this.read = function()
   {
      var info=-1;
      if (this.eof())
         return 0;
      if (cookieInfo.indexOf(" ")!=-1)
         {
         info = parseInt(cookieInfo.substring(0,cookieInfo.indexOf(" ")));
         cookieInfo = cookieInfo.substring(cookieInfo.indexOf(" ")+1,cookieInfo.length);
         }
      else
         {
         info = parseInt(cookieInfo);
         cookieInfo = "";
         }
      return info;
   }
}

function loadStatistics(game)
{
   var sCookie = new myCookie();
   var stats = "";
   var statLen = 25;
   var stat = new Array();
   sCookie.open(game);
   if (sCookie.eof())
   {
      stats = "<center><b>Game not found!! Cookie name: '"+game+"'</b></center><br>";
   }
   else
   {
      stats = "<center><b>Game name: '"+game+"'</b></center>";
   }
   
   /*
   num wins / num ties / num loses / att 1s / att 2s / att 3s / att 4s / att 5s / att 6s / def 1s / def 2s /
   def 3s / def 4s / def 5s / def 6s / 3v2 win / 3v2 tie / 3v2 loss / 3v1 win / 3v1 loss / 2v2 win / 2v2 loss /
   2v1 win / 2v1 loss / 1v2 win / 1v2 loss / 1v1 win / 1v1 loss
   */
   for(var i=0;i<29;i++)
      stat[i]=sCookie.read();
   var attTotal=stat[3]+stat[4]+stat[5]+stat[6]+stat[7]+stat[8];
   var defTotal=stat[9]+stat[10]+stat[11]+stat[12]+stat[13]+stat[14];
   stats+="<p><table align=center style='width:100%;border:1px solid #FFF;background:#eee;' rules=rows>" +
            "<tr style='font-weight:bold;'><td></td><td>Attacker dice distribution</td><td>Defender dice distribution</td></tr>";
   for(var k=0;k<6;k++)
   {
      stats+="<tr style='font-weight:bold;'><td>"+(k+1)+"s</td><td>";
      
      for(var i=0;i<statLen;i++)
         if(4*stat[3+k]/attTotal*statLen>i)
            stats+="<font color='blue'>█</font>";
         else
            stats+="<font color='red'>█</font>";
      stats+=" " + stat[3+k] +" / "+attTotal+" ("+Math.round(stat[3+k]*10000/attTotal)/100+"%)</td><td>";
      for(var i=0;i<statLen;i++)
         if(4*stat[9+k]/defTotal*statLen>i)
            stats+="<font color='blue'>█</font>";
         else
            stats+="<font color='red'>█</font>";
      stats+=" "+ stat[9+k] + " / "+defTotal+" ("+Math.round(stat[9+k]*10000/defTotal)/100+"%)</td></tr>";
   }
   stats+="</table>";

   stats+="<p><table align=center style='width:100%;border:1px solid #FFF;background:#eee;' rules=rows>"+
         "<tr style='font-weight:bold;'><td>Battle Outcomes</td><td>Actual Stats</td><td>Ideal Stats</td></tr>"+
         "<tr style='font-weight:bold;'><td>3v2 ";
   for(var i=0;i<statLen;i++)
      if(i<stat[15]*statLen/(stat[15]+stat[16]+stat[17]))
         stats+="<font color='blue'>█</font>";
      else
         if(i<(stat[15]+stat[16])*statLen/(stat[15]+stat[16]+stat[17]))
            stats+="<font color='yellow'>█</font>";
         else
            stats+="<font color='red'>█</font>";
   stats+=" "+stat[15]+" / "+stat[16]+" / "+stat[17]+" </td><td>"+
   "(<font color='blue'>"+Math.round(stat[15]*10000/(stat[15]+stat[16]+stat[17]))/100+"%</font> /"+
   " <font color='#ffcc00'>"+Math.round(stat[16]*10000/(stat[15]+stat[16]+stat[17]))/100+"%</font> /"+
   " <font color='red'>"+Math.round(stat[17]*10000/(stat[15]+stat[16]+stat[17]))/100+"%</font>"+
   ")</td><td>(<font color='blue'>37.17%</font> / <font color='#ffcc00'>33.58%</font> / <font color='red'>29.26%</font>)</td></tr><tr style='font-weight:bold;'><td>3v1 ";
   for(var i=0;i<statLen;i++)
      if(i<stat[18]*statLen/(stat[18]+stat[19]))
         stats+="<font color='blue'>█</font>";
      else
         stats+="<font color='red'>█</font>";
   stats+=" "+stat[18]+" / "+stat[19]+" </td><td>"+
   "(<font color='blue'>"+Math.round(stat[18]*10000/(stat[18]+stat[19]))/100+"%</font> /"+
   " <font color='red'>"+Math.round(stat[19]*10000/(stat[18]+stat[19]))/100+"%</font>"+
   ")</td><td>(<font color='blue'>65.97%</font> / <font color='red'>34.03%</font>)</td></tr><tr style='font-weight:bold;'><td>2v2 ";
   for(var i=0;i<statLen;i++)
      if(i<stat[20]*statLen/(stat[20]+stat[21]+stat[22]))
         stats+="<font color='blue'>█</font>";
      else
         if(i<(stat[20]+stat[21])*statLen/(stat[20]+stat[21]+stat[22]))
            stats+="<font color='yellow'>█</font>";
         else
            stats+="<font color='red'>█</font>";
   stats+=" "+stat[20]+" / "+stat[21]+" / "+stat[22]+" </td><td>"+
   "(<font color='blue'>"+Math.round(stat[20]*10000/(stat[20]+stat[21]+stat[22]))/100+"%</font> /"+
   " <font color='#ffcc00'>"+Math.round(stat[21]*10000/(stat[20]+stat[21]+stat[22]))/100+"%</font> /"+
   " <font color='red'>"+Math.round(stat[22]*10000/(stat[20]+stat[21]+stat[22]))/100+"%</font>"+
   ")</td><td>(<font color='blue'>22.76%</font> / <font color='#ffcc00'>32.41%</font> / <font color='red'>44.83%</font>)</td></tr><tr style='font-weight:bold;'><td>2v1 ";
   for(var i=0;i<statLen;i++)
      if(i<stat[23]*statLen/(stat[23]+stat[24]))
         stats+="<font color='blue'>█</font>";
      else
         stats+="<font color='red'>█</font>";
   stats+=" "+stat[23]+" / "+stat[24]+" </td><td>"+
   "(<font color='blue'>"+Math.round(stat[23]*10000/(stat[23]+stat[24]))/100+"%</font> /"+
   " <font color='red'>"+Math.round(stat[24]*10000/(stat[23]+stat[24]))/100+"%</font>"+
   ")</td><td>(<font color='blue'>57.87%</font> / <font color='red'>42.13%</font>)</td></tr><tr style='font-weight:bold;'><td>1v2 ";
   for(var i=0;i<statLen;i++)
      if(i<stat[25]*statLen/(stat[25]+stat[26]))
         stats+="<font color='blue'>█</font>";
      else
         stats+="<font color='red'>█</font>";
   stats+=" "+stat[25]+" / "+stat[26]+" </td><td>"+
   "(<font color='blue'>"+Math.round(stat[25]*10000/(stat[25]+stat[26]))/100+"%</font> /"+
   " <font color='red'>"+Math.round(stat[26]*10000/(stat[25]+stat[26]))/100+"%</font>"+
   ")</td><td>(<font color='blue'>25.46%</font> / <font color='red'>74.54%</font>)</td></tr><tr style='font-weight:bold;'><td>1v1 ";
   for(var i=0;i<statLen;i++)
      if(i<stat[27]*statLen/(stat[27]+stat[28]))
         stats+="<font color='blue'>█</font>";
      else
         stats+="<font color='red'>█</font>";
   stats+=" "+stat[27]+" / "+stat[28]+" </td><td>"+
   "(<font color='blue'>"+Math.round(stat[27]*10000/(stat[27]+stat[28]))/100+"%</font> /"+
   " <font color='red'>"+Math.round(stat[28]*10000/(stat[27]+stat[28]))/100+"%</font>"+
   ")</td><td>(<font color='blue'>41.67%</font> / <font color='red'>58.33%</font>)</td></tr></table>";

   stats+="<p><table align=center style='width:100%;border:1px solid #FFF;background:#eee;' rules=rows>" +
         "<tr style='font-weight:bold;'><td>Overall stats</td></tr>" +
         "<tr style='font-weight:bold;'><td>Attacker threw "+attTotal+" dice.</td></tr>" +
         "<tr style='font-weight:bold;'><td>Defender threw "+defTotal+" dice.</td></tr>" +
         "<tr style='font-weight:bold;'><td>Wins / Ties / Loses ";
   for(var i=0;i<statLen;i++)
      if(i<stat[0]*statLen/(stat[0]+stat[1]+stat[2]))
         stats+="<font color='blue'>█</font>";
      else
         if(i<(stat[0]+stat[1])*statLen/(stat[0]+stat[1]+stat[2]))
            stats+="<font color='yellow'>█</font>";
         else
            stats+="<font color='red'>█</font>";
   stats+=" "+stat[0]+" / "+stat[1]+" / "+stat[2]+"</td></tr>"+
         "<tr><td><font color='blue'>█████</font> Attacker wins</td></tr>" +
         "<tr><td><font color='yellow'>█████</font> Attacker wins 1, defender wins 1</td></tr>" +
         "<tr><td><font color='red'>█████</font> Defender wins</td></tr>" +
         "</table>";
   return stats;
}

function addStatistics(id, game)
{
   var stats = loadStatistics(game);
   var el = win.document.getElementById(id);
   el.innerHTML = stats;
}

function addStyles()
{
   var style = "<style>\n"+
            "body\n"+
            "{\n"+
            "   font: normal 12px arial;\n"+
            "   margin: 25px 5px 0 5px;\n"+
            "}\n"+
            "td\n"+
            "{\n"+
            "   font: bold 12px arial;\n"+
            "}\n"+
            "#menu\n"+
            "{\n"+
            "   background-color:#cdc;width:100%;position:fixed;top:0px;left:0px;white-space:nowrap;text-align:center;padding:2px 0 2px 0;border: solid 1px #000;\n"+
            "}\n"+
            "#menu ul\n"+
            "{\n"+
            "   margin: 0;padding: 0;border: solid 0px #000;display: block;\n"+
            "}\n"+
            "#menu ul li\n"+
            "{\n"+
            "   display:inline;border: solid 1px #000;background-color:#cdc;padding:2px 10px 2px 10px;margin:0 -5px 0 0;cursor:pointer;text-align:center;\n"+
            "}\n"+
            "#menu ul li:hover\n"+
            "{\n"+
            "   display:inline;color:#fff;border: solid 1px #000;background-color:#aba;padding:2px 10px 2px 10px;margin:0 -5px 0 0;\n"+
            "}\n"+
            "#menu ul li a\n"+
            "{\n"+
            "   text-decoration: none;\n"+
            "}\n"+
            "</style>";
   return style;
}

function addBody()
{
   var body = "<html>\n"+
            "<head>\n"+
            "   <title>Conquer Club - Dice Analyzer</title>\n"+
            "</head>\n"+
            "<body>\n"+
            "   <div id='menu'>\n"+
            "   </div>"+
            "   <div id='body'>\n"+
            "   </div>\n"+
            "</body>\n"+
            "</html>";
   return body;
}

function testCookies()
{
   var database = new myCookie();
   database.open(OPTIONS['storageCookie']);
   var info = "";
   
   while(!database.eof())
   {
      var game = new myCookie();
      var gameName = database.read();
      game.open(gameName);
      if (!game.eof())
         info += gameName + " ";
   }
   
   database.write(info);
}

function selectGame()
{
   testCookies();
   var database = new myCookie();
   database.open(OPTIONS['storageCookie']);
   var body = win.document.getElementById('body');
   
   if (database.eof())
   {
      body.innerHTML = "The game database is empty!!!";
      return;
   }
   
   body.innerHTML = "";
   var table = win.document.createElement('table');
   table.style.border = "thin none #000";
   table.width = "100%";
   table.height = "100%";
   var tr = win.document.createElement('tr');
   var td = win.document.createElement('td');
   td.style.verticalAlign = "top";
   td.innerHTML = "<div><b>Select a game:</b></div><br>";
   var tdDiv = win.document.createElement('div');
   td.width = "120px";
   tdDiv.style.height = "420px";
   tdDiv.style.overflow = "auto";

   while (!database.eof())
   {
      var el = win.document.createElement('font');
      var game = database.read();
      var div = win.document.createElement("div");
      div.innerHTML = "&bull; Game ";
      el.innerHTML = game;
      el.style.font = "bold 12px arial;";
      el.style.cursor = "pointer;";
      el.style.textDecoration = "underline;";
      el.style.color = "#aba";
      el.addEventListener('click', function(){addStatistics("tbody", this.innerHTML+"");}, false);
      
      div.appendChild(el);
      tdDiv.appendChild(div);
   }
   td.appendChild(tdDiv);
   
   var td2 = win.document.createElement('td');
   td2.id = "tbody";
   tr.appendChild(td);
   tr.appendChild(td2);
   table.appendChild(tr);
   body.appendChild(table);
}

function simulateRolls()
{
   var diceStats = new myCookie();
   diceStats.open(OPTIONS['defaultCookie']);
   var idealStats = new Array(37.17, 33.58, 29.26);
   
   for (var i=0;i<=14;i++)
      diceStats.read();
   
   var wins = diceStats.read();
   var ties = diceStats.read();
   var loses = diceStats.read();
   var total = wins + ties + loses;
   wins = wins * 100 / total;
   ties = ties * 100 / total;
   loses = loses * 100 / total;
   
   var attackerArmies = parseInt(win.document.getElementsByTagName('input')[0].value) - 3;
   var defenderArmies = parseInt(win.document.getElementsByTagName('input')[1].value);
   
   var attackerLoss = new Array();
   var defenderLoss = new Array();
   
   attackerLoss[0] = ((idealStats[1] + Math.abs(idealStats[1] - ties))/2 + idealStats[2] + Math.abs(idealStats[2] - loses)) * defenderArmies /
                 ((idealStats[1] - Math.abs(idealStats[1] - ties))/2 + idealStats[0] - Math.abs(idealStats[0] - wins));
   //alert(((idealStats[1] - Math.abs(idealStats[1] - ties))/2 ));
   defenderLoss[0] = ((idealStats[1] - Math.abs(idealStats[1] - ties))/2 + idealStats[0] - Math.abs(idealStats[0] - wins)) * attackerArmies /
                 ((idealStats[1] + Math.abs(idealStats[1] - ties))/2 + idealStats[2] + Math.abs(idealStats[2] - loses));
   attackerLoss[1] = (idealStats[1]/2 + idealStats[2]) * defenderArmies / (idealStats[1]/2 + idealStats[0]);
   defenderLoss[1] = (idealStats[1]/2 + idealStats[0]) * attackerArmies / (idealStats[1]/2 + idealStats[2]);
   attackerLoss[2] = ((idealStats[1] - Math.abs(idealStats[1] - ties))/2 + idealStats[2] - Math.abs(idealStats[2] - loses)) * defenderArmies /
                 ((idealStats[1] + Math.abs(idealStats[1] - ties))/2 + idealStats[0] + Math.abs(idealStats[0] - wins));
   defenderLoss[2] = ((idealStats[1] + Math.abs(idealStats[1] - ties))/2 + idealStats[0] + Math.abs(idealStats[0] - wins)) * attackerArmies /
                 ((idealStats[1] - Math.abs(idealStats[1] - ties))/2 + idealStats[2] - Math.abs(idealStats[2] - loses));
   attackerLoss[3] = (idealStats[1]/2 + idealStats[2]) * defenderArmies / (idealStats[1]/2 + idealStats[0]);
   defenderLoss[3] = (idealStats[1]/2 + idealStats[0]) * attackerArmies / (idealStats[1]/2 + idealStats[2]);
   
   var outString = "<p><table align=center style='width:100%;border:1px solid #FFF;background:#eee;' rules=all><tr><td></td>"+
               "<td>Worst case scenario</td><td>Ideal case scenario</td><td>Best case scenario</td></tr>";
   outString += "<tr><td>Attacker loses</td>";
   for (var i=0;i<3;i++)
   {
      if (attackerLoss[i] >= attackerArmies)
      {
         outString += "<td>" + attackerArmies + "</td>";
      }
      else
      {
         outString += "<td>" + Math.round(attackerLoss[i]) + "</td>";
      }
   }
   outString += "</tr><tr><td>Defender loses</td>";
   for (var i=0;i<3;i++)
   {
      if (attackerLoss[i] >= attackerArmies)
      {
         outString += "<td>" + Math.round(defenderLoss[i]) + "</td>";
      }
      else
      {
         outString += "<td>" + defenderArmies + "</td>";
      }
   }
   outString += "</tr></table>";

   var output = win.document.getElementById('output');
   output.innerHTML = outString;
}

function diceRollSimulator()
{
   var body = win.document.getElementById("body");
   body.innerHTML = "<center><div style='font:bold 13px arial'>Dice Roll Simulator</div></center>"+
               "<p><div style='font:bold 12px arial'>Enter the number of troops for attacker and defender:</div>"+
               "<table><tr><td>Attacker: </td><td><input type='text' style='border:1px solid;'></td></tr>"+
               "<tr><td>Defender: </td><td><input type='text' style='border:1px solid;'></td></tr>"+
               "<tr><td colspan=2 align='center'><input type='button' value='Start simulation' "+
               "style='color:black;border:1px solid;background-color:#eee;'></td></tr></table><div id='output'></div>"+
               "<div style='position:fixed;top:350px;'><p><b>Warning!</b><p>* These statistics are only an estimate, "+
               "they don't necessary give a real output and since the dice are random large deviations from the norm can "+
               "occur (eg: 15v2 and attacker loses or 15v30 and attacker wins)<p>* In case the attacker gets down to 3 armies "+
               "and the defender still has armies then the simulation stops since the odds of wining change.<p>"+
               "* The worst case scenario and best case scenario is based on the statistics the player has at that moment and the "+
               "distance from the norm. The ideal statistics are based on the norm percentages.</div>";
   var button = win.document.getElementsByTagName('input')[2];
   button.addEventListener('click', simulateRolls, false);
}

function createMenu()
{
   var menu = win.document.getElementById("menu");
   menu.innerHTML = "<ul><li>General Statistics</li><!--<li>Detailed Game Statistics</li>--><li>Dice Roll Simulator</li></ul>";
   
   var menuItem = menu.getElementsByTagName("li");
   menuItem[0].addEventListener("click", function(){addStatistics("body", OPTIONS['defaultCookie']);}, false);
   //menuItem[1].addEventListener("click", selectGame, false);
   menuItem[1].addEventListener("click", diceRollSimulator, false);
}

function createWindow()
{
   win = window.open("","ccstats","height=500, width=950, toolbar=no, scrollbars=yes, menubar=no");
   win.document.write(addStyles());
   win.document.write(addBody());
   win.document.close();
   createMenu();
   addStatistics("body", OPTIONS['defaultCookie']);
}

function createButton()
{
   var leftBar = document.getElementById("leftColumn");
   
   var ul = leftBar.getElementsByTagName("ul");
   var li = document.createElement("li");
   var a = document.createElement("a");
   a.innerHTML = "Dice Analyzer";
   a.setAttribute("href","javascript:void(0);");
   li.addEventListener("click", createWindow, false);
   li.appendChild(a);
   ul[2].appendChild(li);
}

function saveDiceRolls(attackerRolls, defenderRolls, cookieName)
{
   var sCookie = new myCookie();
   
   sCookie.open(cookieName);
   
   var info = new Array();
   if (!sCookie.eof())
   {
      for (var i=0;i<29;i++)
      {
         info[i]= sCookie.read();
      }
   }
   else
   {
      for (var i=0;i<29;i++)
      {
         info[i]= 0;
      }
   }
   
   // order the dice so that the largest values are the first ones
   for (var i=0;i<attackerRolls.length;i++)
      for (var j=i+1;j<attackerRolls.length;j++)
         if (attackerRolls[i]<attackerRolls[j])
         {
            var tmp = attackerRolls[i];
            attackerRolls[i] = attackerRolls[j];
            attackerRolls[j] = tmp;
         }   
   for (var i=0;i<defenderRolls.length;i++)
      for (var j=i+1;j<defenderRolls.length;j++)
         if (defenderRolls[i]<defenderRolls[j])
         {
            var tmp = defenderRolls[i];
            defenderRolls[i] = defenderRolls[j];
            defenderRolls[j] = tmp;
         }

   var score = 0;
   for (var i=0;i<Math.min(defenderRolls.length, attackerRolls.length);i++)
   {
      if (attackerRolls[i] > defenderRolls[i])
         score++;
      else
         score--;
   }
   
   for (var i=0;i<attackerRolls.length;i++)
      info[attackerRolls[i] + 2]++;
   for (var i=0;i<defenderRolls.length;i++)
      info[defenderRolls[i] + 8]++;
      
   if (attackerRolls.length == 3 && defenderRolls.length == 2)
   {
      switch(score)
      {
         case 0: info[16] += 1; info[1] += 1; break; //tie
         case 2: info[15] += 1; info[0] += 1; break; //win
         case -2:info[17] += 1; info[2] += 1; break; //loss
      }
   }
   if (attackerRolls.length == 3 && defenderRolls.length == 1)
   {
      switch(score)
      {
         case 1: info[18] += 1; info[0] += 1; break; //win
         case -1:info[19] += 1; info[2] += 1; break; //loss
      }
   }
   if (attackerRolls.length == 2 && defenderRolls.length == 2)
   {
      switch(score)
      {
         case 0: info[21] += 1; info[1] += 1; break; //tie
         case 2: info[20] += 1; info[0] += 1; break; //win
         case -2:info[22] += 1; info[2] += 1; break; //loss
      }
   }
   if (attackerRolls.length == 2 && defenderRolls.length == 1)
   {
      switch(score)
      {
         case 1: info[23] += 1; info[0] += 1; break; //win
         case -1:info[24] += 1; info[2] += 1; break; //loss
      }
   }
   if (attackerRolls.length == 1 && defenderRolls.length == 2)
   {
      switch(score)
      {
         case 1: info[25] += 1; info[0] += 1; break; //win
         case -1:info[26] += 1; info[2] += 1; break; //loss
      }
   }
   if (attackerRolls.length == 1 && defenderRolls.length == 1)
   {
      switch(score)
      {
         case 1: info[27] += 1; info[0] += 1; break; //win
         case -1:info[28] += 1; info[2] += 1; break; //loss
      }
   }
   
   var str = "";
   for (var i=0;i<info.length;i++)
   {
      str += info[i] + " ";
   }
   sCookie.write(str);
}

function getDice(info)
{
   var dice = new Array();
   var diceRolls = info.getElementsByTagName("li");
   for (var i=0;i<diceRolls.length;i++)
   {
      dice[i] = parseInt(diceRolls[i].innerHTML);
   }
   return dice;
}

function getGameName()
{
   var gameDiv = document.getElementById('right_hand_side');
   var game = gameDiv.getElementsByTagName('h3');
   var num = game[0].innerHTML.substring(game[0].innerHTML.indexOf(' ')+1);
   return num;
}

function saveGameName(game)
{
   var database = new myCookie();
   database.open(OPTIONS['storageCookie']);
   if (database.eof())
   {
      database.write(game);
   }
   else
   {
      var info = "";
      while(!database.eof())
      {
         var gm = database.read();
         if (gm == game)
            return;
         info += gm + " ";
      }
      database.write(info + game);
   }
}

function analyzeDiceRolls(diceInfo)
{
   var roll = diceInfo.getElementsByTagName("div");
   
   for (var i=0;i<roll.length;i++)
   {
      var dice = roll[i].getElementsByTagName("ul");
      saveDiceRolls(getDice(dice[0]), getDice(dice[1]), OPTIONS['defaultCookie']);
      //saveDiceRolls(getDice(dice[0]), getDice(dice[1]), getGameName());
      //saveGameName(getGameName());
   }
}

function main()
{
   createButton();
   var dashboard = document.getElementById('dashboard');
   var log = document.getElementById('log');
   if( !(dashboard && log)) return;
   
   var handle = unsafeWindow.handleResponse;
   unsafeWindow.handleResponse = function()
   {
      var request = unsafeWindow.request;
      if (request.readyState == 4)
      {
         var elem = document.createElement("div");
         elem.innerHTML = request.responseText;
         var divs = elem.getElementsByTagName("div");
         for (var i = 0; i < divs.length; i++)
            if (divs[i].id == "rolls")
            {
               analyzeDiceRolls(divs[i]);
               break;
            }
      }
      return handle();
   }
}

var start = new main();

If so... this is only 1 of the 3 versions he had... but I just got this code from installing the GM script, right-clicking the monkey, "Manage User Scripts", highlighting Dice Analyzer, and clicking "Edit".
Score: 1739
Games: 88 Completed, 52 (59%) Won
#1302/21963
User avatar
Lieutenant Stoney229
 
Posts: 303
Joined: Fri Mar 03, 2006 10:46 am

Postby lancehoch on Sat Mar 08, 2008 4:52 pm

That looks like what I was looking for. Do you know what language that is in? I guess I was looking to add my suggestion from a few posts back, but I did not realize that the code was this complex.
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Postby Stoney229 on Sat Mar 08, 2008 6:14 pm

lancehoch wrote:That looks like what I was looking for. Do you know what language that is in? I guess I was looking to add my suggestion from a few posts back, but I did not realize that the code was this complex.
It's a greasemonkey script... which uses Javascript maybe?? I'm not entirely sure, but I thought it was JS
Score: 1739
Games: 88 Completed, 52 (59%) Won
#1302/21963
User avatar
Lieutenant Stoney229
 
Posts: 303
Joined: Fri Mar 03, 2006 10:46 am

Postby cyberdaniel on Sun Mar 16, 2008 12:26 pm

Hi guys, I think I'm back. I'm trying to start playing again, at least keep 4 games going at any point.

Since I just got back I didn't have time to read all the post so please let me catch up and I'll surely continue improving this script.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Postby cyberdaniel on Sun Mar 16, 2008 12:43 pm

Stoney229 wrote:can there be a tab that tells you the stats for the specific game you're in??


There can be, and I actually have that implemented, however it is still unstable. By unstable, I mean that if too many games need to be stored, firefox will start deleting cookies to make up space. In my case it deleted the most important cookie, the one with the general stats.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Postby lancehoch on Mon Mar 17, 2008 7:30 pm

cyberdaniel, I am not sure if you have read through all the posts since you got back, but up at the top of this page (page 25) I made a post asking about an expected results bar at the bottom of the analyzer. I was wondering if you saw that, or had any comments on the idea.
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Postby yeti_c on Tue Mar 18, 2008 4:50 am

cyberdaniel wrote:
Stoney229 wrote:can there be a tab that tells you the stats for the specific game you're in??


There can be, and I actually have that implemented, however it is still unstable. By unstable, I mean that if too many games need to be stored, firefox will start deleting cookies to make up space. In my case it deleted the most important cookie, the one with the general stats.


CyberDaniel... Can I advise against storing in Cookies...

For AJAX BOB - (and indeed the previous BOB) the GM_setValue GM_getValue functionality is used...

What I would do is - check for cookie if it's there read it in - then save it with GM_setValue - then delete cookie.

Then read with GM_getValue... (if it's still blank then assume no stats...)

For examples on how these functions work - then feel free to look at BOB and check out functions SERIALIZE & DESERIALIZE - and also most of the "snapshot" functions (at the bottom of the script) use these functions too.

C.
Image
Highest score : 2297
User avatar
Lieutenant yeti_c
 
Posts: 9624
Joined: Thu Jan 04, 2007 9:02 am

Postby cyberdaniel on Wed Mar 19, 2008 5:25 pm

lancehoch wrote:cyberdaniel, I am not sure if you have read through all the posts since you got back, but up at the top of this page (page 25) I made a post asking about an expected results bar at the bottom of the analyzer. I was wondering if you saw that, or had any comments on the idea.


I did read it and it looks like something interesting. I'll crank up the math and I'll add it.

yeti_c wrote:CyberDaniel... Can I advise against storing in Cookies...

For AJAX BOB - (and indeed the previous BOB) the GM_setValue GM_getValue functionality is used...

What I would do is - check for cookie if it's there read it in - then save it with GM_setValue - then delete cookie.

Then read with GM_getValue... (if it's still blank then assume no stats...)

For examples on how these functions work - then feel free to look at BOB and check out functions SERIALIZE & DESERIALIZE - and also most of the "snapshot" functions (at the bottom of the script) use these functions too.

C.


I know about it, but that would only move the problem from one place to another. I'm thinking of a way to compress the data or other ways of storing it. At one point I was thinking of hosting it on a server and it is still something that I think is doable, I just need to put more thought into it and actually try coding a few things.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Postby yeti_c on Thu Mar 20, 2008 3:45 am

yeti_c wrote:CyberDaniel... Can I advise against storing in Cookies...

For AJAX BOB - (and indeed the previous BOB) the GM_setValue GM_getValue functionality is used...

What I would do is - check for cookie if it's there read it in - then save it with GM_setValue - then delete cookie.

Then read with GM_getValue... (if it's still blank then assume no stats...)

For examples on how these functions work - then feel free to look at BOB and check out functions SERIALIZE & DESERIALIZE - and also most of the "snapshot" functions (at the bottom of the script) use these functions too.

C.


I know about it, but that would only move the problem from one place to another. I'm thinking of a way to compress the data or other ways of storing it. At one point I was thinking of hosting it on a server and it is still something that I think is doable, I just need to put more thought into it and actually try coding a few things.[/quote]

Yes - and No... the data would be moved into an area that Firefox wouldn't delete... and is also quicker, more reliable - and doesn't require the user to use Cookies...

If you have that much data - then I propose that you need to work a better way of saving it?

Feel free to drop me a PM to have a chat - also - as you're back in the CC world - would you like to join the "Greasy Monkeys" usergroup? (It's a user group for testing, suggestions, betas etc... in a more controlled environment - we have a few devs and an army of testers to help)

C.
Image
Highest score : 2297
User avatar
Lieutenant yeti_c
 
Posts: 9624
Joined: Thu Jan 04, 2007 9:02 am

Postby lancehoch on Mon Mar 24, 2008 9:49 pm

I have had this happen twice now: I opened the dice analyzer through the tab on the side menu and the stats have been reset. Does anyone know why this might happen? I had not reached the limit of 50 days between turns, so I am not sure what is causing the problem. One theory I have is that I had the dice analyzer window open while I took a turn, could this have caused the problem?
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Re: Dice analyzer 1.5a, 1.5b and 1.5c

Postby Pedronicus on Fri Mar 28, 2008 6:55 pm

Welcome back Daniel. I tried clicking on get 'Get Dice analyzer' 1.5 on my new mac, and don't have a clue what to do next.
Image
Highest position 7th. Highest points 3311 All of my graffiti can be found here
Major Pedronicus
 
Posts: 2080
Joined: Tue Jan 24, 2006 2:42 pm
Location: Busy not shitting you....

Re:

Postby cyberdaniel on Wed Apr 02, 2008 7:18 am

lancehoch wrote:cyberdaniel, I am not sure if you have read through all the posts since you got back, but up at the top of this page (page 25) I made a post asking about an expected results bar at the bottom of the analyzer. I was wondering if you saw that, or had any comments on the idea.


I'll start doing this some times this weekend .... hopefully

lancehoch wrote:I have had this happen twice now: I opened the dice analyzer through the tab on the side menu and the stats have been reset. Does anyone know why this might happen? I had not reached the limit of 50 days between turns, so I am not sure what is causing the problem. One theory I have is that I had the dice analyzer window open while I took a turn, could this have caused the problem?


Not too sure, I never tried it myself. I'll do some testing. For now keep it closed during game.

Pedronicus wrote:Welcome back Daniel. I tried clicking on get 'Get Dice analyzer' 1.5 on my new mac, and don't have a clue what to do next.


Thanks,

It should be as simple to install as all the other scripts. Get the greasemonkey addon for Firefox and a pop-up asking you to install it should display. If you can see the code then there might be a bar on top of the window with a few options as install, cancel ...

Let me know it it worked or not. I've heard that it worked fine for other people.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Re: Dice analyzer 1.5a, 1.5b and 1.5c

Postby Han Solo on Sat Apr 12, 2008 12:27 pm

I advised Daniel months ago about my data erased each time i close Firefox - while my C.C. cookies are not deleted.
Unfortunately he never answered.

Does anyone else get this problem ?

Thx, HS.
User avatar
Major Han Solo
 
Posts: 34
Joined: Thu Aug 30, 2007 3:50 am

Re: Dice analyzer 1.5a, 1.5b and 1.5c

Postby lancehoch on Mon Apr 14, 2008 10:37 am

My stats just reset again. Not sure what happened, but this time I definitely did not have the window open while I was rolling. Any progress on this situation? Also, is there going to be an update soon, I saw you mentioned that you were working on some changes to the plugin.
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Re: Dice analyzer 1.5a, 1.5b and 1.5c

Postby dunnsearch on Thu Apr 24, 2008 12:04 pm

thank you. i luv this script
User avatar
Colonel dunnsearch
 
Posts: 7
Joined: Sat Nov 10, 2007 9:28 am

Re: Dice analyzer 1.5a, 1.5b and 1.5c

Postby cyberdaniel on Fri Apr 25, 2008 7:12 am

Han Solo wrote:I advised Daniel months ago about my data erased each time i close Firefox - while my C.C. cookies are not deleted.
Unfortunately he never answered.

Does anyone else get this problem ?

Thx, HS.


Sorry if I didn't reply, I must of been busy or forgot.

I'm assuming this is happening with the latest ajax version of the script.

lancehoch wrote:My stats just reset again. Not sure what happened, but this time I definitely did not have the window open while I was rolling. Any progress on this situation? Also, is there going to be an update soon, I saw you mentioned that you were working on some changes to the plugin.


I know, I've said I'd add that overall percentage thing, I just avoided doing it for some reason. (must be the math I need to do... arr) I'll get it done soon, hopefully ... but if you already know the math for it just send me the thing and I'll put it in since that's the only thing I need.


Regarding the bugs, this version is the least tested out of them all and some ajax related problems might still be there. I'll try getting something together and test/fix all issues that remain.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Re: Dice analyzer 1.5.1a, 1.5.1b and 1.5.1c

Postby cyberdaniel on Fri Apr 25, 2008 7:04 pm

The addition of the overall expected results has been completed. Thanks to lancehoch for helping get this done.

I haven't modified the version in the script so if the new one installed doesn't provide that extra statistic at the bottom of the diceanalyzer window then you might need to have the link refreshed of clear the browser's cache.

The scripts can be found at:
diceanalyzer v1.5.1a
diceanalyzer v1.5.1b
diceanalyzer v1.5.1c

depending on the version you want
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Re: Dice analyzer 1.5.1a, 1.5.1b and 1.5.1c

Postby lancehoch on Fri Apr 25, 2008 7:43 pm

cyberdaniel, what is the difference between the versions? Also, will this reset my statistics when I download the new version?
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Re: Dice analyzer 1.5.1a, 1.5.1b and 1.5.1c

Postby cyberdaniel on Sat Apr 26, 2008 11:53 am

lancehoch wrote:cyberdaniel, what is the difference between the versions? Also, will this reset my statistics when I download the new version?


This is a screenshot of how it looks now. Notice the "overall expected results" at the bottom of the window (right above the color legend).
Image
Don't mind the empty statistics, I've taking the screenshot on a different PC.

This shouldn't reset any statistics. I've tried all 3 versions without any such problems. The only addition was that extra piece of information which uses the current data.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

Re: Dice analyzer 1.5.1a, 1.5.1b and 1.5.1c

Postby lancehoch on Sat Apr 26, 2008 12:20 pm

cyberdaniel, looks great. One thing I noticed though was the expected results are in percentages, but the original bar is in actual stats. For the next update, could we get the percentages of the actual stats somewhere?
Sergeant lancehoch
 
Posts: 4183
Joined: Wed Dec 05, 2007 4:13 pm

Re: Dice analyzer 1.5.1a, 1.5.1b and 1.5.1c

Postby cyberdaniel on Sat Apr 26, 2008 4:53 pm

lancehoch wrote:cyberdaniel, looks great. One thing I noticed though was the expected results are in percentages, but the original bar is in actual stats. For the next update, could we get the percentages of the actual stats somewhere?


The next update planed will have a few other changes in graphics as well. Apart from that I'm not sure what I'll include in the next update. One plan is to revive the per-game statistics but I'll have to see.
"Every battle has been won before it's been fought." Sun Tzu
User avatar
Captain cyberdaniel
 
Posts: 281
Joined: Sat Apr 01, 2006 10:31 am

PreviousNext

Return to Tool Archives

Who is online

Users browsing this forum: No registered users