forked from CookieMonsterTeam/CookieMonster
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed bug with Reset Bonus Income stat, added average CPS stat with o…
…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
Showing
7 changed files
with
520 additions
and
122 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.