Attack and mobility evaluation in chess variants

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

Attack and mobility evaluation in chess variants

Post by Evert »

I'm working on improving the evaluation function for my chess variant engine (mostly bugfixes at the moment, of which there are more than I would have hoped). One of the things I was playing around with is the mobility/king safety evaluation.

The king safety is a generalised form of Ed Schroder's algorithm, as described on his webpage (this may not be the most appropriate algorithm in general, but it's a starting point). For that, I need attack information on the zone around the king. That's easy to get (although there are some technicalities I won't go into).
In a normal chess program, I would re-use the information from the mobility evaluation. However, for chess variants, I can't in general assume that pieces move in the same way as they capture. A clear example is the cannon in Chinese chess, which moves as a rook, but needs to leap over an intermediate piece before it can capture. So the question becomes how to calculate mobility for such pieces: do I count the number of possible moves, or do I count the number of potential captures (attacked squares)?
As an extreme example, say I have a piece that moves as a queen and captures as a king. How do I score mobility for that piece?

Intuitively, I would say that what is important is the control over the board, the number of attacked squares (where you can quibble about whether you should include squares that have pieces on them, or count those in some other way). At the same time though, the ability to move a piece to a better position from where it can attack something has to be worth something too.

I'm starting to think that there are really two different aspects to mobility that are important, and I'm not sure how to weigh those two sensibly. A weighted average of mobility scores based on attacked squares and based on possible movement targets is probably the best approach. I wonder whether it would make sense to evaluate those two aspects separately for a normal chess engine would make sense too.

Anyway, any thoughts or suggestions on this matter?
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Attack and mobility evaluation in chess variants

Post by hgm »

I have never tried mobility evaluation, so none of what I am going to say is substantiated by experiment. But I have always had the feeling captures in normal Chess should not be counted as mobility. If they are good captures, it doesn't really matter if you count them or not, because the current evaluation will not determine the score of the node, but the capture will. If they are bad, they aren't really an option, so they should not be counted. Only the possibility to make an equal trade might be something, and it might actually be worth a lot. Mobility is all about creatng choice, with the statistical inevitability some of the choices will be good. Having one forcing move amongst your choices affectively doubles your options (do it with or without trade).

For divergent pieces I expect mobility to be determined by the moves you can actually make. That is what determines your number of choices. If attacking an empty square where you cannot move to helps much is not clear to me. It might restrict the opponent's choice, but this depends a ot on the value of the piece, and how many attacks there are on the square. A piece that moves as Q and captures as N (=mQcN) pretty much has always the same number of captures on a given square. Attacking opponent pieces, defending own pieces or covering empty squares all have some tactical value, so I would guess this can be included in the PST score with good accuracy. For non-captures, being blocked by an own piece renders the move completely useless, however. Not sure how it would work for capture-only sliders, though, where you can cover a variable number of empty squares, in addition to a single attack or defense.
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Attack and mobility evaluation in chess variants

Post by Evert »

hgm wrote:But I have always had the feeling captures in normal Chess should not be counted as mobility. If they are good captures, it doesn't really matter if you count them or not, because the current evaluation will not determine the score of the node, but the capture will. If they are bad, they aren't really an option, so they should not be counted. Only the possibility to make an equal trade might be something, and it might actually be worth a lot.
Right, I agree this makes sense.
The only counter point I would make is that even if a capture is not a good capture, the possibility of making it may still be worth something, especially in the case of a piece that has to be defended by more valuable pieces (weak pawns, pinned pieces). That's not mobility though, and would be more appropriate for some sort of general "positional weakness" evaluation, possibly with a progressive score as more of those weaknesses are present. Anyway, that's a different topic.
Mobility is all about creatng choice, with the statistical inevitability some of the choices will be good. Having one forcing move amongst your choices affectively doubles your options (do it with or without trade).

For divergent pieces I expect mobility to be determined by the moves you can actually make. That is what determines your number of choices. If attacking an empty square where you cannot move to helps much is not clear to me. It might restrict the opponent's choice, but this depends a ot on the value of the piece, and how many attacks there are on the square.
Ok, that's not what I said earlier, but I agree it makes sense: the reason good mobility is important is because good mobility makes it statistically more likely that one of the moves you have available is useful.

So in a sense, raw mobility scores (number of possible moves) are a very crude way to calculate this. What we're really interested in is having moves that threaten something, or put extra pressure on a weak point. It's not bad to have only a few moves available, as long as these are good moves.
I guess that's the general idea about scoring "forward mobility" higher than "backward mobility". It may be worthwhile to generalise that further and identify "hot spots" in the opponent's position that are worth attacking, then award some bonus for having more ways of doing that (and cumulatively if you can attack multiple weaknesses).
In a sense that's what king-safety evaluation does, the king being a very easy to identify "hot spot".

I'm going to think about that a bit more over the weekend, there may be something worth playing with for a normal chess program there as well.
User avatar
phhnguyen
Posts: 1434
Joined: Wed Apr 21, 2010 4:58 am
Location: Australia
Full name: Nguyen Hong Pham

Re: Attack and mobility evaluation in chess variants

Post by phhnguyen »

Evert wrote:...
In a normal chess program, I would re-use the information from the mobility evaluation. However, for chess variants, I can't in general assume that pieces move in the same way as they capture. A clear example is the cannon in Chinese chess, which moves as a rook, but needs to leap over an intermediate piece before it can capture. So the question becomes how to calculate mobility for such pieces: do I count the number of possible moves, or do I count the number of potential captures (attacked squares)?
As an extreme example, say I have a piece that moves as a queen and captures as a king. How do I score mobility for that piece?
...
For Cannons in Xiangqi, IMO, you may simply ignore their mobility. The most dangerous / useful situation of Cannons is to pin opposite King. Other main use is to defense, by blocking opposite attackers. Thus their mobility says almost nothing.
User avatar
hgm
Posts: 27790
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: Attack and mobility evaluation in chess variants

Post by hgm »

You have to be careful with that, because one of the positive effects of mobility evaluation is that it also helps to avoid trapping of pieces. So it depends a bit on how mobility is calculated; some implementations just count total moves, others put more weight on a penalty for if a certain pieces has an exceptionally low number of moves. E.g. it does not matter so much if your Rook has 10 or 12 moves. But whether it has 0 or 2 moves makes a heck of a difference. The mobility could even be considered one direction at a time. Having 2 moves in both X and Y direction for a Rook seems better than having 0 moves in X and 4 in Y.

In HaQiKi D I noticed that it is very dangerous to put a Cannon in a position where it has 0 moves in one dimension (like between two enemy Pawns). This creates a tactical vulnerability the opponent often exploits in some way at a later time, as a Rook attack along the ray that the Cannon is mobile on attacks all its escape squares at the same time.
lkaufman
Posts: 5960
Joined: Sun Jan 10, 2010 6:15 am
Location: Maryland USA

Re: Attack and mobility evaluation in chess variants

Post by lkaufman »

hgm wrote:I have never tried mobility evaluation, so none of what I am going to say is substantiated by experiment. But I have always had the feeling captures in normal Chess should not be counted as mobility. If they are good captures, it doesn't really matter if you count them or not, because the current evaluation will not determine the score of the node, but the capture will.
I don't understand this comment. When a normal program reaches quiescence, the side to move can accept the score, regardless of whether or not the opponent is threatening to take an unprotected or higher-valued piece. So it certainly is of great value to threaten pieces; they might be doomed, or at the very least a move will have to be spent to save them. Failing to count this for anything would be a clear error. Of course you can choose to score such attacks independently of mobility, but that's not what you say here. In my opinion attacks are in general worth MORE than empty squares you can move to.
Mincho Georgiev
Posts: 454
Joined: Sat Apr 04, 2009 6:44 pm
Location: Bulgaria

Re: Attack and mobility evaluation in chess variants

Post by Mincho Georgiev »

I've always considered mobility as "where you can actually go", which automatically adds the captures. It excludes only the squares taken by friendly pieces. I don't know if others think similar, but my testing results (unfortunately not available for posting anymore since it was while ago) shows that mobility it's clearly better, scored that way. Of course, I am always willing to hear opinions of others, I don't like 'the blind horse' approach, but the tedious testing of this just couldn't convince me that excluding capturing squares is better. I am talking about the conventional chess, don't have any idea if that applies to variants.
p.s. I am adding additional bonuses - bigger for the small center and smaller for the center when collecting mobility data (since i don't use bitboards extensively, piece loop is inevitable). Again, this is omitted only if friendly piece is there (captures stays). 25 Elo pts increase just from that one. Of cource it could be just because of a weight re-balancing caused by the square control values, but gain is there...
User avatar
Evert
Posts: 2929
Joined: Sat Jan 22, 2011 12:42 am
Location: NL

Re: Attack and mobility evaluation in chess variants

Post by Evert »

I think it may be useful conceptually to split "mobility" up into a number of distinct but related concepts (apologies if these terms are non-standard):

Manoeuvrability - all legal non-captures a piece can make.
Board control - all empty squares where an enemy piece that moves there could be captured.
Tension - the ability to capture an enemy piece.

Clearly, for normal chess pieces (except for pawns), manoeuvrability and board control measure the same thing, but I think it's useful to consider them as separate. All of these things are probably worth something in the evaluation.
Having good manoeuvrability means you statistically have a good chance of having a move that threatens something. In fact, that may be a better criterion: having to choose from three threatening moves probably puts you in a better position than having 30 pointless moves to choose from. Board control is probably more about restricting manoevrability of your opponent than about your own position. Tension is probably good if it is against a weakness: a pinned piece, a weak pawn, a piece that has very bad manoevrability, and should probably be scored progressively: having two weaknesses is more then twice as bad as having a single one.

In chess, because manoevrability and board control are so similar for most pieces (and pawns are scored separately anyway) they can probably be treated in a single evaluation term with a single weight. It would be interesting to see whether there's anything to be gained there by splitting it up and consider "safe mobility" for different pieces as well as giving points for being able to move a piece to a location where it controls more important squares or attacks a weakness. Tension may be hard to score properly and not have a big impact. I like the idea of scoring it progressively though, and think it would be interesting to look into.

I'll think about it some more and see whether I can find some time to play around with this.

Quite apart from such considerations though is the question of what effect mobility actually has on the search. Ultimately, the purpose of the evaluation is not so much to get an accurate score for a leaf-node position, but to help the search pick the best move at the root. Intuitively that's the same thing, but because the evaluation is not perfect it may not be the same thing in practice. It's possible that the best move to pick at the root is simply the move that gives you the biggest chance for having a good move later on, in other words, the move that ends up giving you the best mobility relative to your opponent in the long run...