help from Bob please

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

lauriet
Posts: 199
Joined: Sun Nov 03, 2013 9:32 am

help from Bob please

Post by lauriet »

Hi bob, Im asking you because i believe you have probably thought and tried everything.......
I dont want to do legal move gen.
I dont want to do in_check in search.
I want to just let the king be captured (like any other piece) and search will return a score of -10000 cp say.
The problem is the program will then swap off kings if it can, and just keep playing.
Do you have any comments on how this could be implemented elegantly ?

Thanks
Laurie
JVMerlino
Posts: 1357
Joined: Wed Mar 08, 2006 10:15 pm
Location: San Francisco, California

Re: help from Bob please

Post by JVMerlino »

lauriet wrote:Hi bob, Im asking you because i believe you have probably thought and tried everything.......
I dont want to do legal move gen.
I dont want to do in_check in search.
I want to just let the king be captured (like any other piece) and search will return a score of -10000 cp say.
The problem is the program will then swap off kings if it can, and just keep playing.
Do you have any comments on how this could be implemented elegantly ?

Thanks
Laurie
Well, I'm not Bob, and I have to make some assumptions about what you are describing, but I believe I can give a reasonable answer, which is that "swapping off kings" is only one of several bad side-effects of your plan.

One is that, over the course of your search, it sounds like one King could be put in check, and the other side could respond by putting the OTHER King in check. You then "capture" the first King and return -CHECKMATE, but by an invalid series of moves. Also, would this returning of -CHECKMATE happen in the search or in the eval?

Another problem is that the Kings could actually move next to each other! Then what???

Essentially, when you reach the tips of your search tree and need to evaluation the position (and therefore that entire branch), your score will be useless if you have arrived at that tip by one or more illegal moves.

But ultimately it is your engine and you are of course free to implement anything you wish. I think, however, that your plan is fraught with danger and frustration.

jm
jdart
Posts: 4366
Joined: Fri Mar 10, 2006 5:23 am
Location: http://www.arasanchess.org

Re: help from Bob please

Post by jdart »

Another problem is that modern engines frequently do pruning before move generation. In the quiescence search this can always done via the "stand pat" test (for nodes where the side to move is not in check). So if the King can be captured but the node is just pruned, you don't know if the previous move was illegal. If you want to allow King captures and use that to detect illegal moves, you can do so, but then you need to still do some other kind of illegal move detection in cases where search at a node does not generate any moves.

--Jon
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: help from Bob please

Post by bob »

lauriet wrote:Hi bob, Im asking you because i believe you have probably thought and tried everything.......
I dont want to do legal move gen.
I dont want to do in_check in search.
I want to just let the king be captured (like any other piece) and search will return a score of -10000 cp say.
The problem is the program will then swap off kings if it can, and just keep playing.
Do you have any comments on how this could be implemented elegantly ?

Thanks
Laurie
If you make the king value big enough it won't happen. IE if you have your MATE score set to 10000 (or whatever) then set the king value to 100000. Now the score for that side will always be outside any possible alpha/beta window and the search will stop.

But it is much more effective, if you want to search this way, to put a special exit in your move generator. If, at any time, you generate a move that captures the opponent's king, return that special value which would tell you "move at previous ply was illegal, don't accept the score or anything, pretend it never happened."
JVMerlino
Posts: 1357
Joined: Wed Mar 08, 2006 10:15 pm
Location: San Francisco, California

Re: help from Bob please

Post by JVMerlino »

bob wrote:
lauriet wrote:Hi bob, Im asking you because i believe you have probably thought and tried everything.......
I dont want to do legal move gen.
I dont want to do in_check in search.
I want to just let the king be captured (like any other piece) and search will return a score of -10000 cp say.
The problem is the program will then swap off kings if it can, and just keep playing.
Do you have any comments on how this could be implemented elegantly ?

Thanks
Laurie
If you make the king value big enough it won't happen. IE if you have your MATE score set to 10000 (or whatever) then set the king value to 100000. Now the score for that side will always be outside any possible alpha/beta window and the search will stop.

But it is much more effective, if you want to search this way, to put a special exit in your move generator. If, at any time, you generate a move that captures the opponent's king, return that special value which would tell you "move at previous ply was illegal, don't accept the score or anything, pretend it never happened."
As far as I can tell, this wouldn't solve the "kings moving next to each other" problem. A search without legal move detection AND without checking to see if a move gives check would explode with illegal moves/positions, wouldn't it?
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: help from Bob please

Post by bob »

JVMerlino wrote:
bob wrote:
lauriet wrote:Hi bob, Im asking you because i believe you have probably thought and tried everything.......
I dont want to do legal move gen.
I dont want to do in_check in search.
I want to just let the king be captured (like any other piece) and search will return a score of -10000 cp say.
The problem is the program will then swap off kings if it can, and just keep playing.
Do you have any comments on how this could be implemented elegantly ?

Thanks
Laurie
If you make the king value big enough it won't happen. IE if you have your MATE score set to 10000 (or whatever) then set the king value to 100000. Now the score for that side will always be outside any possible alpha/beta window and the search will stop.

But it is much more effective, if you want to search this way, to put a special exit in your move generator. If, at any time, you generate a move that captures the opponent's king, return that special value which would tell you "move at previous ply was illegal, don't accept the score or anything, pretend it never happened."
As far as I can tell, this wouldn't solve the "kings moving next to each other" problem. A search without legal move detection AND without checking to see if a move gives check would explode with illegal moves/positions, wouldn't it?
If one king moves next to the other, on the next ply one of the moves you generate will capture that king. Marking the move at the previous ply as illegal.
User avatar
hgm
Posts: 27792
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: help from Bob please

Post by hgm »

bob wrote:If you make the king value big enough it won't happen. IE if you have your MATE score set to 10000 (or whatever) then set the king value to 100000. Now the score for that side will always be outside any possible alpha/beta window and the search will stop.
Yes it would. Because beta cutoffs only occur after you searched the move, and are based on the score accumulated during all subsequent plies. So no matter how valuable the King, when you let it be captured but then capture the opponent King in retalliation, the move will score close to zero, and not cause any cutoffs.

It is essential you do not search any replies to a King capture.
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: help from Bob please

Post by bob »

hgm wrote:
bob wrote:If you make the king value big enough it won't happen. IE if you have your MATE score set to 10000 (or whatever) then set the king value to 100000. Now the score for that side will always be outside any possible alpha/beta window and the search will stop.
Yes it would. Because beta cutoffs only occur after you searched the move, and are based on the score accumulated during all subsequent plies. So no matter how valuable the King, when you let it be captured but then capture the opponent King in retalliation, the move will score close to zero, and not cause any cutoffs.

It is essential you do not search any replies to a King capture.
That was the point of my second sentence. Pesudo-legal moves have to be caught when they leave the king hanging.
User avatar
hgm
Posts: 27792
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: help from Bob please

Post by hgm »

Well, they can be caught when you capture the King. And it is highly advisable to detect this before you search any moves. Old versions of micro-Max did not do this, and this broke stalemate detection: when in a position where King capture was possible anothermove produced a beta cutoff before the King capture was seen, it returned a score above beta, but lower than +INF. So in the parent node it was not detected that the move was illegal, although it would fail low.

If all moves fail low, the node fails low. But if all moves fail low with -INF score, it means you could be stalemated, which would make the node score 0, which could fail high!

The current version of micro-Max first loops through all moves at depth 0 (i.e. without any reply) temporarily increasing beta to +INF, so that only a King capture can cause a beta cutoff. (Other moves 'score' their MVV/LVA sort key, so that when no King capture is possible, the MVV/LVA-wise best move will be searched first in the next depth iteration, where beta will be restored to its original value.)
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: help from Bob please

Post by Michael Sherwin »

In RomiChess I do pseudo move generation. RomiChess calls the move generator like this.

if(MoveGen()) return mate;

Then in the move generator.

case WKING:
h->moves[id] = king[fs] & notMe;
h->attacked |= king[fs];
continue;
case WLEGAL:
if(bKings & h->attacked) return ILLEGAL; // TRUE;
continue;

So I just accumulate all the attacked squares into a bitboard and do the test for legality as the last step and return ILLEGAL. Then the call to the move generator returns mate.

Does this sound okay or can there be problems?
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through