How to dumb down/weaken/humanize an engine algorithmically?

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
WinPooh
Posts: 267
Joined: Fri Mar 17, 2006 8:01 am
Location: Russia
Full name: Vladimir Medvedev

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by WinPooh »

bob wrote:I've tried a BUNCH of things. I do not like just randomly choosing moves, as it doesn't feel right. Here's what I do in Crafty:

(1) slow the program down, which weakens it tactically. Note that I said "slow it down" and not "speed it up or make it move faster." This keeps the "flow of the game" feel reasonable.

(2) back off of the pruning stuff that tends to help tactically, and become more "brute-forceish"..

(3) interpolate the eval between a purely random number and the actual eval. For example, with the "skill" command, if you use "skill 50" it (a) runs much slower; (2) doesn't extend or reduce; and (3) the eval is made of of 50% random, 50% actual eval. As you back off on the skill level, the strength of the program has a reasonably linear drop, giving you a good chance of finding a setting that is right in line with your playing skill.
How do you deal with forced checkmates? Even at depth 1 advanced q-search can sometimes find a mate in 10...20 moves, which is almost impossible for a weak player.
S.Taylor
Posts: 8514
Joined: Thu Mar 09, 2006 3:25 am
Location: Jerusalem Israel

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by S.Taylor »

jdart wrote:In my engine I slow the speed (thus cutting depth) and randomize the eval. In addition I raise the minimum move frequency for the opening book, so as it gets weaker it will play very common lines but not know about less common ones (it also comes out of book earlier).

However, I am not really happy with the results. At low settings the randomness overwhelms the eval, so that it seems to lack even rudimentary chess knowledge. For example, it will walk the King out to the 3rd or 4th rank in the opening.

I'd like to have a "basic" and "advanced" eval and somehow keep the basic chess knowledge, like development and rudimentary king safety, while progressively reducing the more advanced stuff. That way at low levels it would play a bit more like a beginner who's had a few lessons but lacks sophisticated positional knowledge.

--Jon
One needs to find common denominators that all weak players do badly.

But the things that some do well, should stay.

AND it has to be in the human way.

One complication is that it should also be inconsistent in ways that weak human are inconsistent vs strong humans.
Jesse Gersenson
Posts: 593
Joined: Sat Aug 20, 2011 9:43 am

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by Jesse Gersenson »

At the very least, analyze 50-100 human games in the strength range you would like your engine to play.

For players in the 400-800 elo range, for example, you'll find they:
  • - show favoritism towards moving pawns or queen
    - don't know about en passant
    - don't know about pawn promotion
    - don't play for mate
    - rarely castle
    - will move the same pieces several times during the 'opening'
    - try to attack before their pieces are developed
    - 'giving check' is often favored over normal moves. it's as though they get points each time they give check.
User avatar
lucasart
Posts: 3232
Joined: Mon May 31, 2010 1:29 pm
Full name: lucasart

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by lucasart »

dkl wrote: Stockfish seems to just limit the search depth, consider via multipv several lines, and dependent on the strength level, add some kind of penalty for each line, and then chooses some weaker move.
I don't think you understood the code. I invite you to look at it again:
https://github.com/official-stockfish/S ... search.cpp
Theory and practice sometimes clash. And when that happens, theory loses. Every single time.
carldaman
Posts: 2283
Joined: Sat Jun 02, 2012 2:13 am

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by carldaman »

jdart wrote:In my engine I slow the speed (thus cutting depth) and randomize the eval. In addition I raise the minimum move frequency for the opening book, so as it gets weaker it will play very common lines but not know about less common ones (it also comes out of book earlier).

However, I am not really happy with the results. At low settings the randomness overwhelms the eval, so that it seems to lack even rudimentary chess knowledge. For example, it will walk the King out to the 3rd or 4th rank in the opening.

I'd like to have a "basic" and "advanced" eval and somehow keep the basic chess knowledge, like development and rudimentary king safety, while progressively reducing the more advanced stuff. That way at low levels it would play a bit more like a beginner who's had a few lessons but lacks sophisticated positional knowledge.

--Jon
The way I see it, the bulk of the playing strength of virtually all chess engines is their tactical strength, not their knowledge. To reduce their strength in a realistic way, tactical weakening is required.

It is a question of how to implement this in an intelligent and realistic way that produces a credible opponent for a human player. In this sense, it is probably wise to retain most of the knowledge and static eval and figure out how to consistently scale down the tactical vision to emulate human tactical strength/weakness (at various levels).

A bad way of doing this would have the engine play reasonably strong for most moves, but with some horrible obvious blunders interspersed. The only time such blunders should occur is in severe time trouble.

CL
carldaman
Posts: 2283
Joined: Sat Jun 02, 2012 2:13 am

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by carldaman »

kbhearn wrote:I'd suggest overall if you want to make an engine that feels like a real opponent you might want to start from the ground up with that in mind rather than making a strong engine in mind. Give it closer to human limitations, stick to those limitations, and as it'll already be quite weak at that point the question will be how to make it strong enough to be a good opponent rather than how to make it make human mistakes.

I'd start with allowing it to look at say no more than 10-20 positions per second. This will immediately rule out exhaustive search as an option and put an appropriate amount of emphasis on speculative pruning and pattern matching for a human-like search and bringing the right type of errors where overlooked moves are overlooked for a reason (such as they were atypical or the position was too complicated to look at all the important moves) and attempts to tweak evaluation for personality parameters are more likely to result in significantly different play as the scope of the search isn't so large as to tactically compensate for the misevaluations.
Interesting thoughts, Kevin.

I also think some knowledge that the typical human player has must also be present in the engine itself, or else it won't be a realistic opponent. Human players like to make necessary thematic moves, and build plans around such ideas, so a realistic eval should also be strong enough to detect those. Where the average human is quite poor is in the tactical and calculation/execution areas. They can see a plan, but not execute it properly. Of course, average players don't have the deep positional understanding of human masters, but then again, neither did most top engines, until recently!

Traditionally, the engines' strength is built primarily on tactics, which comes from search, so to emulate a human player we must have the priorities reversed and have search be crippled and take a back seat to evaluation based on chess knowledge.

I've always wanted to see an engine that could simply play stubbornly, attempting to carry out plans even if they didn't work. Normally, the inherent tactical strength of normal engines does not allow this. So, I think a realistic human-emulator must be crafted differently from the outset, with an emphasis on evaluation and chess moves generated based on what *looks* good in view of it, rather than on what works tactically based on deep calculation.

Don't most humans make moves because they just "look right" to them, and not necessarily because they're absolutely sound? Likewise, a human-emulator should play in a similar fashion. Each move should have a knowledge-based purpose first, with tactical soundness a secondary factor, and be heavily weighted towards the former.

Regards,
CL
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by Ferdy »

Jesse Gersenson wrote:At the very least, analyze 50-100 human games in the strength range you would like your engine to play.

For players in the 400-800 elo range, for example, you'll find they:
  • - show favoritism towards moving pawns or queen
    - don't know about en passant
    - don't know about pawn promotion
    - don't play for mate
    - rarely castle
    - will move the same pieces several times during the 'opening'
    - try to attack before their pieces are developed
    - 'giving check' is often favored over normal moves. it's as though they get points each time they give check.
Nice ideas too. It is interesting to implement.
Ferdy
Posts: 4833
Joined: Sun Aug 10, 2008 3:15 pm
Location: Philippines

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by Ferdy »

carldaman wrote:
jdart wrote:In my engine I slow the speed (thus cutting depth) and randomize the eval. In addition I raise the minimum move frequency for the opening book, so as it gets weaker it will play very common lines but not know about less common ones (it also comes out of book earlier).

However, I am not really happy with the results. At low settings the randomness overwhelms the eval, so that it seems to lack even rudimentary chess knowledge. For example, it will walk the King out to the 3rd or 4th rank in the opening.

I'd like to have a "basic" and "advanced" eval and somehow keep the basic chess knowledge, like development and rudimentary king safety, while progressively reducing the more advanced stuff. That way at low levels it would play a bit more like a beginner who's had a few lessons but lacks sophisticated positional knowledge.

--Jon
The way I see it, the bulk of the playing strength of virtually all chess engines is their tactical strength, not their knowledge. To reduce their strength in a realistic way, tactical weakening is required.

It is a question of how to implement this in an intelligent and realistic way that produces a credible opponent for a human player. In this sense, it is probably wise to retain most of the knowledge and static eval and figure out how to consistently scale down the tactical vision to emulate human tactical strength/weakness (at various levels).

A bad way of doing this would have the engine play reasonably strong for most moves, but with some horrible obvious blunders interspersed. The only time such blunders should occur is in severe time trouble.

CL
Tactics can be weakened by not allowing it to search deeper, and this is one of the easiest way to do and easy to scale as well. Another way is by ruining the eval to make the search inefficient and inconsistent. I have to say which I forgot to mention in my first post, that one of the methods that I use is by consistently changing the material piece values. As the set rating is lowered the queen, rook, bishop and knight values will approach the value of a pawn.
PK
Posts: 893
Joined: Mon Jan 15, 2007 11:23 am
Location: Warsza

Re: How to dumb down/weaken/humanize an engine algorithmical

Post by PK »

HGM has recently posted a code of NEG - an engine that doesn't search at all. It knows enough to capture enemy pieces, to escape when a piece is threatened and to promote pawns, but that's about all. I wonder what could be achieved by investing serious programming effort into such engine, then adding shallow search to moves that static engine considers critical. Perhaps this is the way to go if one is serious about emulating a weak player.