Chess-bot is an automated application designed for demonstration and educational purposes on chess.com, the most popular chess website and mobile application.
Please refrain from using this bot for cheating purposes.
This bot leverages several technologies and resources to function effectively:
- chess.com: The main platform where the bot operates.
- stockfish.online: Utilizes Stockfish, the most powerful chess engine, to evaluate the best moves considering multiple depths.
- cypress.io: A leading JavaScript/TypeScript testing framework used for writing automated tests.
- chess.js: A handy npm package employed for converting algebraic notation to FEN.
The bot begins by setting up the visual field of the game:
cy.viewport(1000, 660)
Custom settings are managed within the /fixtures
folder, which includes:
languageMutations.json
playerLevel.json
stockFishDepth.json
numOfGameplayMoves.json
firstMove.json
The first move depends on the color assigned to the bot:
cy.getMyPlayerColor()
- White: Opens with King's Pawn Opening -
e4
. - Black: Uses a defensive move -
kc6
.
These moves are configurable in the fixture files.
The bot waits for each opponent's turn using a loop:
cy.get('[data-ply="x"]').should('exist')
All moves from chess.com are scanned:
cy.scanMovesFromChessMoveList()
This populates an array with all the moves, which is then evaluated to determine the best move using Stockfish:
cy.getBestMove(listOfMoves)
The bot executes moves using:
cy.move()
This function calculates the necessary board coordinates for the move.
Clone the repository and set up the project:
git clone https://github.com/miroslavmyrha/chess-bot.git
cd chess-bot
npm install
To run the bot:
npm run cypress:open
Select playChess.cy.js
in the Cypress UI to start the bot.
Contributions are welcome! For major changes, please open an issue first to discuss what you'd like to change. Ensure to update tests as appropriate.