-
Notifications
You must be signed in to change notification settings - Fork 0
/
ai.js
52 lines (49 loc) · 1.73 KB
/
ai.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
50
51
52
var chai = require('chai');
var async = require('async');
var ai;
if (process.env.COVERAGE)
ai = require('../cov-lib/ai');
else
ai = require('../lib/ai');
describe('ai', function () {
describe('player', function () {
it('should create a player object', function () {
var player = ai.extend({
turn: function () {},
inflection: function () {},
init: function () {},
});
chai.expect(player).to.be.instanceof(ai.Player);
});
});
describe('basic', function () {
it('should take choices and return a decision (turn)', function (done) {
var choices = ['conquer', 'discover', 'exchange', 'expand', 'develop', 'consent'];
var players = choices.map(function (value) { return ai.basic[value]; });
var world = {};
var tasks = players.map(function (player, i) {
return player.turn.bind(player, choices, i, world);
});
async.parallel(tasks, function (err, players_choices) {
chai.expect(players_choices).to.deep.equal(choices);
done();
});
});
it('should take choices and return a decision (inflection)', function (done) {
var choices = ['conquer', 'discover', 'exchange', 'expand', 'develop', 'consent'];
var players = choices.map(function (value) { return ai.basic[value]; });
var world = {};
var tasks = players.map(function (player, i) {
return player.inflection.bind(player, choices, i, world);
});
async.parallel(tasks, function (err, players_choices) {
chai.expect(players_choices).to.deep.equal(choices);
done();
});
});
});
describe('repl', function () {
// TODO repl tests
it.skip('should turn stdin into player choices', function () { });
});
});