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.

Re: Dice

Postby Tyrion81 on Wed Sep 26, 2007 7:15 pm

cyberdaniel mentions it in this thread:
cyberdaniel wrote:Do you have version 1.5? If so, you need the Ajax enabled.

If you decide not to use Ajax you'll have to use the 1.4 version of the script:
v1.4a
v1.4b
v1.4c
Corporal 1st Class Tyrion81
 
Posts: 14
Joined: Thu Mar 22, 2007 8:29 pm
Location: Sydney, Australia

Dice analyzer

Postby alex_white101 on Fri Dec 07, 2007 5:59 am

I downloaded the dice analyzer a long time ago now, i havent looked at it since ajax, i have now installed the new bob for ajax and my dice analyzer isnt working, have i done something wrong?
''Many a true word is spoken in jest''
User avatar
Corporal 1st Class alex_white101
 
Posts: 1992
Joined: Sun Feb 25, 2007 1:05 am

Postby Aerial Attack on Fri Dec 07, 2007 9:18 am

This has nothing to do with AJAX BOB. If you haven't looked at your Dice Analyzer since pre-AJAX, you have version 1.4 or before (not AJAX compatible). There is a version 1.5 available - see the main Dice Analyzer thread (where this should be merged).
Image
My Conquer Club Scripts | Bests: 2133, #205
User avatar
Sergeant Aerial Attack
 
Posts: 1132
Joined: Mon Jun 04, 2007 7:59 pm
Location: Generation One: The Clan

Postby oggiss on Wed Jan 16, 2008 8:19 am

I have now installed dice analyzer but where can I see my stats? :O
User avatar
Major oggiss
 
Posts: 1607
Joined: Thu Jan 18, 2007 8:43 am
Location: Sweden - Probably the best country in the world

Postby oggiss on Thu Jan 17, 2008 12:05 pm

Can someone tell me how????????????
User avatar
Major oggiss
 
Posts: 1607
Joined: Thu Jan 18, 2007 8:43 am
Location: Sweden - Probably the best country in the world

Postby yeti_c on Thu Jan 17, 2008 12:13 pm

oggiss wrote:Can someone tell me how????????????


I think there is a menu option on the left hand side.

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

Postby hecter on Thu Jan 17, 2008 3:41 pm

yeti_c wrote:
oggiss wrote:Can someone tell me how????????????


I think there is a menu option on the left hand side.

C.

Ya, under "Personal Menu".
In heaven... Everything is fine, in heaven... Everything is fine, in heaven... Everything is fine... You got your things, and I've got mine.
Image
User avatar
Private 1st Class hecter
 
Posts: 14632
Joined: Tue Jan 09, 2007 6:27 pm
Location: Tying somebody up on the third floor

Postby Ros on Mon Jan 28, 2008 11:48 am

I want to download diceanalyser but i can't open cyberdaniel.

Is there another way to get it?
Major Ros
 
Posts: 79
Joined: Fri Oct 27, 2006 1:32 pm
Location: Rotterdam

Postby hecter on Mon Jan 28, 2008 2:34 pm

Ros wrote:I want to download diceanalyser but i can't open cyberdaniel.

Is there another way to get it?

http://userscripts.org/scripts/show/21767
In heaven... Everything is fine, in heaven... Everything is fine, in heaven... Everything is fine... You got your things, and I've got mine.
Image
User avatar
Private 1st Class hecter
 
Posts: 14632
Joined: Tue Jan 09, 2007 6:27 pm
Location: Tying somebody up on the third floor

Postby Twill on Tue Jan 29, 2008 4:28 am

Updated first post with userscript host.
Retired.
Please don't PM me about forum stuff any more.

Essential forum poster viewing:
Posting, and You! and How to behave on an internet forum...on the internet
User avatar
Corporal 1st Class Twill
 
Posts: 3630
Joined: Fri Jan 20, 2006 10:54 pm

Postby sanosuke on Mon Feb 18, 2008 7:11 pm

sorry, didnt want to read 24 pages to find out...but how do I look at the statistics page?
Image
User avatar
Sergeant sanosuke
 
Posts: 102
Joined: Mon Jan 14, 2008 9:56 am
Location: Memphis, TN

Postby BaldAdonis on Mon Feb 18, 2008 7:13 pm

sanosuke wrote:sorry, didnt want to read 24 pages to find out...but how do I look at the statistics page?

Dice Analyzer under Personal Menu, next to "my profile", "my settings", and all that.
User avatar
Captain BaldAdonis
 
Posts: 2334
Joined: Fri Aug 24, 2007 1:57 am
Location: Trapped in Pleasantville with Toby McGuire

Postby sanosuke on Mon Feb 18, 2008 8:41 pm

aah didn't think of looking there. Thanks! Now I gotta read the pages to find out exactly how this works...I'm going to assume it only logs my rolls and by default that would make me attacker O.o
Image
User avatar
Sergeant sanosuke
 
Posts: 102
Joined: Mon Jan 14, 2008 9:56 am
Location: Memphis, TN

Postby hecter on Mon Feb 18, 2008 9:52 pm

sanosuke wrote:aah didn't think of looking there. Thanks! Now I gotta read the pages to find out exactly how this works...I'm going to assume it only logs my rolls and by default that would make me attacker O.o

Ya. The script has no way of finding out how other people fare against you. The attacker is 100% you and the defender is a mix of all your opponents.
In heaven... Everything is fine, in heaven... Everything is fine, in heaven... Everything is fine... You got your things, and I've got mine.
Image
User avatar
Private 1st Class hecter
 
Posts: 14632
Joined: Tue Jan 09, 2007 6:27 pm
Location: Tying somebody up on the third floor

Postby sanosuke on Mon Feb 18, 2008 10:46 pm

Thanks Hecter, thats what I thought but it's nice to have confirmation ^_^

Well, if thats the case, the script only proves that I'm one unlucky SOB :cry: :cry:
Image
User avatar
Sergeant sanosuke
 
Posts: 102
Joined: Mon Jan 14, 2008 9:56 am
Location: Memphis, TN

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

PreviousNext

Return to Tool Archives

Who is online

Users browsing this forum: No registered users