MCPcopy Create free account
hub / github.com/RootbeerComputer/backend-GPT / makeRandomMove

Function makeRandomMove

frontend-chess/src/ChessBoard.js:20–41  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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({

Callers

nothing calls this directly

Calls 1

makeAMoveFunction · 0.85

Tested by

no test coverage detected