Giter Site home page Giter Site logo

chessbot_python's Introduction

Chessbot

"Why create another chessbot ?" The explanation is simple : I did not find a free bot I liked online : all the bots I saw on internet are parsing the html of the different websites to find the positions. But it creates a big limitation : if there is a new website, or a new html organisation, nothing will work. On the other hand my bot just looks at the screen and work with it to find the chessboard and the pieces. It is much more robust !

This chess bot can play automatically as white or black on lichess.com, chess.com, chess24.com and theoretically any website using drag and drop to move pieces. It uses stockfish engine to process moves, mss to do fast screenshots, pyautogui to move the mouse, chess to store and test the moves, and opencv to detect the chessboard. It has been written only with python.

About the bot level, it beats easily chess.com computer on level 8/10 (around 2000 ELO) when taking 1.2 second per move and crushes every human opponent on any time format longer than 1 minute.

This bot has been developped on iOS, but all the librairies it is using are compatible on Linux and Windows too.

Getting Started

Prerequisites

Stockfish:

This bot uses stockfish to calculate the next best move. Here is the procedure to make it work :

  • Download stockfish for your OS (https://stockfishchess.org/download/), the macOS stockfish I used is already commited.
  • Add it to your path with : export PATH=$PATH:$(pwd)
  • Test that stockfish is working well by running the command stockfish in your terminal. It should output something like this: Stockfish 120218 64 by T. Romstad, M. Costalba, J. Kiiski, G. Linscott

Python:

This bot requires python 3 to run

Using the bot:

The bot runs very easily:

  • go in the folder that contains the source code
  • Run the command python3 main.py

Limitations:

This project is far from perfect yet, it has a few limitations :

  • Because of the computer vision algorithm used to detect the chessboard, the square colors should be with plain colors, without having wierd textures.
  • The GUI is still quite basic
  • One small deviation during a game (the board moved, the user touched the mouse...) and the bot will not work at all.
  • It is not possible to stop the chessbot without closing the window
  • This project has been tested only on a Mac

Please feel free to help me improve it

Author

Stanislas Heili - Initial work - myGit

chessbot_python's People

Contributors

stanou01260 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

chessbot_python's Issues

No module named 'numpy'

Traceback (most recent call last):
File "main.py", line 3, in
import chessboard_detection
File "/Users/aleksandrveselov/Desktop/chessbot_python-master/code/chessboard_detection.py", line 1, in
import numpy as np
ModuleNotFoundError: No module named 'numpy'

No module named 'chess'

When trying to start the program I encountered the error 'No module named 'chess'' I am not very experienced in these sort of things especially python so I am unsure as to how to fix this issue.

Cannot use it in Windows

You mentioned in you readme file "Add it to your path with : export PATH=$PATH:$(pwd)" but as I was trying on Windows it on windows, I downloaded the Stockfish file of Windows suitable for my processor, set both user PATH variable and system PATH variable to the directory of the unzipped exe file of Stock fish.Still after typing stockfish in the command line stockfish message of authors does not appear.

I have restarted my PC and rechecked if this changes but no effect.Kindly advise
I have tried 3 different setup files and unzipped the file in Desktop\Projects\Chess_bot
Screenshot (1190)

works pretty good on windows

this bot is really well-programmed, hats off to the developer! (especially how the board is detected automatically)
but, most of the time the bot will not see the move the opponent has made, this causes it not do anything, and i'm the one who need to finish the game. I'm not really sure if it's because of my computer slowness making the program misses some frame. Can someone confirm this?
i also submitted a pull request that adds 'requirements.txt' to help user setup the library quickly.

Transform uci notations

In your code I have seen that it says that you use (import chess.uci) to go from 1. e4 to e2e4. I wanted to know how this operation is carried out to implement it in my own project?

update to conform to python-chess v1.0+

The python-chess module now uses a different interface for chess.uci. I am willing to make a pull request to update it to the current library standard, if the author of this repository is still here.

Problems

There are some problems.

  1. please make requirements.txt file.
  2. The bot stops after 7 moves in windows
  3. It cant detect the current position of the game.
  4. Mouse movements are the same.
  5. It doesn't support pre-move.

How to play by time?

I wanna the bot to play a game in 1 min or 2 min. How to do it? Am I need to edit the code and fix it? Thanks in advance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.