Home

Lichess Winrate per Hour

Diego Andriano (not AI)

20-06-2023

1306 / 250wpm = 5.2m

Introduction

Hello everyone! Have you ever wanted to - be better? Have you ever wanted to excel in some specific something you typically do? follow these simple steps, pay me $5000 and get your results NOW!

I'm joking, of course. No one has the tools to fix you. Back to the article, i'm an avid chess player. Not very good at it, but i do enjoy it. This particular Sunday, i started my morning with 2 rapid games of chess. I lost both of them, quite badly. The day goes on, and in the afternoon i'm winning 3 games straight.

Am i *better* at the afternoon? Or is it just plain coincidence? Let's find that out! We're going to be connecting to Lichess, creating some nice code, and testing it all out with PHPUnit.

What we're making

We're creating a Laravel command. When you feed this command with enough data, it will tell you how good do you do in different time frames. How will we see that? It's all about win rate. We'll compare win rates.

This command will return all the win rates separated by hours (7.00: 56%, 8.00: 42%). Will this be conclusive? probably not, but if you ever bet your house on a chess game, my command will be here free for your consulting ;)

Okay, i think if you ever get in a high stakes board game you'll appreciate if this was an API instead of a random command. So let's make that API!

Tools

  • Laravel
  • Lichess API
Laravel Laravel Logo

Starting point and pre-steps

First off, we need to get some games. From Lichess' API we can get all the games on a given account (it obviously has to exist on lichess, you can't ask for the chess.com games of the same account). We see some limitations, namely the reqs per second, but this is not a concern for what i'm gonna do.

Want to read more things like this? Subscribe!

Okay, that sounds great! If you were to download the games right now, you'd see it is in PGN format (it can be treated as a string). Not JSON. You can download it in ndjson format, but i think we'll be able to read it in pgn. Maybe some performance issues, but i'm not expecting so many people to use it, and this is the kind of things you use once and never touch again in your life, so... it might be kinda slow, get over it.

On Laravel and code review

I could start copying and pasting and trying to explain meanwhile, but i think it's easier to repeat the process i've already applied in the Spotify post. Here's the URL for the whole code. To see it working, this is the URL

Last words.

Initially, the idea was to write as i code. That way, you could experience the whole process. Midway through though, i realized the code was subpar, and the writing was even worse. It's like the saying

Any man who can drive safely while kissing a pretty girl is simply not giving the kiss the attention it deserves.

Source...?

So i decided to go for this route again. Hope you forgive me :D.

Do you have any notes? Do you think there's a better way? Comment it out on the gist and let's talk about it, i'm all in for getting better as a dev. Also, hope you enjoyed reading, see you next time!.