Skip to content

Commit

Permalink
Fixed bug with Reset Bonus Income stat, added average CPS stat with o…
Browse files Browse the repository at this point in the history
…ptions, added average Cookie Clicks stat with options (Issue CookieMonsterTeam#10), added the option to calculate with Wrinkers (Issue CookieMonsterTeam#34), added the option to calculate with average CPS, and minor cleanup
  • Loading branch information
Aktanusa committed Apr 26, 2016
1 parent 5d0958b commit eb3c403
Show file tree
Hide file tree
Showing 7 changed files with 520 additions and 122 deletions.
278 changes: 217 additions & 61 deletions CookieMonster.js

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions queue/queue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
Queue.js
A function to represent a queue
Created by Stephen Morley - http://code.stephenmorley.org/ - and released under
the terms of the CC0 1.0 Universal legal code:
http://creativecommons.org/publicdomain/zero/1.0/legalcode
*/

/* Creates a new queue. A queue is a first-in-first-out (FIFO) data structure -
* items are added to the end of the queue and removed from the front.
*/
function Queue(){

// initialise the queue and offset
var queue = [];
var offset = 0;

// Returns the length of the queue.
this.getLength = function(){
return (queue.length - offset);
}

// Returns true if the queue is empty, and false otherwise.
this.isEmpty = function(){
return (queue.length == 0);
}

/* Enqueues the specified item. The parameter is:
*
* item - the item to enqueue
*/
this.enqueue = function(item){
queue.push(item);
}

/* Dequeues an item and returns it. If the queue is empty, the value
* 'undefined' is returned.
*/
this.dequeue = function(){

// if the queue is empty, return immediately
if (queue.length == 0) return undefined;

// store the item at the front of the queue
var item = queue[offset];

// increment the offset and remove the free space if necessary
if (++ offset * 2 >= queue.length){
queue = queue.slice(offset);
offset = 0;
}

// return the dequeued item
return item;

}

/* Returns the item at the front of the queue (without dequeuing it). If the
* queue is empty then undefined is returned.
*/
this.peek = function(){
return (queue.length > 0 ? queue[offset] : undefined);
}

/* Returns the item at the spot specified by place in the queue (without
* dequeuing it). If the queue is emprty or the requested place is outside
* the queue then undefined is returned.
*/
this.get = function(place){
var item = undefined;
if (queue.length > 0 && place < (queue.length - offset) && place >= 0) {
item = queue[(offset + place)];
}
return item;
}

}
113 changes: 110 additions & 3 deletions src/Cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
* Cache *
*********/

CM.Cache.AddQueue = function() {
CM.Cache.Queue = document.createElement('script');
CM.Cache.Queue.type = 'text/javascript';
CM.Cache.Queue.setAttribute('src', 'http://aktanusa.github.io/CookieMonster/queue/queue.js');
document.head.appendChild(CM.Cache.Queue);
}

CM.Cache.NextNumber = function(base) {
var count = base > Math.pow(2, 53) ? Math.pow(2, Math.floor(Math.log(base) / Math.log(2)) - 53) : 1;
while (base == base + count) {
Expand Down Expand Up @@ -31,13 +38,27 @@ CM.Cache.RemakeIncome = function() {
CM.Sim.BuyBuildings(100, 'Objects100');
}

CM.Cache.RemakeWrinkBank = function() {
var totalSucked = 0;
for (var i in Game.wrinklers) {
var sucked = Game.wrinklers[i].sucked;
var toSuck = 1.1;
if (Game.Has('Sacrilegious corruption')) toSuck *= 1.05;
if (Game.wrinklers[i].type==1) toSuck *= 3; // Shiny wrinklers
sucked *= toSuck;
if (Game.Has('Wrinklerspawn')) sucked *= 1.05;
totalSucked += sucked;
}
CM.Cache.WrinkBank = totalSucked;
}

CM.Cache.RemakeBuildingsPP = function() {
CM.Cache.min = -1;
CM.Cache.max = -1;
CM.Cache.mid = -1;
for (var i in CM.Cache.Objects) {
//CM.Cache.Objects[i].pp = Game.Objects[i].getPrice() / CM.Cache.Objects[i].bonus;
CM.Cache.Objects[i].pp = (Math.max(Game.Objects[i].getPrice() - Game.cookies, 0) / Game.cookiesPs) + (Game.Objects[i].getPrice() / CM.Cache.Objects[i].bonus);
CM.Cache.Objects[i].pp = (Math.max(Game.Objects[i].getPrice() - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (Game.Objects[i].getPrice() / CM.Cache.Objects[i].bonus);
if (CM.Cache.min == -1 || CM.Cache.Objects[i].pp < CM.Cache.min) CM.Cache.min = CM.Cache.Objects[i].pp;
if (CM.Cache.max == -1 || CM.Cache.Objects[i].pp > CM.Cache.max) CM.Cache.max = CM.Cache.Objects[i].pp;
}
Expand All @@ -55,7 +76,7 @@ CM.Cache.RemakeBuildingsPP = function() {
CM.Cache.RemakeUpgradePP = function() {
for (var i in CM.Cache.Upgrades) {
//CM.Cache.Upgrades[i].pp = Game.Upgrades[i].getPrice() / CM.Cache.Upgrades[i].bonus;
CM.Cache.Upgrades[i].pp = (Math.max(Game.Upgrades[i].getPrice() - Game.cookies, 0) / Game.cookiesPs) + (Game.Upgrades[i].getPrice() / CM.Cache.Upgrades[i].bonus);
CM.Cache.Upgrades[i].pp = (Math.max(Game.Upgrades[i].getPrice() - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (Game.Upgrades[i].getPrice() / CM.Cache.Upgrades[i].bonus);
if (isNaN(CM.Cache.Upgrades[i].pp)) CM.Cache.Upgrades[i].pp = 'Infinity';
var color = '';
if (CM.Cache.Upgrades[i].pp <= 0 || CM.Cache.Upgrades[i].pp == 'Infinity') color = CM.Disp.colorGray;
Expand All @@ -72,7 +93,7 @@ CM.Cache.RemakeUpgradePP = function() {
CM.Cache.RemakeBuildingsOtherPP = function(amount, target) {
for (var i in CM.Cache[target]) {
//CM.Cache[target][i].pp = CM.Cache[target][i].price / CM.Cache[target][i].bonus;
CM.Cache[target][i].pp = (Math.max(CM.Cache[target][i].price - Game.cookies, 0) / Game.cookiesPs) + (CM.Cache[target][i].price / CM.Cache[target][i].bonus);
CM.Cache[target][i].pp = (Math.max(CM.Cache[target][i].price - (Game.cookies + CM.Disp.GetWrinkConfigBank()), 0) / Game.cookiesPs) + (CM.Cache[target][i].price / CM.Cache[target][i].bonus);
var color = '';
if (CM.Cache[target][i].pp <= 0 || CM.Cache[target][i].pp == 'Infinity') color = CM.Disp.colorGray;
else if (CM.Cache[target][i].pp < CM.Cache.min) color = CM.Disp.colorBlue;
Expand Down Expand Up @@ -198,9 +219,83 @@ CM.Cache.RemakeSellForChoEgg = function() {
CM.Cache.SellForChoEgg = sellTotal;
}

CM.Cache.InitCookiesDiff = function() {
CM.Cache.CookiesDiff = new Queue();
CM.Cache.WrinkDiff = new Queue();
CM.Cache.ChoEggDiff = new Queue();
CM.Cache.ClicksDiff = new Queue();
}

CM.Cache.UpdateAvgCPS = function() {
var currDate = Math.floor(Date.now() / 1000);
if (CM.Cache.lastDate != currDate) {
var choEggTotal = Game.cookies + CM.Cache.SellForChoEgg;
if (Game.cpsSucked > 0) {
choEggTotal += CM.Cache.WrinkBank;
}
choEggTotal *= 0.05;

if (CM.Cache.lastDate != -1) {
var timeDiff = currDate - CM.Cache.lastDate
var bankDiffAvg = Math.max(0, (Game.cookies - CM.Cache.lastCookies)) / timeDiff;
var wrinkDiffAvg = (CM.Cache.WrinkBank - CM.Cache.lastWrinkCookies) / timeDiff;
var choEggDiffAvg = Math.max(0,(choEggTotal - CM.Cache.lastChoEgg)) / timeDiff;
var clicksDiffAvg = (Game.cookieClicks - CM.Cache.lastClicks) / timeDiff;
for (var i = 0; i < timeDiff; i++) {
CM.Cache.CookiesDiff.enqueue(bankDiffAvg);
CM.Cache.WrinkDiff.enqueue(wrinkDiffAvg);
CM.Cache.ChoEggDiff.enqueue(choEggDiffAvg);
CM.Cache.ClicksDiff.enqueue(clicksDiffAvg);
}
// Assumes the queues are the same length
while (CM.Cache.CookiesDiff.getLength() > 1800) {
CM.Cache.CookiesDiff.dequeue();
CM.Cache.WrinkDiff.dequeue();
CM.Cache.ClicksDiff.dequeue();
}

while (CM.Cache.ClicksDiff.getLength() > 30) {
CM.Cache.ClicksDiff.dequeue();
}
}
CM.Cache.lastDate = currDate;
CM.Cache.lastCookies = Game.cookies;
CM.Cache.lastWrinkCookies = CM.Cache.WrinkBank;
CM.Cache.lastChoEgg = choEggTotal;
CM.Cache.lastClicks = Game.cookieClicks;

var totalGainBank = 0;
var totalGainWrink = 0;
var totalGainChoEgg = 0;
var cpsLength = Math.min(CM.Cache.CookiesDiff.getLength(), CM.Disp.times[CM.Config.AvgCPSHist] * 60);
// Assumes the queues are the same length
for (var i = CM.Cache.CookiesDiff.getLength() - cpsLength; i < CM.Cache.CookiesDiff.getLength(); i++) {
totalGainBank += CM.Cache.CookiesDiff.get(i);
totalGainWrink += CM.Cache.WrinkDiff.get(i);
totalGainChoEgg += CM.Cache.ChoEggDiff.get(i);
}
CM.Cache.AvgCPS = (totalGainBank + (CM.Config.CalcWrink ? totalGainWrink : 0)) / cpsLength;

if (Game.HasUnlocked('Chocolate egg') && !Game.Has('Chocolate egg')) {
CM.Cache.AvgCPSChoEgg = (totalGainBank + (CM.Config.CalcWrink ? totalGainWrink : 0) + totalGainChoEgg) / cpsLength;
}
else {
CM.Cache.AvgCPSChoEgg = CM.Cache.AvgCPS;
}

var totalClicks = 0;
var clicksLength = Math.min(CM.Cache.ClicksDiff.getLength(), CM.Disp.times[CM.Config.AvgClicksHist]);
for (var i = CM.Cache.ClicksDiff.getLength() - clicksLength; i < CM.Cache.ClicksDiff.getLength(); i++) {
totalClicks += CM.Cache.ClicksDiff.get(i);
}
CM.Cache.AvgClicks = totalClicks / clicksLength;
}
}

CM.Cache.min = -1;
CM.Cache.max = -1;
CM.Cache.mid = -1;
CM.Cache.WrinkBank = -1;
CM.Cache.NoGoldSwitchCookiesPS = 0;
CM.Cache.Lucky = 0;
CM.Cache.LuckyReward = 0;
Expand All @@ -219,4 +314,16 @@ CM.Cache.CentEgg = 0;
CM.Cache.SellForChoEgg = 0;
CM.Cache.Title = '';
CM.Cache.HadFierHoard = false;
CM.Cache.lastDate = -1;
CM.Cache.lastCookies = -1;
CM.Cache.lastWrinkCookies = -1;
CM.Cache.lastChoEgg = -1;
CM.Cache.lastClicks = -1;
CM.Cache.CookiesDiff;
CM.Cache.WrinkDiff;
CM.Cache.ChoEggDiff;
CM.Cache.ClicksDiff;
CM.Cache.AvgCPS = -1;
CM.Cache.AvgCPSChoEgg = -1;
CM.Cache.AvgClicks = -1;

6 changes: 5 additions & 1 deletion src/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ CM.ConfigData.BuildColor = {label: ['Building Colors OFF', 'Building Colors ON']
CM.ConfigData.BulkBuildColor = {label: ['Bulk Building Colors (Single Buildings Color)', 'Bulk Building Colors (Calculated Color)'], desc: 'Color code bulk buildings based on single buildings color or calculated bulk value color', toggle: false, func: function() {CM.Disp.UpdateBuildings();}};
CM.ConfigData.UpBarColor = {label: ['Upgrade Bar/Colors OFF', 'Upgrade Bar/Colors ON'], desc: 'Color code upgrades and add a counter', toggle: true, func: function() {CM.Disp.ToggleUpBarColor();}};
CM.ConfigData.Colors = {desc: {Blue: 'Color Blue. Used to show better than best PP building, for Click Frenzy bar, and for various labels', Green: 'Color Green. Used to show best PP building, for Blood Frenzy bar, and for various labels', Yellow: 'Color Yellow. Used to show between best and worst PP buildings closer to best, for Frenzy bar, and for various labels', Orange: 'Color Orange. Used to show between best and worst PP buildings closer to worst, for Next Reindeer bar, and for various labels', Red: 'Color Red. Used to show worst PP building, for Clot bar, and for various labels', Purple: 'Color Purple. Used to show worse than worst PP building, for Next Cookie bar, and for various labels', Gray: 'Color Gray. Used to show negative or infinity PP, and for Next Cookie/Next Reindeer bar', Pink: 'Color Pink. Used for Dragonflight bar', Brown: 'Color Brown. Used for Dragon Harvest bar'}, func: function() {CM.Disp.UpdateColors();}};
CM.ConfigData.CalcWrink = {label: ['Calculate with Wrinklers OFF', 'Calculate with Wrinklers ON'], desc: 'Calculate times and average Cookies Per Second with Wrinkers', toggle: true};
CM.ConfigData.CPSMode = {label: ['Current Cookies Per Second', 'Average Cookies Per Second'], desc: 'Calculate times using current Cookies Per Second or average Cookies Per Second', toggle: false};
CM.ConfigData.AvgCPSHist = {label: ['Average CPS for past 1m', 'Average CPS for past 5m', 'Average CPS for past 10m', 'Average CPS for past 15m', 'Average CPS for past 30m'], desc: 'How much time average Cookies Per Second should consider', toggle: false};
CM.ConfigData.AvgClicksHist = {label: ['Average Cookie Clicks for past 1s', 'Average Cookie Clicks for past 5s', 'Average Cookie Clicks for past 10s', 'Average Cookie Clicks for past 15s', 'Average Cookie Clicks for past 30s'], desc: 'How much time average Cookie Clicks should consider', toggle: false};
CM.ConfigData.ToolWarnCautBon = {label: ['Calculate Tooltip Warning/Caution With Bonus CPS OFF', 'Calculate Tooltip Warning/Caution With Bonus CPS ON'], desc: 'Calculate the warning/caution with or without the bonus CPS you get from buying', toggle: true};
CM.ConfigData.Flash = {label: ['Flash OFF', 'Flash ON'], desc: 'Flash screen on Golden Cookie/Season Popup', toggle: true};
CM.ConfigData.Sound = {label: ['Sounds OFF', 'Sounds ON'], desc: 'Play a sound on Golden Cookie/Season Popup', toggle: true};
CM.ConfigData.Volume = {label: [], desc: 'Volume of the sound'};
Expand All @@ -136,7 +141,6 @@ CM.ConfigData.Tooltip = {label: ['Tooltip Information OFF', 'Tooltip Information
CM.ConfigData.TooltipAmor = {label: ['Tooltip Amortization Information OFF', 'Tooltip Amortization Information ON'], desc: 'Add amortization information to buildings tooltip', toggle: true};
CM.ConfigData.ToolWarnCaut = {label: ['Tooltip Warning/Caution OFF', 'Tooltip Warning/Caution ON'], desc: 'A warning/caution when buying if it will put the bank under the amount needed for max "Lucky!"/"Lucky!" (Frenzy) rewards', toggle: true, func: function() {CM.Disp.ToggleToolWarnCaut();}};
CM.ConfigData.ToolWarnCautPos = {label: ['Tooltip Warning/Caution Position (Left)', 'Tooltip Warning/Caution Position (Bottom)'], desc: 'Placement of the warning/caution boxes', toggle: false, func: function() {CM.Disp.ToggleToolWarnCautPos();}};
CM.ConfigData.ToolWarnCautBon = {label: ['Calculate Tooltip Warning/Caution With Bonus CPS OFF', 'Calculate Tooltip Warning/Caution With Bonus CPS ON'], desc: 'Calculate the warning/caution with or without the bonus CPS you get from buying', toggle: true};
CM.ConfigData.ToolWrink = {label: ['Wrinkler Tooltip OFF', 'Wrinkler Tooltip ON'], desc: 'Shows the amount of cookies a wrinkler will give when popping it', toggle: true};
CM.ConfigData.Stats = {label: ['Statistics OFF', 'Statistics ON'], desc: 'Extra Cookie Monster statistics!', toggle: true};
CM.ConfigData.UpStats = {label: ['Statistics Update Rate (Default)', 'Statistics Update Rate (1s)'], desc: 'Default Game rate is once every 5 seconds', toggle: false};
Expand Down
Loading

0 comments on commit eb3c403

Please sign in to comment.