Evaluation in Xiangqi

Discussion of chess software programming and technical issues.

Moderators: hgm, Dann Corbit, Harvey Williamson

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

Evaluation in Xiangqi

Post by hgm »

What makes Xiangqi fundamentally different from international Chess is that 3 of the 7 piece types, including the King, are confined to their own half of the board (or even a sub-set thereof, but that is of no import here). They can thus only be used in defense. As a consequence, even the material evaluation cannot simply add fixed piece values: if you have more defenders than you would need to hold off the opponent pieces that can cross into your board half, the surplus is basically worthless. In particular, when the opponent has no attacking material left, all your defenders are useless.

Naive evaluations might think it is an equal deal to (indirectly) trade one defender for another if you are, say, Rook vs Pawn behind, but in fact this is losing, as 3 defenders will succumb to a Rook (and the Pawn will eventually get lost), while 4 defenders would keep you safe. While the opponent would not even need a single defender to guard his King from your Pawn, as long as he has the Rook to avoid zugzwang (and thus stalemate, which in XQ is a win).

So one would have to use a fundamentally different way to evaluate the material imbalance. So far my own engine was using a method that valued the defenders by how much attacking material the opponent has. But during the ICGA tournament this proved unsatisfactory, as one also has to judge the value of Pawns. These can be used for little else than attack (as they already start pretty far forward). But if the attack is futile, given the number of defenders the opponent has, the Pawn becomes practically useless. The engine would make the (losing) mistake of not wanting to trade his own promoted (but futile) Pawn for the opponent's yet unpromoted Pawn that makes all the difference considering your lack of defensive material.

So I was thinking of making a 'dual' evaluation, which for each side would express the risk to its King by the material present. This would involve the defenders of side A, the Pawns of side B and the 'ergodic' pieces that can cover the entire board. If the defending side has the upper hand with this material, the score given to it should saturate, so that no value is attached to having even more defensive material. The evaluations for the two sides can then be subtracted.

This is not completely trivial, however, because the ergodic material participates in both evaluations. Say you have 2 Horses and 2 defenders, and the opponent has a Rook and 2 defenders. Your two defenders cannot hold off the Rook, so you will need at least one of the Horses to prevent from being overwhelmed. For the opponent, his two defenders are not enough to hold off 2 Horses, so you might think he now needs the Rook to help his defense. But when one of your Horses is tied up to your own defense, it cannot be used in the attack. So when he is attacking with his Rook, you effectively have only a single Horse for the attack, and the 2 defenders keep him safe from that.

So one has to be careful to divide the ergodic material into defenders and attackers. A guidence for this could be that attacking is in general more profitable than defending in XQ. So that if there are multiple solutions (e.g. in the presented case, use the Rook in defense and allow his two Horses to attack, or use the Rook in attack to tie up one of his Horses in defense), the most attacking solution is preferable. There also seems an important difference between quite mobile pieces like Rook and Canon, which can switch from attack to defense in a single move,or indeed do both at the same time, and short-range Horses, which need several moves to cross the board, and thus have to be dedicated to either attack or defend.