AI offer/agree to a draw like a human?

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

AI offer/agree to a draw like a human?

Post by zulban »

Hello again folks. I'm wondering how I might program my AI whether to agree to draws when the human offers one. I'm not asking about detecting repetition draws or insufficient material draws, that is done.

Cases
I can think of four cases:
* This game is not progressing, it is boring lately, I agree to draw.
* I am losing badly so I happily agree to draw.
* The game is not progressing, though I'm doing very well, so I'd like to see it "not progressing" for longer before agreeing to draw.
* I'm doing badly, but this board design is so wild that scores are jumping all over the place. I refuse the draw because maybe things will work out.

Challenges
The wiki "draw" article is pretty limited for the human-like aspect of this. Another challenge is that for my game ChessCraft the player can create custom pieces and boards with custom rules. So there may be many pieces, few pieces, only ultra-powerful pieces, only weak pieces, or uneven sides.

Image

So in classic chess, you might say that being down 10 material points is terrible, but it's not necessarily so bad if there are 10 queens. Similarly, being down 2 points might be terrible in ChessCraft.

So basically I am working with score histories from my AI search. Here's a game that starts slow but white starts stomping black:
  • 1.572396,
    1.457698,
    1.482192,
    1.457529,
    -0.01120018,
    0.02255237,
    0.08746424,
    0.02937162,
    0.004312338,
    -7.144287,
    8.145383,
    11.46157,
    4.705821,
    15.12602,
    24.7927
For my own convenience, these are only the scores when it's the computer's turn to play, which is likely enough to solve this problem.

I've been considering using values like "standard deviation of first 5 scores" and "standard deviation of most recent 5 scores" and "material score of board with only white pieces" and "percentage of material score that white still has from start" etc.

My Attempts
So far I have a rule like:
  • recentStd = standard deviation of 5 most recent scores
    std = standard deviation for entire history
    if (no recent captures) and (recentStd < std / 5) then agree to draw, uneventful game
However the other cases elude me. Anyone have thoughts or resources on human-like draw accepts for a computer AI?

Thanks :)
Dann Corbit
Posts: 12538
Joined: Wed Mar 08, 2006 8:57 pm
Location: Redmond, WA USA

Re: AI offer/agree to a draw like a human?

Post by Dann Corbit »

No-brainer draw offers:
1) You think you will lose and it is not apparent yet
2) You have a proven draw by TB search

No progress draws can be very tricky. I have seen SF give a static score for 15 plies and then suddenly take off and earn a checkmate.
Of course, that is very rare.
Taking ideas is not a vice, it is a virtue. We have another word for this. It is called learning.
But sharing ideas is an even greater virtue. We have another word for this. It is called teaching.
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: AI offer/agree to a draw like a human?

Post by hgm »

I would think that the following two cases cover most events:

* Negative score. (Or at least below contempt.)
* Score did not significantly increase for 20 moves or so, and the reversible-move counter is running up.
Sesse
Posts: 300
Joined: Mon Apr 30, 2018 11:51 pm

Re: AI offer/agree to a draw like a human?

Post by Sesse »

Dann Corbit wrote: Fri Dec 07, 2018 6:25 am No-brainer draw offers:
1) You think you will lose and it is not apparent yet
2) You have a proven draw by TB search
2) sounds very dangerous against a human. There are tons of TB-drawn positions that are nearly impossible to hold for a human against a tablebase.
zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Re: AI offer/agree to a draw like a human?

Post by zulban »

You have a proven draw by TB search
If you mean endgame table, can't do that. The player can create boards and change how pieces move and immediately play the AI. I can only do a few seconds of mobile pre-computation.
negative score
This is not a "human-like" draw heuristic. If you're playing a friend for fun, do you immediately agree to a draw any moment you sense you are doing slightly bad? Seems lame.
Score did not significantly increase for 20 moves or so
Easily said. Maybe I wasn't clear enough, but I am struggling to quantify "significantly increase". I don't know in advance what "wildly fluctuating score" means mathematically, statistically.

Thanks for the input so far :o
Alexander Schmidt
Posts: 1203
Joined: Thu May 10, 2007 2:49 pm

Re: AI offer/agree to a draw like a human?

Post by Alexander Schmidt »

Dann Corbit wrote: Fri Dec 07, 2018 6:25 am No-brainer draw offers:
1) You think you will lose and it is not apparent yet
2) You have a proven draw by TB search

No progress draws can be very tricky. I have seen SF give a static score for 15 plies and then suddenly take off and earn a checkmate.
Of course, that is very rare.
I think it is not about the best performance but about to be a fair opponent for humans.

So I won't offer a draw when losing. The human opponent will recognize this behavior and decline draw offers. And for humans it would be very nice to see a draw offer by the engine instead of playing 50moves where the engine shuffles the pieces and waits for a human mistake. In that case the human will anyway "adjust" the game and will not play the engine again.

Offer a draw when you think it is a draw, or if you think you are in front but can't make progress.

Wait for and accept a draw offer when you are behind or slightly in front in endgames, resign early. Implement some endgame knowledge about drawish endings.
User avatar
hgm
Posts: 27789
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: AI offer/agree to a draw like a human?

Post by hgm »

zulban wrote: Sat Dec 08, 2018 3:08 amThis is not a "human-like" draw heuristic. If you're playing a friend for fun, do you immediately agree to a draw any moment you sense you are doing slightly bad? Seems lame.
I would accept a draw if he offers one... 'Contempt' is the usual solution for the 'slightly' problem. When you are behind it is embarrassing to offer a draw anyway. Unless you think it should be clear to the opponent that he did not and cannot make progress. But that belongs to the other case.
Easily said. Maybe I wasn't clear enough, but I am struggling to quantify "significantly increase". I don't know in advance what "wildly fluctuating score" means mathematically, statistically.
Well, I don't know what engine you are using, but wildly fluctuating scores are not usual in quiet positions with conventional engines. The root position has a certain static evaluation (and if it is not quiet this could be replaces by the Quiescence-Search score), and if no progress can be made deeper searches should produce scores that are very similar. A transposition table would mask the low-depth evaluations, but these would have appeared as root scores a few moves earlier in the game.

You should have an idea of what the draw margin is in the game you are playing, but it doesn't seem unreasonable to require specification of that in the game definition. The reversible move counter is a measure of (lack of) progress, and many engines taper the evaluation score gradually towards a draw when it gets above a certain value. If you do that the score should even start decreasing for a strong side that fails to make progress, and build in a drive to go for non-reversible moves. As long as the score over (say) 20 moves spans a range of more than 30% of the draw margin things are still happening, and if the total score is above the draw margin it seems reasonable to suppose that you can still force a win.
corres
Posts: 3657
Joined: Wed Nov 18, 2015 11:41 am
Location: hungary

Re: AI offer/agree to a draw like a human?

Post by corres »

zulban wrote: Fri Dec 07, 2018 6:01 am Hello again folks. I'm wondering how I might program my AI whether to agree to draws when the human offers one. I'm not asking about detecting repetition draws or insufficient material draws, that is done.
Cases
I can think of four cases:
* This game is not progressing, it is boring lately, I agree to draw.
* I am losing badly so I happily agree to draw.
* The game is not progressing, though I'm doing very well, so I'd like to see it "not progressing" for longer before agreeing to draw.
* I'm doing badly, but this board design is so wild that scores are jumping all over the place. I refuse the draw because maybe things will work out.
...
When chess programs will be "human thinking simulators" they will recommend draw as a human.
zulban
Posts: 36
Joined: Sun Apr 08, 2018 6:23 pm

Re: AI offer/agree to a draw like a human?

Post by zulban »

The reversible move counter is a measure of (lack of) progress, and many engines taper the evaluation score gradually towards a draw when it gets above a certain value.
This is a good idea, I'll try that. The reversible move counter can gradually lower the threshold for draws.

I'm using my own engine - I kind of have to since the player can make custom pieces and boards. When you say "fluctuate wildly" you're actually making a lot of assumptions. Take for example this series of scores from a hypothetical stockfish game:

0.04
-0.1
0.01
-0.09

You might say that is fairly static. Well what if we multiply all values by 10:

0.4
-1.0
0.1
-0.9

Now you might say the game is fluctuating a fair bit. The reason we think this is we're assuming these are classic chess scores. You're also assuming "0" is neutral - which makes sense in classic chess since both sides start fairly even.

Whereas with mine, a change of "1" might be fairly static in one game, but in a completely different piece/board design, "0.1" might be fluctuating wildly. That's my problem, I can't use classic chess assumptions. I need some kind of statistical measure based on the scores of the game so far. Thus my attempts with standard deviations, etc.

Still trying to work it out...
Pio
Posts: 334
Joined: Sat Feb 25, 2012 10:42 pm
Location: Stockholm

Re: AI offer/agree to a draw like a human?

Post by Pio »

zulban wrote: Sat Dec 08, 2018 10:45 pm
The reversible move counter is a measure of (lack of) progress, and many engines taper the evaluation score gradually towards a draw when it gets above a certain value.
This is a good idea, I'll try that. The reversible move counter can gradually lower the threshold for draws.

I'm using my own engine - I kind of have to since the player can make custom pieces and boards. When you say "fluctuate wildly" you're actually making a lot of assumptions. Take for example this series of scores from a hypothetical stockfish game:

0.04
-0.1
0.01
-0.09

You might say that is fairly static. Well what if we multiply all values by 10:

0.4
-1.0
0.1
-0.9

Now you might say the game is fluctuating a fair bit. The reason we think this is we're assuming these are classic chess scores. You're also assuming "0" is neutral - which makes sense in classic chess since both sides start fairly even.

Whereas with mine, a change of "1" might be fairly static in one game, but in a completely different piece/board design, "0.1" might be fluctuating wildly. That's my problem, I can't use classic chess assumptions. I need some kind of statistical measure based on the scores of the game so far. Thus my attempts with standard deviations, etc.

Still trying to work it out...
I am fairly sure that when he wrote score he meant win probability.