-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.ts
77 lines (71 loc) · 1.7 KB
/
main.ts
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import crypto from 'crypto';
import { sprintf } from 'sprintf-js';
import _ from 'lodash';
import { GameObject } from './lib/GameObject';
let p1wins = 0;
let p2wins = 0;
let ties = 0;
let nPlys = 0;
let msec = 0;
let check = '';
const scores: number[] = [];
const game = new GameObject(1);
// Seeds are useless with this on
// turnOnBetterRandom(true);
const n = 600;
console.log("Playing", n, "games without PRNG.");
for (let i = 0; i < n; ++i) {
let res;
try {
res = game.playOneGame();
} catch (error) {
console.log('Game failed with seed:', game.deck.seed);
console.error(error);
process.exit();
}
const area = res.w * res.h;
const aspect = res.w / res.h;
if (res.p1score > res.p2score) {
++p1wins;
} else if (res.p1score < res.p2score) {
++p2wins;
} else {
++ties;
}
const p1 = (p1wins / (i + 1)) * 100;
const p2 = (p2wins / (i + 1)) * 100;
const ti = (ties / (i + 1)) * 100;
/*
console.log(
sprintf(
'%5d %3d %3d %3d %2d %2d %4d %5.3f %6.2f %6.2f %6.2f %12d %3d %5.1f',
i + 1,
res.p1score,
res.p2score,
res.nply,
res.w,
res.h,
area,
aspect,
p1,
p2,
ti,
res.seed,
res.nDead,
res.playTime
)
);
*/
if (res.nply !== 100) {
nPlys += res.nply;
msec += res.playTime;
scores.push(res.p1score);
scores.push(res.p2score);
} else {
console.log('Skip deadlock in performance result');
}
check += `${res.p1score}${res.p2score}${res.nply}${res.w}${res.h}`;
}
console.log(sprintf('Average score: %.1f', _.mean(scores)));
console.log(sprintf('msec per ply: %.3f', msec / nPlys));
console.log('Checksum:', crypto.createHash('md5').update(check).digest('hex'));