1 // Assuming V(ariantRules) class is loaded.
2 // args: object with position (mandatory), orientation, marks (optional)
3 function getDiagram(args
)
5 const [sizeX
,sizeY
] = [V
.size
.x
,V
.size
.y
];
6 // Obtain array of pieces images names
7 const board
= VariantRules
.GetBoard(args
.position
);
8 const orientation
= args
.orientation
|| "w";
12 // Turn (human) marks into coordinates
13 markArray
= doubleArray(sizeX
, sizeY
, false);
14 let squares
= args
.marks
.split(",");
15 for (let i
=0; i
<squares
.length
; i
++)
17 const res
= /^([a-z]+)([0-9]+)$/i.exec(squares
[i
]);
18 const x
= sizeX
- parseInt(res
[2]); //white at bottom, so counting is reversed
19 const y
= res
[1].charCodeAt(0)-97; //always one char: max 26, big enough
20 markArray
[x
][y
] = true;
24 const [startX
,startY
,inc
] = orientation
== 'w'
26 : [sizeX
-1, sizeY
-1, -1];
27 for (let i
=startX
; i
>=0 && i
<sizeX
; i
+=inc
)
29 boardDiv
+= "<div class='row'>";
30 for (let j
=startY
; j
>=0 && j
<sizeY
; j
+=inc
)
32 boardDiv
+= "<div class='board board" + sizeY
+ " " +
33 ((i
+j
)%2==0 ? "light-square-diag" : "dark-square-diag") + "'>";
34 if (board
[i
][j
] != V
.EMPTY
)
36 boardDiv
+= "<img src='/images/pieces/" +
37 V
.getPpath(board
[i
][j
]) + ".svg' class='piece'/>";
39 if (!!args
.marks
&& markArray
[i
][j
])
40 boardDiv
+= "<img src='/images/mark.svg' class='mark-square'/>";