![]() I also realise that there are still many things I can improve to make my chess bot even stronger, but my goal was achieved and my painful loss in 15 seconds completely forgotten.īut, please don’t use this software to cheat against other humans. I have shown that using just HTML as my inputs and outputs is very effective and super easy. This was a really fun project to work on and this post just shows you the tip of the iceberg (checkout my repository if you would like to know more). Feel free to create a Pull Request if you have fixes or improvements!! Final words If you have issues on Window maybe you can try out Windows Subsystem for Linux (WSL). But, as I already mentioned, I’m using a Macbook Pro so I have no clue what it will do in other environments. ![]() By default the WebAssembly chess engine is used, so no docker needed. Now hit play and sit back and relax, my bot will do the rest. It will start a browser and it will automatically navigate to the right place for you, wait until you see the ‘play’ button That’s it, now you can start playing $> lerna run start:bot packages/bot/.env and add your credentials. First clone the repository and build it $> git clone $> cd $> yarn $> lerna run build ![]() If you like, you can run my chess bot too. The reason behind playing weaker when my bot moves faster is unknown to me, but my best guess would be that they heavily rely on pondering, which might work against humans but not against my bot, because it can move extremely fast. With this strategy my bot never lost a single match!! In this game my bot starts a bit weaker (negative score) but around move 30 makes mistakes and the game is already won around move 40. In those cases my bot has a slight advantage. Pondering is simply using the opponent’s move time to consider likely opponent movesĪ Ponder hit means that the opponent did the expected move which my engine was pondering about. The structure of the HTML looks as follows This basically means that you have to fake the mouse and trigger programmatically a mousedown and mouseupon the correct HTML elements. The final piece of the puzzle is to move a chess piece. For example, to add code that measures the time my engine uses to think, I simply do let start: number eventhub.on('', () => start = Date.now()) eventhub.on('', () => console.log(Date.now() - start)) Move chess pieces This is what I use to connect all the different parts of my application. EventHub is used to trigger events for different phases during the match, like or game.over. DI (not shown in my code examples) gives me control over which classes get injected where and how they are instantiated. In my experience Dependency Injection (DI) and the Publish–subscribe pattern ( EventHub) are ideal candidates. When I run experiments like this, it always means that at some point new insights are gained and parts of the application have to be rewritten, removed or added. Luckily MutationObserver will do all the work here It is this change in HTML that is ideal for this particular situation. But if you’ve ever played at you might have noticed that your clock (bottom right corner) is highlighted when you have to move. Turn based gameĬ is not going to notify me when it’s my turn, so I have to monitor the HTML for changes that reflect this kind of information. The code that is injected in the browser has two important tasks, move chess pieces and monitor the game to determine when it is time to move. It can move extremely fast because no round trip to the backend is needed. I also have a WebAssembly version of Stockfish which I can inject into the browser as well. At the end of the game some game statistics are written to file which can be used for analysis to improve my chess bot. Without a GPU it plays very slow and too weak for the bot. I also created a docker image with Leela Chess Zero (Lc0), which is an other even stronger open source chess engine, but that one requires a GPU which I don’t have (old laptop). For convenience I run Stockfish inside a Docker container. At the start of each turn all required game information is sent using WebSockets to my NestJS backend, which uses an opening book (super fast) or the Stockfish chess engine. As soon as the game starts my chess bot automatically activates and starts playing. From there on I have to manually pick a bot and hit the play button. Puppeteer is responsible for spinning up the browser and navigate to, login and finally upload and execute the browser-bundle inside the browser.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |