export some scoring functions for use in testing

This commit is contained in:
Tyler Renelle
2012-09-25 23:51:15 -04:00
parent 534e1be622
commit 80ac213fda
2 changed files with 99 additions and 30 deletions

View File

@@ -1,5 +1,5 @@
// Generated by CoffeeScript 1.3.3
var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, updateStats, user, _;
var MODIFIER, async, content, cron, expModifier, helpers, hpModifier, model, moment, score, setModel, setupNotifications, taskDeltaFormula, updateStats, user, _;
async = require('async');
@@ -68,22 +68,66 @@ setupNotifications = function() {
});
};
expModifier = function(value) {
var dmg, modified;
dmg = user.get('items.weapon') * MODIFIER;
dmg += (user.get('stats.lvl') - 1) * MODIFIER;
/*
Calculates Exp & GP modification based on weapon & lvl
{value} task.value for gain
{modifiers} may manually pass in stats as {weapon, exp}. This is used for testing
*/
expModifier = function(value, modifiers) {
var dmg, lvl, modified, weapon, _ref;
if (modifiers == null) {
modifiers = null;
}
_ref = [user.get('items.weapon'), user.get('stats.lvl')], weapon = _ref[0], lvl = _ref[1];
if (modifiers) {
weapon = modifiers.weapon, lvl = modifiers.lvl;
}
dmg = weapon * MODIFIER;
dmg += (lvl - 1) * MODIFIER;
modified = value + (value * dmg);
return modified;
};
hpModifier = function(value) {
var ac, modified;
ac = user.get('items.armor') * MODIFIER;
ac += (user.get('stats.lvl') - 1) * MODIFIER;
/*
Calculates HP-loss modification based on armor & lvl
{value} task.value which is hurting us
{modifiers} may manually pass in modifier as {armor, lvl}. This is used for testing
*/
hpModifier = function(value, modifiers) {
var ac, armor, lvl, modified, _ref;
if (modifiers == null) {
modifiers = null;
}
_ref = [user.get('items.armor'), user.get('stats.lvl')], armor = _ref[0], lvl = _ref[1];
if (modifiers) {
armor = modifiers.armor, lvl = modifiers.lvl;
}
ac = armor * MODIFIER;
ac += (lvl - 1) * MODIFIER;
modified = value - (value * ac);
return modified;
};
/*
Calculates the next task.value based on direction
For negative values, use a line: something like y=-.1x+1
For positibe values, taper off with inverse log: y=.9^x
Would love to use inverse log for the whole thing, but after 13 fails it hits infinity. Revisit this formula later
{currentValue} the current value of the task, determines it's next value
{direction} 'up' or 'down'
*/
taskDeltaFormula = function(currentValue, direction) {
var delta, sign;
sign = direction === "up" ? 1 : -1;
return delta = currentValue < 0 ? (-0.1 * currentValue + 1) * sign : (Math.pow(0.9, currentValue)) * sign;
};
updateStats = function(stats) {
var money, tnl;
if (user.get('stats.lvl') === 0) {
@@ -127,7 +171,7 @@ updateStats = function(stats) {
};
score = function(taskId, direction, options) {
var adjustvalue, delta, exp, hp, lvl, modified, money, num, sign, task, taskObj, taskPath, type, userObj, value, _ref, _ref1, _ref2;
var adjustvalue, delta, exp, hp, lvl, modified, money, num, task, taskObj, taskPath, type, userObj, value, _ref, _ref1, _ref2;
if (options == null) {
options = {
cron: false,
@@ -155,8 +199,7 @@ score = function(taskId, direction, options) {
});
return;
}
sign = direction === "up" ? 1 : -1;
delta = value < 0 ? (-0.1 * value + 1) * sign : (Math.pow(0.9, value)) * sign;
delta = taskDeltaFormula(value, direction);
delta *= options.times;
adjustvalue = type !== 'reward';
if ((type === 'habit') && (taskObj.up === false || taskObj.down === false)) {
@@ -284,8 +327,11 @@ cron = function() {
};
module.exports = {
MODIFIER: MODIFIER,
setModel: setModel,
MODIFIER: MODIFIER,
score: score,
cron: cron
cron: cron,
expModifier: expModifier,
hpModifier: hpModifier,
taskDeltaFormula: taskDeltaFormula
};