forked from gbtami/pychess-variants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathresult.ts
124 lines (119 loc) · 3.25 KB
/
result.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { h } from 'snabbdom';
import { _ } from './i18n';
import { Variant } from './variants';
export function gameType(rated: string | number) {
switch (rated) {
case "True":
case "1":
case 1:
return _("Rated");
case "2":
case 2:
return _("IMPORT");
default:
return _("Casual");
}
}
export function aiLevel(title: string, level: number) {
return (title === 'BOT' && level >= 0) ? ' ' + _('level %1', level): '';
}
export function renderRdiff(rdiff: number) {
if (rdiff === undefined) {
return h('span');
} else if (rdiff === 0) {
return h('span', '±0');
} else if (rdiff < 0) {
return h('bad', rdiff);
} else if (rdiff > 0) {
return h('good', '+' + rdiff);
} else {
return h('span');
}
}
export function result(variant: Variant, status: number, result: string) {
let text = '';
const variantName = variant.name;
// console.log("result()", variantName, status, result);
const first = _(variant.colors.first);
const second = _(variant.colors.second);
switch (status) {
case -2:
case -1:
text = _('Playing right now');
break;
case 0:
text = _('Game aborted');
break;
case 1:
text = _('Checkmate');
break;
case 2:
text = _('%1 resigned', (result === '1-0') ? second : first);
break;
case 3:
text = _('Stalemate');
break;
case 4:
text = _('Time out');
break;
case 5:
text = _('Draw');
break;
case 6:
text = _('Time out');
break;
case 7:
text = _('%1 abandoned the game', (result === '1-0') ? second : first);
break;
case 8:
text = _('Cheat detected');
break;
case 9:
text = _('Not started');
break;
case 10:
text = _('Invalid move');
break;
case 11:
text = _('Unknown reason');
break;
case 12:
switch (variantName) {
case 'orda':
case 'synochess':
case 'dobutsu':
case 'shinobi':
case 'empire':
case 'ordamirror':
text = _('Campmate');
break;
case 'chak':
text = _('Altar mate');
break;
case 'atomic':
text = _('Explosion of king');
break;
case 'duck':
text = _('King captured');
break;
default:
text = _('Point counting');
break;
}
break;
case 13:
switch (variantName) {
case 'janggi':
text = _('Point counting');
break;
default:
text = _('Repetition');
break;
}
break;
default:
text = '*';
break
}
return (status <= 0) ? text : text + ', ' + result;
}