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";
10 if (!!args
.marks
&& args
.marks
!= "-")
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 coords
= V
.SquareToCoords(squares
[i
]);
18 markArray
[coords
.x
][coords
.y
] = true;
22 if (!!args
.shadow
&& args
.shadow
!= "-")
24 // Turn (human) shadow indications into coordinates
25 shadowArray
= doubleArray(sizeX
, sizeY
, false);
26 let squares
= args
.shadow
.split(",");
27 for (let i
=0; i
<squares
.length
; i
++)
29 const rownum
= V
.size
.x
- parseInt(squares
[i
]);
33 for (let i
=0; i
<V
.size
.y
; i
++)
34 shadowArray
[rownum
][i
] = true;
37 if (squares
[i
].length
== 1)
39 // Shadow a full column
40 const colnum
= V
.ColumnToCoord(squares
[i
]);
41 for (let i
=0; i
<V
.size
.x
; i
++)
42 shadowArray
[i
][colnum
] = true;
45 // Shadow just one square:
46 const coords
= V
.SquareToCoords(squares
[i
]);
47 shadowArray
[coords
.x
][coords
.y
] = true;
51 const [startX
,startY
,inc
] = orientation
== 'w'
53 : [sizeX
-1, sizeY
-1, -1];
54 for (let i
=startX
; i
>=0 && i
<sizeX
; i
+=inc
)
56 boardDiv
+= "<div class='row'>";
57 for (let j
=startY
; j
>=0 && j
<sizeY
; j
+=inc
)
59 boardDiv
+= "<div class='board board" + sizeY
+ " " +
60 ((i
+j
)%2==0 ? "light-square-diag" : "dark-square-diag") +
61 (shadowArray
.length
> 0 && shadowArray
[i
][j
] ? " in-shadow" : "") +
63 if (board
[i
][j
] != V
.EMPTY
)
65 boardDiv
+= "<img src='/images/pieces/" +
66 V
.getPpath(board
[i
][j
]) + ".svg' class='piece'/>";
68 if (markArray
.length
> 0 && markArray
[i
][j
])
69 boardDiv
+= "<img src='/images/mark.svg' class='mark-square'/>";