Xiangqi evaluation function

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Xiangqi evaluation function

Post by Greg Strong »

So I really have no idea what the evaluation function in a Xiangqi engine should look like. From my Chinese Chess book, I have taken the material values it suggests:

Rook 9
Cannon 4.5
Knight 4
Counsellor 2
Minister 2
Pawn 1 (increased to 2 after crossing the river)

I have guesses for piece-square-tables for some pieces... Rook and Cannon slightly more valuable in the three center files that oppose the enemy castle. Knight more valuable in the center of the board and attacking the castle. Pawn more valuable crossed the river and attacking the enemy castle.

But that's about all I've got. Maybe Rooks get a bonus for being on an open file? Cannons on semi-open file? Or, since the pawn rank is so thin, maybe there's no point to these.

Any insight into evaluating in Xaingqi is much appreciated.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Xiangqi evaluation function

Post by hgm »

Pawns and Knights should be aggressively drawn towards the opponent Palace. A Pawn on e8 can be worth ~3. You could devaluate Cannon in the late end-game; eventually it will become less valuable than Horse, if you have not much material left to act as platform. (Especially when the Rooks are gone.)

Defensive pieces (Advisors + Elephants) derive their value purely from the presence of attacking material of the opponent. E.g. in KHKAAEE black is not ahead, as white is the only one that still has mating potential (the defence is too strong, though, to win in practice). You want to prevent the engine converts a +8 advantage in KHHAAEEKHAA to KAAEEK rather than KHHKAAEE, and you want to discourage black to trade A in KHHAAKHAA.

In the middle-game the only good place for the King is e0, where it does not obstruct Advisor movement. Leaving the back rank is very bad. Pile up A and E in front of it. Do not let these get pinned by a Cannon, so they keep defending the A and E on the back rank.

Cannons are very dangerous on the central file and back rank. Rooks on the 8th rank. (Especially on d8/f8, when the block the Elephants from defending each other. Batteries of C+R on the back rank are very dangerous.

Horses are very vulnerable to trapping, because they can be blocked. Edge and next-to edge squares are therefore very dangerous to them.

A Cannon sandwiched by opposing Rooks can be a real problem, as it can represent an unbreakable soft pin that in the end unavoidably will cost you a Cannon. Especially on the b- and h- file this can be a problem, as you don't have many pieces that can defend a Cannon there. To a lesser extent the same problem can occur along the third rank.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Xiangqi evaluation function

Post by hgm »

Oh, and do not allow an enemy Cannon to directly face your King when you are still flanked by your Advisors in the middle-game! This is very dangerous, and usually costs you at least a H or C, (if you don't get mated).
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Xiangqi evaluation function

Post by hgm »

And one more advanced issue: If the value of defenders goes up, the value of a Pawn approaching the Palace goes up similarly, as such Pawns will typically be traded for one (or two, if you are lucky) defenders.
User avatar
phhnguyen
Posts: 1437
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Xiangqi evaluation function

Post by phhnguyen »

Few suggestions for beginners that you may consider:

1) King tropism

Implement King tropism in Xiangqi is little easier than Western chess because a Xq King can move in a small area only. You need to build King tropism for short range attacking pieces Pawns and Horses only. For long range attacking pieces Cannons and Rooks it may not help much.

Some score tables can help you very well to implement King tropism.

2) Mobility
Mainly for Rooks and Horses.

A score table of the Horse can also help you to punish a Horse when it locates in the board border which would lose a half of its mobility.

3) King safety
If King stays in his original (start) position it is fine, punish if he moves out, heavily if he goes up any rank.

Bonus if one Advisor still stays in original position, one is up to the middle of Palace (but punish if over that point). Bonus for Elephants if one is up in front of King, one in original position.

One again, few simple score tables can help you too.

However, you may punish:
- When "eye" of elephants is blocked
- When opponent is still strong but one of Advisor or one of Elephant is lost because of future danger.

4) Opening development
Give heavy penalties if any Horse, Rook still stays in his start position.
Bonus if a Pawn in column c or g is up, give more change for Horse in its side (left or right) to attack later.

5) Attacking shape / number

Significant bonus when one Cannon is pinning King, Horse and Rook are near the opponent castle. A Pawn can also play the role of a Horse or a Rook if it is close enough to the King. Do extra bonus if:
- Other Cannon is also pinning or "facing" to that King (usually one attacks King by column, one by rank)
- Opponent defenders are not full
- King is not in start position. Special bonus when attacking pieces and that King are in the same side (left or right side)

I suggest you to download and study my VSCCP program (at http://xqfan.com) - it has been installed already some simple knowledge for evaluation.

Good luck and have fun with your Xiangqi program :D

/Pham
User avatar
Greg Strong
Posts: 388
Joined: Sun Dec 21, 2008 6:57 pm
Location: Washington, DC

Re: Xiangqi evaluation function

Post by Greg Strong »

Thanks a lot to both of you. This is very helpful. Much of this should be doable pretty easily... And I will definitely check out your program, Nguyen!

Cheers,
Greg
liuzy

Re: Xiangqi evaluation function

Post by liuzy »

phhnguyen wrote:Few suggestions for beginners that you may consider:

1) King tropism

Implement King tropism in Xiangqi is little easier than Western chess because a Xq King can move in a small area only. You need to build King tropism for short range attacking pieces Pawns and Horses only. For long range attacking pieces Cannons and Rooks it may not help much.

Some score tables can help you very well to implement King tropism.

2) Mobility
Mainly for Rooks and Horses.

A score table of the Horse can also help you to punish a Horse when it locates in the board border which would lose a half of its mobility.

3) King safety
If King stays in his original (start) position it is fine, punish if he moves out, heavily if he goes up any rank.

Bonus if one Advisor still stays in original position, one is up to the middle of Palace (but punish if over that point). Bonus for Elephants if one is up in front of King, one in original position.

One again, few simple score tables can help you too.

However, you may punish:
- When "eye" of elephants is blocked
- When opponent is still strong but one of Advisor or one of Elephant is lost because of future danger.

4) Opening development
Give heavy penalties if any Horse, Rook still stays in his start position.
Bonus if a Pawn in column c or g is up, give more change for Horse in its side (left or right) to attack later.

5) Attacking shape / number

Significant bonus when one Cannon is pinning King, Horse and Rook are near the opponent castle. A Pawn can also play the role of a Horse or a Rook if it is close enough to the King. Do extra bonus if:
- Other Cannon is also pinning or "facing" to that King (usually one attacks King by column, one by rank)
- Opponent defenders are not full
- King is not in start position. Special bonus when attacking pieces and that King are in the same side (left or right side)

I suggest you to download and study my VSCCP program (at http://xqfan.com) - it has been installed already some simple knowledge for evaluation.

Good luck and have fun with your Xiangqi program :D

/Pham
VSCCP, good job. But the evaluation function is too simple, even me can win easily, just like playing with a child.
User avatar
hgm
Posts: 27808
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Xiangqi evaluation function

Post by hgm »

I don't think the evaluation function carries most of the blame for that. The main weakness of VSCCP is its search depth (or rather, the lack of it). MaxQi has an even much simpler evaluation than VSCCP, but it beats it easily. (Well, you would probably beat MaxQi too, but it would be a lot tougher for you than VSCCP.)