Computer mode in rules section almost OK
[vchess.git] / public / javascripts / utils / squareId.js
diff --git a/public/javascripts/utils/squareId.js b/public/javascripts/utils/squareId.js
new file mode 100644 (file)
index 0000000..a3423f7
--- /dev/null
@@ -0,0 +1,12 @@
+// Get the identifier of a HTML square from its numeric coordinates o.x,o.y.
+function getSquareId(o)
+{
+       // NOTE: a separator is required to allow any size of board
+       return  "sq-" + o.x + "-" + o.y;
+}
+
+// Inverse function
+function getSquareFromId(id) {
+       let idParts = id.split('-');
+       return [parseInt(idParts[1]), parseInt(idParts[2])];
+}