Any Xiangqi programmers out there?

Discussion of chess software programming and technical issues.

Moderator: Ras

User avatar
hgm
Posts: 28359
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Any Xiangqi programmers out there?

Post by hgm »

I have some difficulty understanding the handling of repetitions in Xiangqi. For one, not all sources seem to give the same rules: At http://www.zonzab.co.uk/xiangqi_rules.html it says for instance that perpetual mate threats and combination of checks and attacks on other pieces are forbidden, while http://www.clubxiangqi.com/rules/asiarule.htm say that these are draws.

Now the second source looks more official, but the rules it presents are actualy a lot more incoherent than those mentoned n the first source. Is there actually agreement on the exact rules of Xiangqi?

Another question is how to implement rules like this in an engine. Would the following approach be satisfacory?

When the search encounters a repeated position, it examines all moves that led from the previous occurence to the current one, to determine which pieces were attacked by the moves of either side. Then it computes (for each side) the intersection of these piece sets. If this intersection is non-empty for both, or empty for both, the node is scored as a draw. If the intersection is non-empty for only one side (meaning one or more of its pieces have been chased throughout the repetition loop), this side wins.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Re: Any Xiangqi programmers out there?

Post by sje »

The rules of Xiangqi vary from place to place. Since the game has appeared in a number of computer tournaments like the Computer Olympiad, you might want to see which rules (and notation system) were in use.

http://en.wikipedia.org/wiki/Xiangqi

It may be the case that a commercially successful Xiangqi program will need to play by any of several different sets of rules.
NowCan
Posts: 7
Joined: Mon Aug 13, 2007 10:16 am

Re: Any Xiangqi programmers out there?

Post by NowCan »

At http://www.zonzab.co.uk/xiangqi_rules.html it says for instance that perpetual mate threats and combination of checks and attacks on other pieces are forbidden

This is the Chinese rule.

while http://www.clubxiangqi.com/rules/asiarule.htm say that these are draws.

It's Asia rule.

For computer, Chinese rule is more difficult, especially perpetual mate threats. So, ICGA use Asia rule.
TonyJH
Posts: 183
Joined: Tue Jun 20, 2006 4:41 am
Location: USA

Re: Any Xiangqi programmers out there?

Post by TonyJH »

I had the same difficulty, so my xiangqi engine doesn't handle this problem very well -- it just avoids repetitions by assuming the repetition is always losing for itself. So, at least it shouldn't forfeit games because of its lack of understanding of perpetual chase.
Therefore my engine doesn't adjudicate (or detect) perpetual chase, but it detects and adjudicates perpetual check.

FYI: Qianhong uses its own xiangqi protocol (which I don't use) that I believe uses a command "BAN" to handle this. (See here). For this to work, the GUI has to be smart enough to enforce all of the repetition rules, and the engines don't really need to. Although the engines probably should understand them as well, if they intend to play at a high level.

Then again, if every xiangqi engine tries to implement all of the complex rules related to repetition, I wouldn't be surprised if the engines will still have disagreements in many cases..
User avatar
hgm
Posts: 28359
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Any Xiangqi programmers out there?

Post by hgm »

Indeed, even te Asia rules, despite their 40-rule description, seem very ambiguous to me. Especially "Mate Threat". From the examples, this actualy seems to include any mate-in-N. But f you are in a heavily won position, eventual mate is of course always unavoidabe, although it might take far longer to prove it than plying out the game. Or do longer mates only count if the opponent is checked on every move long the path except the first? Perhaps this is a moot point, because it only decides if the game is drawn or lost to the side threatening mate, and neither of those results is acceptable anyway in a heavily won position.

I did not study the Asian rules carefully enough yet to know if there ever was a situation where a mate threat woud be treated differently from an "idle" move (= not attacking or threatening to attack anything). If this is not the case (and I suspect this), the whole mate-threat concept could be eliminated from the rule set. It might be mentioned only to highlight the difference with Chinese rules, where t is a necessary concept (because perpetual mate threatsare forbidden there), clarifying things for people used to playing Xiangqi under Chinese rules, but thereby obfuscating things for ignorant Western-Chess players like me...

Perhaps we should design our own set of "EuroAmerican rules"? The one TJxiangqi is using now, "He who brings about a repetition loses", seems a bit of an over-simplification to capture the spirit of the game, as I suspect it could be abused to win endings with insufficient mating material but so few pieces that repetitions are unvoidable. (E.g. against a bare King.) How about "He who brings about a repetition through a move that creates a L x H attack or an attack on an undefended piece or an attack on an equal pinned piece loses, unless the move resolves such an attack on an equal or even higher piece"? (Repeats that do not lose through some explicit rule are draws.)

The simplification would be that all the conditions can be checked on the current move and the position in which it was made. It is not exactly the same as Asian rules, as it would also forbid chasing multiple pieces by one. But my guess is that Asian rules only allow this becase it almost never happens in practice.
Michel
Posts: 2292
Joined: Mon Sep 29, 2008 1:50 am

Re: Any Xiangqi programmers out there?

Post by Michel »

I can't help finding this thread very amusing. Is this a difference between Western and Eastern thinking?

Sorry for not being able to make a useful contribution. :(