-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutomaSpec.js
62 lines (43 loc) · 1.06 KB
/
AutomaSpec.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
53
54
55
56
57
58
59
60
61
62
import {
Automa,
Game,
Win
} from '../src/index.js';
describe('Automa', function() {
let wins = 0;
let passes = 0;
let losses = 0;
after(() => {
console.log('Results (W/L/P): %s %s %s', wins / 1000, losses / 1000, passes / 1000);
});
it('should play game', function() {
for (let i = 0; i < 1000; i++) {
// given
const game = new Game({ verbose: false });
const automas = [
new Automa(),
new Automa(),
new Automa()
];
let next = game.next('start');
while (next) {
if (next[0] === 'end') {
if (game.state.result.outcome === Win) {
wins++;
} else {
losses++;
}
break;
}
if (next[0] === 'ask-declare' && next[1] === null) {
passes++;
break;
}
const [ step, player ] = next;
const automa = automas[player];
const [ state, ...args ] = automa.next(game, step, player);
next = game.next(state, player, ...args);
}
}
});
});