Evaluation questions

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
RedBedHed
Posts: 84
Joined: Wed Aug 04, 2021 12:42 am
Full name: Ellie Moore

Evaluation questions

Post by RedBedHed »

Hello again!

I have written a very simple alpha-beta search just to get a feel for Charon's speed. However, I am not sure how best to approach the evaluation function. Right now, I am using left shifts by the heuristic values 1,3,3,5,9,100 to score every piece on the board. I give a big penalty to either side if they are in checkmate, and a tiny penalty if they are in check.

The engine actually plays a half-way decent game at depth 6 (at least from the perspective of an amateur like myself) with this evaluation. It takes one second or less to make each move. The only thing that really concerns me is that the engine moves its king before castling.

How should I evaluate in order to nudge the engine into a castle move? Also, should I consider piece position during evaluation? What else should I consider to make the engine play well? I'm working on my Zobrist module, so I should be able to search deeper soon... And I plan to add a quiescence search as well...
>> Move Generator: Charon
>> Engine: Homura
void life() { playCapitalism(); return; live(); }
User avatar
RedBedHed
Posts: 84
Joined: Wed Aug 04, 2021 12:42 am
Full name: Ellie Moore

Re: Evaluation questions

Post by RedBedHed »

Eventually, I want to try NNUE. But I have a lot of research to do first.
>> Move Generator: Charon
>> Engine: Homura
void life() { playCapitalism(); return; live(); }
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Evaluation questions

Post by algerbrex »

RedBedHed wrote: Sun Aug 15, 2021 11:34 pm Hello again!

I have written a very simple alpha-beta search just to get a feel for Charon's speed. However, I am not sure how best to approach the evaluation function. Right now, I am using left shifts by the heuristic values 1,3,3,5,9,100 to score every piece on the board. I give a big penalty to either side if they are in checkmate, and a tiny penalty if they are in check.

The engine actually plays a half-way decent game at depth 6 (at least from the perspective of an amateur like myself) with this evaluation. It takes one second or less to make each move. The only thing that really concerns me is that the engine moves its king before castling.

How should I evaluate in order to nudge the engine into a castle move? Also, should I consider piece position during evaluation? What else should I consider to make the engine play well? I'm working on my Zobrist module, so I should be able to search deeper soon... And I plan to add a quiescence search as well...
Hi Ellie, congrats on getting this point.

Starting off, I recommend just using piece-square tables and material evaluation.

You're free to role your own piece-square tables, but if you're not a strong player (2000+), it'll work much better to just borrow some from another engine and credit the author. Eventually, you can move towards tapered evaluation, which often gives quite a boost in Elo. A basic (but powerful) implementation of tapered eval can be found here.

And later down the line, once you starting adding more evaluation parameters, you can use Texel tuning, or similar algorithms, to automatically tune the evaluation values.

Some other features you'll probably want to consider after a while would be piece mobility, pawn structure (especially passed pawns), and king safety.

But as for right now, good piece-square tables + material evaluation, along with ab-pruning, quiescence search, and negamax, should be enough to put your engine anywhere between 1700-1500 Elo, probably closer to 1700 for you given your engine speed.
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Evaluation questions

Post by algerbrex »

RedBedHed wrote: Sun Aug 15, 2021 11:34 pm How should I evaluate in order to nudge the engine into a castle move?
That's the cool thing about the piece-square tables. Rather than you having to tune your engine to make it castle or develop its pieces towards the center, or whatnot, the engine will recognize from the piece-square tables that generally positions where the king is castled, and positions, where its pieces take control of the center, are better than positions where it doesn't do these things.

Of course, as I mentioned piece-square tables aren't the end all be all, but they definitely can serve as a strong foundation for an engine's evaluation function, and can really save you from a lot of tedious "micro-tuning" of the evaluation (like trying to coax your engine into castling).

Also, don't forget to add repetition detection and fifty-move rule detection, as it'll keep your engine from drawing winning positions. Working repetition detection can be worth anywhere from 50-100 Elo!
User avatar
RedBedHed
Posts: 84
Joined: Wed Aug 04, 2021 12:42 am
Full name: Ellie Moore

Re: Evaluation questions

Post by RedBedHed »

This all sounds fascinating! Especially the piece-square tables! I am so excited to try it all out! :D I'm at Hayden library right now, watching the Patrick Winston AI lectures to review. Sadly, I might not be able to work on the engine every day anymore (school starts back up in about 3-4 days). But I definitely plan to continue working on it whenever I have spare time! :)
>> Move Generator: Charon
>> Engine: Homura
void life() { playCapitalism(); return; live(); }
User avatar
RedBedHed
Posts: 84
Joined: Wed Aug 04, 2021 12:42 am
Full name: Ellie Moore

Re: Evaluation questions

Post by RedBedHed »

Thanks so much for all of these awesome research leads!
>> Move Generator: Charon
>> Engine: Homura
void life() { playCapitalism(); return; live(); }
User avatar
algerbrex
Posts: 608
Joined: Sun May 30, 2021 5:03 am
Location: United States
Full name: Christian Dean

Re: Evaluation questions

Post by algerbrex »

RedBedHed wrote: Mon Aug 16, 2021 1:09 am This all sounds fascinating! Especially the piece-square tables! I am so excited to try it all out! :D I'm at Hayden library right now, watching the Patrick Winston AI lectures to review. Sadly, I might not be able to work on the engine every day anymore (school starts back up in about 3-4 days). But I definitely plan to continue working on it whenever I have spare time! :)
:lol: I understand, school's about to start for me as well in three days, so Blunder too will be improved in my spare time. But don't worry, I'm pretty convinced that slow and steady is the way to make a strong engine :D
Henk
Posts: 7251
Joined: Mon May 27, 2013 10:31 am

Re: Evaluation questions

Post by Henk »

If you have no time then you could do this. Implement principal variation search and LMR.
Set LMR to 300. Now you can boast you solved chess but only move ordering need to be improved (a bit).

To do this you only need to change a few lines of code.
amanjpro
Posts: 883
Joined: Sat Mar 13, 2021 1:47 am
Full name: Amanj Sherwany

Re: Evaluation questions

Post by amanjpro »

Henk wrote: Mon Aug 16, 2021 11:09 am If you have no time then you could do this. Implement principal variation search and LMR.
Set LMR to 300. Now you can boast you solved chess but only move ordering need to be improved (a bit).

To do this you only need to change a few lines of code.
Is this supposed to be a helpful message? C'mon man the guy is new to chess programming, you will confuse him

To Ellie,

What Henk really means is that he thinks that most engines today are doing random pruning, reductions and tweaks to gain elo, and the only driver is elo gain not understanding WTF is happening. While I agree with that, but I also admit that trying to reason about search tree is hard.

Now ask yourself a question, what is your end goal really. If you want to know what is happening, then I try a handcrafted evaluation, implement the ideas that you know about chess, consult the CPW for evaluation and etc... You can get to 3000 without NNUE, and you can get to 2200 without even Texel tuning or PeSTO....
User avatar
RedBedHed
Posts: 84
Joined: Wed Aug 04, 2021 12:42 am
Full name: Ellie Moore

Re: Evaluation questions

Post by RedBedHed »

Henk, that seemed mean-spirited... and I'm not sure who it was directed at... But I feel the need to say something...

Until computers (maybe descendants of Sycamore or Jiuzhang?) are miraculously able to search the full game tree, I don't think chess will ever be "solved"... And I'm pretty sure you know that.

Some of the people on this forum really are geniuses. Everything that I have read so far has been eye-opening. But I'd like to think that they are here because they enjoy hacking chess and collaborating to make beautiful software. I'm going to keep thinking that way.

Amanj, thanks for having my back :)

My end goal with chess programming is to make something beautiful for my honors thesis, and to understand how humans and machines reason about zero-sum games. I want to work on AI in the real world someday, and I feel like this is the best place to start researching.

I've lived through quite a bit in 25 years. I've survived conversion therapy... Lost my family on both sides. I've been homeless several times. I bought my first computer when I was living in a shelter, actually. My parent's wealth kept me from qualifying for federal student aid, so I coffee-shop-hopped and watched lectures on public wi-fi until I did.

I don't know how I made it to ASU. Honestly, I figured that I would be dead by now. I just want to learn everything that I possibly can while I am still alive. And I want to spend the rest of my time fighting for a world where people treat each other like people.

But for now... I'll focus on making the best chess engine that I can. I'll take your suggestion and read up on evaluation. :)
>> Move Generator: Charon
>> Engine: Homura
void life() { playCapitalism(); return; live(); }