forked from gbtami/pychess-variants
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinfo.ts
31 lines (25 loc) · 1.38 KB
/
info.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
import { h, VNode } from 'snabbdom';
import { getCounting, getJanggiPoints } from './chess';
import { patch } from './document';
// Counting for makruk, cambodian, sittuyin
export function updateCount(fen: string, whiteContainer: VNode | Element, blackContainer: VNode | Element) {
const [countingPly, countingLimit, countingSide, ] = getCounting(fen);
whiteContainer = patch(whiteContainer, h('div#misc-infow', ''));
blackContainer = patch(blackContainer, h('div#misc-infob', ''));
const countingStr = `${Math.floor((countingPly + 1)/2)}/${countingLimit/2 + (countingLimit/2)%2}`;
if (countingLimit !== 0 && countingPly !== 0) {
if (countingSide === 'w')
whiteContainer = patch(whiteContainer, h('div#misc-infow', countingStr));
else
blackContainer = patch(blackContainer, h('div#misc-infob', countingStr));
}
return [whiteContainer, blackContainer];
}
// Material point for janggi
export function updatePoint(fen: string, choContainer: VNode | Element, hanContainer: VNode | Element) {
const board = fen.split(" ")[0];
const [choPoint, hanPoint] = getJanggiPoints(board);
choContainer = patch(choContainer, h('div#misc-infow', { class: {'text-color-blue': true} }, choPoint));
hanContainer = patch(hanContainer, h('div#misc-infob', { class: {'text-color-red': true} }, hanPoint));
return [choContainer, hanContainer];
}