()
| 18 | } |
| 19 | |
| 20 | function makeRandomMove() { |
| 21 | let gameCopy = Object.assign( |
| 22 | Object.create(Object.getPrototypeOf(game)), |
| 23 | game |
| 24 | ); |
| 25 | let gameFen = gameCopy.fen(); |
| 26 | const newFen = gameFen.replace("w", "b"); |
| 27 | gameCopy.load(newFen); |
| 28 | console.log(gameCopy); |
| 29 | |
| 30 | setGame(gameCopy); |
| 31 | |
| 32 | const possibleMoves = gameCopy.moves(); |
| 33 | |
| 34 | console.log(possibleMoves); |
| 35 | if (game.isGameOver() || game.isDraw() || possibleMoves.length === 0) |
| 36 | return; // exit if the game is over |
| 37 | const randomIndex = Math.floor(Math.random() * possibleMoves.length); |
| 38 | makeAMove(possibleMoves[randomIndex]); |
| 39 | // makeAMove(possibleMoves[0]); |
| 40 | setComputerTurn(false); |
| 41 | } |
| 42 | |
| 43 | function onDrop(sourceSquare, targetSquare) { |
| 44 | const move = makeAMove({ |
nothing calls this directly
no test coverage detected