top of page

MIRAGE CHESS NNUE CUSTOM AI

Why?

After I created the Mirage Chess Variant. I started testing it out with my friends. It was everything i had ever hoped for. A new play ground where I could use my creativity to create new openings, sacrifice pawns to create initiative, engage in positional battles across the 10x10 board. I felt like a pioneer. We were in uncharted territory. Each move was new, no one had ever played it before. But after a while, I started to wonder if any of the plans I come up with is sound at all. I began to doubt my ability.

 

I was a good chess player, my peak was top 200 online in Viet Nam, 2170 rated rapid (97th% percentile of all chess players) but I was no where near the best. For the first time ever I couldn't check my playing accuracy with a chess computer. (I know i'm spoiled :)). It was as if I had started playing chess in the 1960s. I couldn't see all the possibilities, but the computer could.  Before I knew it, I had set out to create a super human chess engine on my own variant.

What is NNUE?

The current strongest computer chess engine is called stockfish. It was created by using an efficiently updated able neural network with a halfKpv2 process and trained from scratch starting from a handcrafted function by expert programmers and professional chess player.

The handcrafted functions take a snapshot of the board and evaluates the winning chances of both sides. The function takes into account things like strong squares and weak squares on the board, piece activity, which sides controls more space, material imbalance, safety of the king… etc. By the end, the function outputs an evaluation number that tells you which side is better. But this is per board position only, the secret sauce to stockfish is that it is trained on a NNUE (Efficiently updatable neural network).

Using NNUE never really crossed chess computer programmers mind, as they were thought to be not as strong. But a Japanese programmer called Yu Nasu got bored one day and ported the method from Shogi (traditional Japanese variant of chess) into chess. Now, it is one of the most widely used methods for chess engines.

The NNUE has four layers of input. The first layer being the thickest, 2x41024 inputs for a normal 8x8 chess board, then it slowly decreases as the network outputs a single eval number. So, what do you feed into the neural network? There are only 3 information needed per input: King position at all times on the board, what piece is it, and which square is it. This is where the “efficient” part of the name makes sense. Instead of evaluating each position separately from scratch with the handcrafted function, it would take too much time to go through the entire search tree on the board, resulting in an extremely slow computer engine. The NNUE takes into account positions and pieces RELATIVE to the king position. For example, the more enemy pieces are closer to our king, we can assume that the king is in danger and the position needs to be searched more carefully and vice versa, if a knight moves away further from the king, we can allow some shortcuts and not search so far ahead.

That is the watered-down explanation of the processes, if you would like more details, I would suggest checking this research paper out:

https://arxiv.org/abs/2209.01506

 

How?

While researching, I came across Fairy stockfish, which is a fork of stockfish code that is modified to work on different chess variants. There was already a big selection of variants already been trained, but mine is not on it of course =))

I downloaded the source code and tweaked some stuff, after a while I was able to recreate my variant in the program based on what variants they have done in the past. Complete with both sides castling, 10x10 board, new custom pieces, and new position.

I trained the program 3 times. Each with time 500,000,000 different positions at depth 3, and 1,000,000 different positions at depth 12 for validation data.

After approximately 10 days of letting my computer run at 100% CPU and GPU power it was safe to say I created a superhuman chess engine. Here is it in action.

bottom of page