cm-chessboard 7.7.6 → 7.7.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/model/Position.js +14 -5
package/package.json
CHANGED
package/src/model/Position.js
CHANGED
|
@@ -110,14 +110,23 @@ export class Position {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
static squareToIndex(square) {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
return 8 * rank + file
|
|
113
|
+
const coordinates = Position.squareToCoordinates(square)
|
|
114
|
+
return coordinates[0] + coordinates[1] * 8
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
static indexToSquare(index) {
|
|
119
|
-
|
|
120
|
-
|
|
118
|
+
return this.coordinatesToSquare([Math.floor(index % 8), index / 8])
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static squareToCoordinates(square) {
|
|
122
|
+
const file = square.charCodeAt(0) - 97
|
|
123
|
+
const rank = square.charCodeAt(1) - 49
|
|
124
|
+
return [file, rank]
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
static coordinatesToSquare(coordinates) {
|
|
128
|
+
const file = String.fromCharCode(coordinates[0] + 97)
|
|
129
|
+
const rank = String.fromCharCode(coordinates[1] + 49)
|
|
121
130
|
return file + rank
|
|
122
131
|
}
|
|
123
132
|
|