Xiangqi chase - again

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Xiangqi chase - again

Post by Evert »

I implemented a Xiangqi chase algorithm in Sjaak (specifically, a slightly modified version of the one discussed here: http://www.talkchess.com/forum/viewtopic.php?t=41110). It seems to work fine, although just to be safe Sjaak doesn't claim in case the opponent makes what it would consider an illegal chase, just in case the GUI doesn't agree (if it did, it probably would not have sent on the move anyway). Of course, that may mean that Sjaak will now try to avoid the repetition, which probably implies dropping a piece and losing the game anyway.

Anyway, that's not what I wanted to bring up. Given that detecting and resolving the chase is relatively expensive (with having to unwind the move stack and detecting threats for both sides; the upshot is that it should be relatively rare as well) I'm wondering of the one or two other people on here who have ever looked at making a Xiangqi engine have considered hashing the detected chases, so that when the position occurs again in another part of the tree (or we try this same sequence of moves again later) we can simply re-use the result.

Worth it? Not worth it? Too unreliable, given that the chase stuff is all very path dependent?
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Xiangqi chase - again

Post by hgm »

Evert wrote:Of course, that may mean that Sjaak will now try to avoid the repetition, which probably implies dropping a piece and losing the game anyway.
I don't get that. If Sjaak thinks the opponent is chasing, it should thing continuing to repeat would be winning. Recognizing the chase should encourage it to persist in chases that it considders losing for the opponent. Even when it does not claim.

In HaQiKi D I also do not claim in the root, because it is not only a mater of identifying the chase properly, but there also must be some minimum number of repeats before you are allowed to claim. (I forgot whether this is 3 or 4.) So you cannot claim before the Nth repeat, although the engine already judges the repeat the first time it returns to the node.
I'm wondering of the one or two other people on here who have ever looked at making a Xiangqi engine have considered hashing the detected chases, so that when the position occurs again in another part of the tree (or we try this same sequence of moves again later) we can simply re-use the result.
I have never considered that, and am not even sure how to do it. A chase is not a property of the position, but of the path leading to it, just like a repetition in FIDE. In HaQiKi D I reduced the cost by only doing it when the remaining depth is above a certain value (like 4, IIRC).

It is true that determining if something is a chase can be expensive, but chases are not that common in the tree. To be able to repeat a position you must search it at least 4 ply. Only a few leaves of that 4-ply tree will end up back in its root position.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Xiangqi chase - again

Post by Evert »

hgm wrote: I don't get that. If Sjaak thinks the opponent is chasing, it should thing continuing to repeat would be winning. Recognizing the chase should encourage it to persist in chases that it considders losing for the opponent. Even when it does not claim.
I think you're right. I was trying to reconstruct what would happen without thinking it entirely through.
In HaQiKi D I also do not claim in the root, because it is not only a mater of identifying the chase properly, but there also must be some minimum number of repeats before you are allowed to claim. (I forgot whether this is 3 or 4.) So you cannot claim before the Nth repeat, although the engine already judges the repeat the first time it returns to the node.
I think it's 3 (and the 4 is for Shogi, if I recall correctly) but that doesn't matter much. This is another issue, which of course also shows up in normal chess. Sjaak does a test before it calls search to see if the game is "over", and there it does the 3-fold repetition accurately.
I have never considered that, and am not even sure how to do it. A chase is not a property of the position, but of the path leading to it, just like a repetition in FIDE. In HaQiKi D I reduced the cost by only doing it when the remaining depth is above a certain value (like 4, IIRC).

It is true that determining if something is a chase can be expensive, but chases are not that common in the tree. To be able to repeat a position you must search it at least 4 ply. Only a few leaves of that 4-ply tree will end up back in its root position.
My original idea was by analogy of the "banmoves" command in UCCI (which I completely ignore, which I guess runs the risk of having the game forfeit if I would end up playing one of the "banned" moves), but I guess the concerns there (that it's too simplistic to handle chases that way) would still apply here.

What could be stored quite easily is the detection of what pieces are threatened (and possibly what pieces are threatening), but that information by itself I think is only enough to rule out that one side is chasing (if it has no threats, it is not chasing).

How exactly can you avoid doing the chase-detection in the last 4 ply? I only do it if the repetition table (and game history) indicate that the position has actually been repeated, but when a repetition does occur I always test for a chase. What do you do for a repetition that occurs in the last 4 plies? Just allow it?
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Xiangqi chase - again

Post by hgm »

Evert wrote:What do you do for a repetition that occurs in the last 4 plies? Just allow it?
The same what should happen if it turned out not to be a chase: evaluate it as draw.

I haven't really measured if this costs any Elo. In a test between a version of HaQiKi D with chase detection (from 4 ply on) and one evaluating every repetition as draw 18% of the games ended in a forfeit. But as it typically is the losing side that chases (if he thinks it will mean draw)it seems reasonable to assume that about half of them would have been lost anyway. So we are talking about 9% of the games that turn a draw into a forfeit, i.e. lose half a point. So by being completely chase unaware you score 4.5% less, i.e. some 30 Elo. That is all there is to earn, if there was no slowdown at all. Now if you never actually forfeit, and are only not able to foresee chases when they start more than 4 ply from now (when you search 12 ply), it must cost you only a quite small fraction of that.