-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjm6.js
49 lines (38 loc) · 1.12 KB
/
jm6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var fs = require ('fs');
var pips_per_die = 4
var die_rx = /^([0-9]+)[Dd](\+([1-3]))?$/;
function dice_to_cost (stat) {
var match = die_rx.exec (stat);
if (match != null) {
dice = parseInt (match[0], 10);
if (match[3] != null) {
pips = parseInt (match[3], 10);
} else {
pips = 0;
}
return (dice * 4) + pips;
} else {
throw 'Invalid Stat: ' + stat
}
}
function cost_to_dice (cost) {
var dice = Math.floor (cost / pips_per_die);
var pips = cost % pips_per_die;
var s = dice.toString () + 'D';
if (pips != 0)
s = s + '+' + pips.toString ();
return s;
}
var args = process.argv.slice(2);
console.log ('args: ', args);
var characters_file = fs.readFileSync (args[0]);
console.log ('Characters_file: %s', characters_file);
var characters = JSON.parse (characters_file);
console.log ('Characters: %s', characters);
for (var i = 0; i < characters.length; i++) {
var character = characters[i];
console.log ('Character %d: %s', i, JSON.stringify (character));
}
var cost = dice_to_cost ('3D+3');
console.log ('cost: %d', cost);
console.log ('dice: %s', cost_to_dice (cost));