nodegame-client
Advanced tools
Comparing version 2.0.4 to 2.0.5
@@ -24,4 +24,4 @@ /** | ||
// Auto-Generated. | ||
node.version = '2.0.4'; | ||
node.version = '2.0.5'; | ||
})(window); |
@@ -1128,13 +1128,13 @@ /** | ||
* | ||
* The first parameter hook can be a string, a function, or an object | ||
* The first parameter can be a string, a function, or an object | ||
* containing an hook property. | ||
* | ||
* @params {mixed} hook Either the hook to be called or an object containing | ||
* at least the hook to be called and possibly even ctx and name | ||
* @params {object} ctx A reference to the context wherein the hook is | ||
* called. | ||
* @params {string} name The name of the hook. If not provided, this method | ||
* provides an uniqueKey for the hook | ||
* @params {string|function|object} hook The hook (string or function), | ||
* or an object containing a `hook` property (others: `ctx` and `name`) | ||
* @params {object} ctx The context wherein the hook is called. | ||
* Default: node.game | ||
* @params {string} name The name of the hook. Default: a random name | ||
* starting with 'timerHook' | ||
* | ||
* @returns {mixed} The name of the hook, if it was added; false otherwise. | ||
* @returns {string} The name of the hook | ||
*/ | ||
@@ -1173,2 +1173,3 @@ GameTimer.prototype.addHook = function(hook, ctx, name) { | ||
* @param {string} name Name of the hook to be removed | ||
* | ||
* @return {mixed} the hook if it was removed; false otherwise. | ||
@@ -1558,12 +1559,20 @@ */ | ||
if ('object' !== typeof timer) { | ||
timer = { milliseconds: timer }; | ||
} | ||
// If function, it can return a full object, | ||
// a function, or just the number of milliseconds. | ||
if ('function' === typeof timer) timer = timer.call(this.node.game); | ||
if ('function' === typeof timer.milliseconds) { | ||
timer.milliseconds = timer.milliseconds.call(this.node.game); | ||
if (null === timer) return null | ||
if ('function' === typeof timer) timer = timer.call(this.node.game); | ||
if ('number' === typeof timer) timer = { milliseconds: timer }; | ||
if ('object' !== typeof timer || | ||
'number' !== typeof timer.milliseconds || | ||
timer.milliseconds < 0) { | ||
this.node.warn('GameTimer.getStepOptions: invalid value for ' + | ||
'milliseconds. Found: ' + timer.milliseconds); | ||
return null; | ||
} | ||
if ('number' !== typeof timer.milliseconds) return null; | ||
// Make sure update and timer are the same. | ||
@@ -1570,0 +1579,0 @@ if ('undefined' === typeof timer.update) { |
@@ -257,3 +257,13 @@ /** | ||
alg = alg.toLowerCase(); | ||
if (alg !== 'roundrobin' && alg !== 'random') { | ||
if (alg === 'roundrobin' || alg === 'random') { | ||
if (alg === 'random' && | ||
arguments[2] && arguments[2].replace === true) { | ||
matches = randomPairs(arguments[1], arguments[2]); | ||
} | ||
else { | ||
matches = pairMatcher(alg, arguments[1], arguments[2]); | ||
} | ||
} | ||
else { | ||
throw new Error('Matcher.generateMatches: unknown algorithm: ' + | ||
@@ -263,3 +273,2 @@ alg + '.'); | ||
matches = pairMatcher(alg, arguments[1], arguments[2]); | ||
this.setMatches(matches); | ||
@@ -604,2 +613,3 @@ return matches; | ||
* competitor should be added or not. Default: true. | ||
* - rounds: number of rounds to repeat matching. Default | ||
* | ||
@@ -652,2 +662,110 @@ * @return {array} matches The matches according to the algorithm | ||
// TODO: support limited number of rounds. | ||
// function pairMatcher(alg, n, options) { | ||
// var ps, matches, bye; | ||
// var i, lenI, j, lenJ; | ||
// var roundsLimit, odd; | ||
// var skipBye; | ||
// | ||
// if ('number' === typeof n && n > 1) { | ||
// ps = J.seq(0, (n-1)); | ||
// } | ||
// else if (J.isArray(n) && n.length > 1) { | ||
// ps = n.slice(); | ||
// n = ps.length; | ||
// } | ||
// else { | ||
// throw new TypeError('pairMatcher.' + alg + ': n must be ' + | ||
// 'number > 1 or array of length > 1.'); | ||
// } | ||
// | ||
// odd = (n % 2) === 1; | ||
// roundsLimit = n-1 ; // (odd && !skipBye) ? n+1 : n; | ||
// | ||
// options = options || {}; | ||
// if ('number' === typeof options.rounds) { | ||
// if (options.rounds <= 0) { | ||
// throw new Error('pairMatcher.' + alg + ': options.rounds ' + | ||
// 'must be a positive number or undefined. ' + | ||
// 'Found: ' + options.rounds); | ||
// } | ||
// if (options.rounds > roundsLimit) { | ||
// throw new Error('pairMatcher.' + alg + ': ' + | ||
// 'options.rounds cannot be > than ' + | ||
// roundsLimit + '. Found: ' + options.rounds); | ||
// } | ||
// roundsLimit = options.rounds; | ||
// } | ||
// | ||
// matches = new Array(roundsLimit); | ||
// | ||
// bye = 'undefined' !== typeof options.bye ? options.bye : -1; | ||
// skipBye = options.skipBye || false; | ||
// if (n % 2 === 1) { | ||
// // Make sure we have even numbers. | ||
// ps.push(bye); | ||
// n += 1; | ||
// } | ||
// i = -1, lenI = roundsLimit; | ||
// for ( ; ++i < lenI ; ) { | ||
// // Shuffle list of ids for random. | ||
// if (alg === 'random') ps = J.shuffle(ps); | ||
// // Create a new array for round i. | ||
// matches[i] = []; | ||
// j = -1, lenJ = n / 2; | ||
// for ( ; ++j < lenJ ; ) { | ||
// if (!skipBye || (ps[j] !== bye && ps[n - 1 - j] !== bye)) { | ||
// // Insert match. | ||
// matches[i].push([ps[j], ps[n - 1 - j]]); | ||
// } | ||
// } | ||
// // Permutate for next round. | ||
// ps.splice(1, 0, ps.pop()); | ||
// } | ||
// return matches; | ||
// } | ||
// TODO: random with replacement. | ||
// /** | ||
// * ### pairMatcher | ||
// * | ||
// * Creates tournament schedules for different algorithms | ||
// * | ||
// * @param {string} alg The name of the algorithm | ||
// * | ||
// * @param {number|array} n The number of participants (>1) or | ||
// * an array containing the ids of the participants | ||
// * @param {object} options Optional. Configuration object | ||
// * contains the following options: | ||
// * | ||
// * - rounds: the number | ||
// * | ||
// * @return {array} matches The matches according to the algorithm | ||
// */ | ||
// function pairMatcherWithReplacement(n, options) { | ||
// var matches, i, len; | ||
// | ||
// if ('number' === typeof n && n > 1) { | ||
// n = J.seq(0, (n-1)); | ||
// } | ||
// else if (J.isArray(n) && n.length > 1) { | ||
// n = n.slice(); | ||
// } | ||
// else { | ||
// throw new TypeError('pairMatcherWithReplacement: n must be ' + | ||
// 'number > 1 or array of length > 1.'); | ||
// } | ||
// | ||
// i = -1, len = n.length; | ||
// matches = new Array(len-1); | ||
// for ( ; ++i < len ; ) { | ||
// m | ||
// } | ||
// | ||
// return matches; | ||
// } | ||
// ## Closure | ||
@@ -654,0 +772,0 @@ })( |
{ | ||
"name": "nodegame-client" | ||
, "description": "nodeGame client for the browser and node.js" | ||
, "version": "2.0.4" | ||
, "version": "2.0.5" | ||
, "homepage": "http://www.nodegame.org" | ||
@@ -6,0 +6,0 @@ , "keywords": ["game", "multiplayer", "experiment", "behavioral", "socket.io", "websockets"] |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
5146129
66541