Skip to content

My own project - chess bot using Cypress plays on chess.com

License

Notifications You must be signed in to change notification settings

miroslavmyrha/chess-bot

Repository files navigation

Chess-bot

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.

ezgif com-video-to-gif

Introduction

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.

How it Works?

1. Game Initialization

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

2. Making the First Move

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.

3. Monitoring Opponent's Moves

The bot waits for each opponent's turn using a loop:

cy.get('[data-ply="x"]').should('exist')

4. Scanning and Evaluating Moves

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)

5. Executing Moves

The bot executes moves using:

cy.move()

This function calculates the necessary board coordinates for the move.

Installation

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.

Contributing

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.

License

MIT

About

My own project - chess bot using Cypress plays on chess.com

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published