@pedrobzz
Hey there, my name is Pedro Bzz and I'm a developer who's head over heels in love with Typescript. As a full-stack developer, I've got the skills to build an application from start to finish, both front-end and back-end, and my passion is using technology to make my life (and users' lives) easier and better. I'm always keeping an eye out for the latest technologies in the market, and I love the idea of having an amazing "Developer Experience", meaning that working with me is always easy!
Friday Finance
Balneário Camboriú, Santa Catarina - Brazil
Developing since January 2018
React, Next.js, TypeScript, Tailwind CSS, Vue, GraphQL, Node.js, Express and tRPC
PyChess is a Python-based chess AI that I developed in 2020 to play on chess.com using the Stockfish engine. I used OpenCV and PyAutoGUI to interact with the user screen and mimic human behavior, and the adaptive algorithm in PyChess proved highly effective, allowing it to play against players of any skill level and even win against the hardest chess.com AI.
However, as this was essentially cheating, I only played a few dozen matches online and PyChess was eventually banned after just three months of use.
I started the PyChess project because I wanted to learn more about OpenCV and I was also playing chess every day, either at school or at home on the computer, but I was extremely bad at it. Thinking about this, I came to the conclusion that "if chess is a game of intelligence, then making an AI that beats everyone at chess is not cheating, as it proves that I am the most intelligent", and that's how I got started!
Joking aside, I wanted to study OpenCV, and I knew I could never make a chess engine, that is, analyze the moves and say which is the best through an algorithm, so I decided to use Stockfish for that. So, with this in hand, dividing the problem into smaller parts was simple and straightforward.
First, I needed an algorithm to be able to read the computer screen and understand which pieces are on the board and where. The second part was to translate this information into FEN (Forsyth-Edwards) Notation, which is a way of describing the position of the pieces on a board through text, so that Stockfish can understand the game.
With this, the solution was to use a simple algorithm where the user defined where the board started and where it ended, using a UI, and then the board was divided into 64 parts, and these parts were associated with a Row/Column.
Then, a very simple script was able to identify in which parts a piece was contained and, upon finding all of them, it executed the script to identify the piece.
After that, an array was assembled with all the pieces in their position, exactly as on the board, and translated into FEN Notation. With this, Stockfish ran, and gave you the best move. However, to not make it too easy, Stockfish started with a light difficulty, and as the opponent played, it increased the difficulty.
Basically, the best moves were calculated, and based on the "score" of the opponent's move, the script adjusted the difficulty automatically. This allowed the AI to lose some times, and that was exactly the goal, but even when that happened, the chance of losing was minimal, to the point of almost never losing to humans and, when it did lose, it was because I wanted to interfere and make some moves.
However, I played little against humans, since for every game against a human, 5 games were played against AI. My favorite mode was Blitz, because it was extremely fast, and it also made me optimize the algorithm so that it didn't lose extra time.
To play, PyAutoGUI was used, and some algorithms were made so that the movements looked like they were made by humans and not a robot that goes from position X to position Y in a straight line almost instantly.