cm-chessboard 4.1.2 → 4.1.3
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/index.html +8 -5
- package/package.json +1 -1
package/index.html
CHANGED
|
@@ -37,15 +37,18 @@ It works, it is cool and it is easy to use. 👍</p>
|
|
|
37
37
|
const board = new Chessboard(document.getElementById("board"), {
|
|
38
38
|
position: "start"
|
|
39
39
|
})
|
|
40
|
-
setInterval(() => {
|
|
40
|
+
const interval = setInterval(() => {
|
|
41
41
|
makeRandomMove()
|
|
42
42
|
board.setPosition(chess.fen(), true)
|
|
43
43
|
}, 250)
|
|
44
44
|
function makeRandomMove() {
|
|
45
|
-
const possibleMoves = chess.moves()
|
|
46
|
-
if (possibleMoves.length === 0)
|
|
47
|
-
|
|
48
|
-
|
|
45
|
+
const possibleMoves = chess.moves()
|
|
46
|
+
if (possibleMoves.length === 0) {
|
|
47
|
+
clearInterval(interval)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
const randomIndex = Math.floor(Math.random() * possibleMoves.length)
|
|
51
|
+
chess.move(possibleMoves[randomIndex])
|
|
49
52
|
}
|
|
50
53
|
</script>
|
|
51
54
|
<div class="clearfix"></div>
|