I addet a negative maximum funktion, with some other optimizations. The time spent to make the engin better isn’t addjustivied. I am gona leave it just like it is. It is better than me and that is good enough.
I addet dynamic depth, so the fewer pieces are on the board the deeper the position gets analyzed.
After some big optimizations, like moveordering and alpha-beta pruning, we are at a point where the engin actually beginns to get good. This engin is now comportable able to beat me. (I am about 1400 elo). It struggels a bit on endgames, and log-term development. I wasn’t really able to get a high depthed search, like other engins have it. I will have to take a good look why that might be. Thats gona be my next step.
First test on the engin.
I use a recursive minimax funktion. Look a couple of moves into the futer and evaluate the positions. The bot already understands the idea of captures. But it has no positional play at all. It is also terreable at checkmating.
I am not really sure how to structure my next few blogs. It will defenitly take 20h+ until the engin is somewhere playable. And I don’t want to log such a long time in on go. So I think I am just gona give small updates inbetween to show the inside of a chess engin.
The codepiece here is a basic evaluation funktion. It tells me exaclty which side is better at any given point. Although right now it is only counting material and not the quallity of the pieces that they contribute in the game.
Now with all of the groundlaying rules done, it is time to focus on the bot. I have already worked on the way the bot is gona be implemented. But the implementation itsself is still the biggest thing to work on. Right here you can see a bot that does a random legal move on the board. I didn’t even bother to check what elo this would be, but i would assume 150 to 250 elo. Next I will work on a evaluation funktion, which should be pretty easy.
This was the most frustrating error jet. Took me forever to figur out what even was going on. And I took me even longer fixing it. So what keept happening was this:
To fix this I have implemented a way to queen as user and also, one for the Bot, later down the line. Although the bot one only queens for now. I am not sure jet if it is even nessecery to programm it to promot to any other piece, because it is almost never really the only winning idea.
Checkmate has been addet, also the ability to draw, by stalemate and the 50 move rule. I won’t do the draw for insuficient material jet, maybe later down the road. But while testing I found a terrific but with pawnpromotion, It sometimes giliches out and ask you for a piece even if your not on the first or eightest rang.
I honestly expected the castling to be more complicated. But it is done now. With all rules implemented. No castling, afte moving the rook, the king, or if the king is in check, or if a rook has been taken. There is only one thing missing to make this game really playable, in a Player vs Player sense. Checkmate!
Got it! Now blocks, checks, pins, and captures work. Everything works. The only missing thing is chastling wich might be a bit tricky to implement. The way the code works now, is the following:
This may not ultimatle be the fasters way, but it’s fast enough for now. I might implement a even faster algorithem in the futur, but I like this one because it is just so clean and readable.
With the new logic it was a easy to add the legal moves for the king back in. Now lets get back at tackeling the blocking and check, and block mechanics.
All pieces are back to the right way the shouldm except the king. I know have some super clean funktions, that should make position calculation extreamly fast. I also heard about some optimizations with shifting bit array, to make the movecalculation for a sigle piece even faster. Not really shure how that works jet, but I am planing on implementing that to in the futer. The faster my legal moves calculator is now, the better the engin is gona get later on.
I realized that the way my current isKingInCheck funktion works, would just be way to slow, to make a powerfull engin later on. I did a quick search on the internet, and it turns out I need to split between legal and pseudo legal moves. Where the pseudo legal moves, disregard checks. So I started rewriting the last 400 lines of code. There is not much to show here.
Finally got the check logic on the king correctly. You are now unable to move a piece, if you are in check. Of course the blocking mecaniks are still missing. And I also should start working on the castlingmechaniks. But then I would me pretty much ready to start on the actual engin.
Quick update, I solved the file capturing error of pawns. It was only a wrong < and > sign.
I am slowly getting the realization, how hard this actually gone be. Protected pieces now can’t be captured by the king. But I am still struggeling with the concept of check. It only works for pawns currently, there seems to be a big bug somewhere in the code. And pawns are able to capture from file a to h.
Addet the complete movementlogic ecxept for the king. Even promotions and the sneaky en passant. The kings still proves to be a bit of a challange. But I will get it soon
I started on some legal checks for the pawn, rook and knight for now. Everything moves as expected. Even with captures and pieces of the own color blocking you. I have also added the blue indecators witch squares are allowed and witch are blocked. The other pieces will come soon.
The piece moving logic is now implemented. You could now theoreticly play the game(exept for promoting pawns). But there are still no legal checks, this will be the next thing to add.