It is official now: 2002 ELO with 1961 characters!

Discussion of anything and everything relating to chess playing software and machines.

Moderators: hgm, Rebel, chrisw

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

Re: It is official now: 2002 ELO with 1961 characters!

Post by hgm »

The evaluation of uMax 4.8 is calculated in a purely differential way, i.e. it scores the (direct) value of moves, rather than the position. This might make the score of a position slightly path dependent, a problem that is completely ignored.

The value of a move is calculated as captured material (P=2, N=7, B=8, R=12, Q=23, all multiplied by 37 to get "centiPawn"), and positional points for the change in distance to the center. The latter is calculated from a kind of piece-square table shared by P,N,B abd K (and absent for Q and R). This table holds the square of the distance to the point e4.5 (so (file-'e')*(file-'e') + (rank-4.5)*(rank-4.5)). When a piece is captured, its piece-square points do not get lost. This is an inconsitency, (if it forcibly loses a piece, it could try to move it to a good square first to earn some piece-square points), but it did not seem to matter in practice. uMax does not know about open files, or 7th rank for Rooks. It does also not know about the Bishop pair, (but errs to the safe side by valuing B above N).

Game stage is determined from a variable that (at game level, not updated in the tree) counts how much non-Pawn material is captured (according to N,B=2, R=3, Q=6), for both sides together. So without promotions it ranges from 0 (opening) to 40 (Pawn ending). As long as it is under 30, a non-castling King move gets a penalty of 20 effectively freezing the King. A castling gets a 30 point bonus.

A Pawn move gets, apart from the piece-square points, a bonus increasing from 9 pt in the opening to 19 pt in a Pawn ending. (9 + 0.25 * GameStageIndicator). But it gets a 9-pt penalty if there is no Pawn 2 squares left or right fro its FROM-square (for releasing Pawn control over the squares it defended). It can get this penalty twice, if Pawns are missing on both sides. In lieu of King safety, moving a Pawn that was directly in front of its King gets an extra 9-pt penalty. (So a Pawn shield of only one...)

Pawn pushes to 6th and 7th rank each get 64-pt bonus, this bonus does disappear if the Pawn is captured or promotes. So a Pawn on the 6th is worth nearly 2 Pawns, one on the 7th nearly 3. uMax does not know about passers, even a blocked Pawn on the 6th gets this bonus. These terms proved very important, without them, uMax was extremely naive towards passers, and let them walk unopposed to 7th rank before trying to stop them.

That is currenty all.
User avatar
Mike S.
Posts: 1480
Joined: Thu Mar 09, 2006 5:33 am

Re: It is official now: 2002 ELO with 1961 characters!

Post by Mike S. »

hgm wrote:That is currenty all.
Thanks; this is interesting. So there is no passed pawn bonus and no doubled pawn penalty... and also no eval for piece mobility. Before, I would have thought that these are very basic requirements, but as you have proven an engine can achieve 2000+ Elo without it. :mrgreen:

I wonder if the castling bonus decision could be simplified if you check only, if queens are on the board still or gone. Because I think as a (very simplified) thumb rule we could say, if queens have been exchanged it isn't urgent anymore to castle. Although, the problem could arise that the corresponding rook isn't activated as it would be, by castling.

Does the king get a bonus for centralisation in each game stage? I think that should only be if the endgame is "near," or at least not yet as long as queens are on the board. Isn't that also a conflict with the castling bonus? (I admit I didn't calculate the resulting values.)

I apologize if my ideas are nonsense :roll: they are only from a patzer's viewpoint, what came to my mind first. - Anyway, thanks for the detailed description.
Regards, Mike
nczempin

Re: It is official now: 2002 ELO with 1961 characters!

Post by nczempin »

Mike S. wrote:
hgm wrote:That is currenty all.
Thanks; this is interesting. So there is no passed pawn bonus and no doubled pawn penalty... and also no eval for piece mobility. Before, I would have thought that these are very basic requirements, but as you have proven an engine can achieve 2000+ Elo without it. :mrgreen:

I wonder if the castling bonus decision could be simplified if you check only, if queens are on the board still or gone. Because I think as a (very simplified) thumb rule we could say, if queens have been exchanged it isn't urgent anymore to castle. Although, the problem could arise that the corresponding rook isn't activated as it would be, by castling.

Does the king get a bonus for centralisation in each game stage? I think that should only be if the endgame is "near," or at least not yet as long as queens are on the board. Isn't that also a conflict with the castling bonus? (I admit I didn't calculate the resulting values.)

I apologize if my ideas are nonsense :roll: they are only from a patzer's viewpoint, what came to my mind first. - Anyway, thanks for the detailed description.
Well, knowing how it evaluates, it should be possible to steer it to certain positions to exploit its weaknesses. That's what I do whenever I work on my own engine, and then I try to stop that gap.


So then it should be simple for a human with considerably less than 2000 (like me) to consistently beat it. Not that that is on my agenda (and of course I have to be very careful tactically against that 10-ply+ search).
User avatar
hgm
Posts: 27811
Joined: Fri Mar 10, 2006 10:06 am
Location: Amsterdam
Full name: H G Muller

Re: It is official now: 2002 ELO with 1961 characters!

Post by hgm »

Mike S. wrote:Thanks; this is interesting. So there is no passed pawn bonus and no doubled pawn penalty... and also no eval for piece mobility. Before, I would have thought that these are very basic requirements, but as you have proven an engine can achieve 2000+ Elo without it. :mrgreen:

....
I have tried to discourage formation of doubled Pawns, by scoring each Pawn move with a penalty if there was already an own Pawn behind the TO-square (by far the most common way in which it creates doubled Pawns). To my surprise that did not lead to any improvement of the results, so I dropped it again. I guess isolated Pawns are more important than doubled Pawns, but recognizing them is so difficult that it does not pay off in terms of ELO/char.

The centralization points for Knights and Bishops act as a poor man's substitute for the mobility. I still would like to try it with true mobility, though. This doesn't have to take many characters, just use the first two IID iterations for counting moves, rather than searching them.

Your ideas are not crazy at all. Indeed the King always tries to centralize, but by penalizing King moves more than can ever be earned by centralizing when there still is a lot of material on the board, this doesn't really matter. You might think that when a King move is forced for evading a check this might lead to the King chosing to walk towards unsafe squares closer to the center, but usually the search will foresee that on such squares it will be chased away quickly by more checks, with more penalties for King moves. So in practice its dominant concern is to put the King on a square that it cannot be forced to leave, which is usually safely in a corner. The same drive to avoid King moves often makes it maintain a good Pawn shield, even though it does not get any explicit points for that.

I tried to make the castling bonus so big that uMax main drive during the opening is to reap the castling bonus. This to prevent him destroying the Pawn shield before the King is there, leaving no good place to castle to. Once the King is there, the Pawn in front of it will be glued in place. The decision could hardly be simpler as it is now: a castling always gets a bonus independent of game stage or anything else. In practice, the only reason for not castling quickly is if its castling rights are destroyed before it could castle. So the situation where later in the game (after Queens have been traded) it has to chose between castling and other positionally good moves hardly ever occurs. And if it occurs, castling is hardly ever disastrously wrong. (Like you say, it develops a Rook that is unlikely to be very active in the corner.)

The game-stage indicator it uses now is approximately equivalent to the disappearence of Queens (the Queens make up 6 of the 20 points per side). It would not take significantly more or less code to only count Queens; the way it is done is simply accumulate captured material divided by some constant (and rounded down). Now I divide by 128, meaning that Pawns get rounded to 0, and other pieces to the mentioned values. If I would divide by 512 in stead everything except Queens would be rounded to 0. I have not really tested the alternatives, but it seemed to me that two Rooks are about as dangerous as a Queen, for a King strolling through open space. so the 2:3:6 weights did seem a natural measure for the danger. Counting also something for other pieces has the advantage that at the same time it can be used for estimating the probability for Zugzwang (and thus disable null move), so that you don't need another indicator for that.
Last edited by hgm on Tue Jun 05, 2007 12:45 pm, edited 2 times in total.
Uri Blass
Posts: 10311
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: It is official now: 2002 ELO with 1961 characters!

Post by Uri Blass »

hgm wrote:The evaluation of uMax 4.8 is calculated in a purely differential way, i.e. it scores the (direct) value of moves, rather than the position. This might make the score of a position slightly path dependent, a problem that is completely ignored.

The value of a move is calculated as captured material (P=2, N=7, B=8, R=12, Q=23, all multiplied by 37 to get "centiPawn"), and positional points for the change in distance to the center. The latter is calculated from a kind of piece-square table shared by P,N,B abd K (and absent for Q and R). This table holds the square of the distance to the point e4.5 (so (file-'e')*(file-'e') + (rank-4.5)*(rank-4.5)). When a piece is captured, its piece-square points do not get lost. This is an inconsitency, (if it forcibly loses a piece, it could try to move it to a good square first to earn some piece-square points), but it did not seem to matter in practice. uMax does not know about open files, or 7th rank for Rooks. It does also not know about the Bishop pair, (but errs to the safe side by valuing B above N).

Game stage is determined from a variable that (at game level, not updated in the tree) counts how much non-Pawn material is captured (according to N,B=2, R=3, Q=6), for both sides together. So without promotions it ranges from 0 (opening) to 40 (Pawn ending). As long as it is under 30, a non-castling King move gets a penalty of 20 effectively freezing the King. A castling gets a 30 point bonus.

A Pawn move gets, apart from the piece-square points, a bonus increasing from 9 pt in the opening to 19 pt in a Pawn ending. (9 + 0.25 * GameStageIndicator). But it gets a 9-pt penalty if there is no Pawn 2 squares left or right fro its FROM-square (for releasing Pawn control over the squares it defended). It can get this penalty twice, if Pawns are missing on both sides. In lieu of King safety, moving a Pawn that was directly in front of its King gets an extra 9-pt penalty. (So a Pawn shield of only one...)

Pawn pushes to 6th and 7th rank each get 64-pt bonus, this bonus does disappear if the Pawn is captured or promotes. So a Pawn on the 6th is worth nearly 2 Pawns, one on the 7th nearly 3. uMax does not know about passers, even a blocked Pawn on the 6th gets this bonus. These terms proved very important, without them, uMax was extremely naive towards passers, and let them walk unopposed to 7th rank before trying to stop them.

That is currenty all.
It seems to me that you have too high bonus for pawn in the 7th based on this discription.

Note that I also do not understand the code and I wonder if the following dictionary(from the link that I give here) for meaning of the variables is correct for 4.8 or you changed part of the names or maybe existing name are used in more meaning that is more logical because I see no logical reason to change existing names

http://home.hccnet.nl/h.g.muller/var.html

Here is your relevant code for pawns from your site

Code: Select all

if&#40;p<3&#41;                                 /* pawns&#58;                   */
       &#123;v-=9*(&#40;x-2&M||b&#91;x-2&#93;-u&#41;+               /* structure, undefended    */
              &#40;x+2&M||b&#91;x+2&#93;-u&#41;-1              /*        squares plus bias */
             +&#40;b&#91;x^16&#93;==k+36&#41;)                 /*** cling to magnetic K ***/
             -&#40;R>>2&#41;;                          /* end-game Pawn-push bonus */
        i+=V=y+r+1&S?647-p&#58;2*&#40;u&y+16&32&#41;;      /* promotion / passer bonus */
        b&#91;y&#93;+=V;                               /* upgrade P or convert to Q*/
       &#125;
unfortunately I do not understand all of this

v is evaluation score
p is the type of piece
M=0x88
x=orign square of the move
x-2&M is?
u is Piece doing the move under consideration(what is the difference
between it and p)
b[x-2]-u is?
x+2&M is?
k is 8 for white to move 16 for black to move
b[x^16]==k+36 is ?
R Origin square of best move returned by 'D()'
-(R>>2) is ?

i+=V=y+r+1&S?647-p:2*(u&y+16&32); is ?

I am not used to short code like that and I find it hard to understand what is going on.

For example I do not understand what the computer does before and what it does after in expression like u&y+16&32 and in my program I usually use () to understand what is going on even if I do not need them.

I may write (((u&y)+16)&32) or ((u&(y+16))&32) or (u&((y+16)&32))


Uri
User avatar
Mike S.
Posts: 1480
Joined: Thu Mar 09, 2006 5:33 am

Re: It is official now: 2002 ELO with 1961 characters!

Post by Mike S. »

hgm wrote: I have tried to discourage formation of doubled Pawns, by scoring each Pawn move with a penalty if there was already an own Pawn behind the TO-square (by far the most common way in which it creates doubled Pawns). To my surprise that did not lead to any improvement of the results, so I dropped it again.
Thx again. - Meanwhile it came to my mind: Since mobility (and rook to 7th rank) are not included, a doubled pawn penalty could be counter-productive sometimes, because: Often, the side which captures creating the doubled pawn, gets compensation in the form of an (half-)open file. So, the risk would be that µMax misses a chance where the advantage of the open file is bigger than the disadvantage of the doubled pawn.

I see this sometimes while playing against weaker or inexperienced opponents; typical is: Black has castled short, but not White, and: Bg4xNf3 g2xf3, and I get advantage or at least aggressive threats after Rh1-g1, maybe O-O-O etc. It may sound simple, but is quite typical... Often, I have moved the wQ to d2 to provoke that :mrgreen: My opponents learned doubled pawns are bad, but miss how dangerous the open g file will be... Old chess computers had the same weakness.
Regards, Mike
Tord Romstad
Posts: 1808
Joined: Wed Mar 08, 2006 9:19 pm
Location: Oslo, Norway

Re: It is official now: 2002 ELO with 1961 characters!

Post by Tord Romstad »

Uri Blass wrote:For example I do not understand what the computer does before and what it does after in expression like u&y+16&32
You can use this table when you are in doubt.
and in my program I usually use () to understand what is going on even if I do not need them.
This is a very good idea, IMHO. It improves readability, prevents lots of silly bugs, and makes it easier to edit and navigate in the code. There is no good reason to omit all parenthesises, unless you try to minimize the number of characters in your code.

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

Re: It is official now: 2002 ELO with 1961 characters!

Post by hgm »

You are correct: It did not occur to me to update the explanation of variable names yet. I did not change many names, but the assignments of R and W in the old explanation were tentative, i.e. I had them reserved for making future changes that in the end did not prove (sufficiently) benificial.

R is now the game-stage indicator, starting at 0, and reaching 40 when all non-Pawn material is captured. So (R>>2) is a Pawn push bonus that increases from 0 to 10 as the game progresses. (By the way, using this term was suggested to me by Maarten Claessens.)

x-2&M tests if the square 2 left from the FROM square x is on the board (it is non-zero, i.e. true, if it is off the board).
If it is on the board, the || operator needs to evaluate its right-hand-side operand, b[x-2]-u, which is then an on-board access that compares the piece at square x-2 with the piece that moved, u. If they are the same (i.e. both Pawns, as this happens in the section that is only executed for Pawn moves, and of the same color) the expression (x-2&M||b[x-2]-u), which is parsed as ((x-2)&M) || (b[x-2]-u), evaluates to 0 (meaning no penalty), if there isn't an own pawn there, or it was off board, it evaluates to 1 (which is later multiplied by the factor 9 in front of the parantheses), and you get the penalty.

The last two lines are the 6th/7th rank bonus, which is indeed the most obfuscated part of the code:
y is the TO square, y+16 shifts it one rank, (to number ranks from 1-8, rather than 0 to 7) and (y+16)&32 then isolates the '2' bit of the binary rank number. Thus it evaluates to 32 for a TO square on rank 2,3,6 and 7, and to zero otherwise. Then it is ANDed with u, which in the '32' bit encodes if the Pawn moving now had moved before ('virgin bit'). If it had not, than the Pawn was apparently on the 2nd rank, and the current TO square thus on the 3rd rank, and the '32' bit ends up cleared. So the value of 32 only results for Pawns pushed to 6th/7th rank (if they are white; 2nd/3rd if they are black). Multiplying by 2 gives the mentioned bonus of 64.

Now y+r+1 is where you get if you would continue the current move by one more step (r) and one square to the right, and with &S (S=128) you test if this falls off the board rank-wise. If it does, the current Pawn move was a promotion, and it gets the bonus 647-p, (as specified by the conditional (y+r+1) ? ... : ... operator), where p is the piece type: 1 or 2 depending on the color of the Pawn.

So in the end V is set to 647-p (promotion), 64 (move to 6th/7th rank) or 0 (other Pawn moves).

This V is than added to i, (V+=i), which holds value of captured material, to incorporate the calculated bonus in the score of the move. In total a promotion earns 64+64+647-p = 775-p = 773 or 774, (as you always have to cross 6th and 7th rank to promote), which is approximately the difference in value of Queen and Pawn.

This V is also added to the piece code on the board b[y], so that it is increased by 64 for Pawns on the 6th, 128 for pawns on the 7th, and 775-p for 'Pawns' on the 8th. As the piece type originally was p, this means that for a Pawn on the 8th the piece type becomes 775 = 768+7. But as the board is an array of char, the 768 = 3*256 is clipped off, and only the 7 remains, which happens to be the piece type for a Queen.

For Pawns on 6th or 7th the bonus of 64 or 128 remains stored in their piece encoding on the board (in bits that were otherwise unused), so that it can be added to the piece value when the Pawn should be captured on 6th or 7th rank. In effect this makes Pawns on 6th or 7th rank distinct pieces, different from ordinary Pawns, with different piece values, (but with the same moves), to which ordinary Pawns promote if they reach 6th or 7th rank.
Pablo Vazquez
Posts: 154
Joined: Thu May 31, 2007 9:05 pm
Location: Madrid, Spain

Re: It is official now: 2002 ELO with 1961 characters!

Post by Pablo Vazquez »

Do you use the Mingw compiler? In case you do, what version is it? Thanks

Pablo
Uri Blass
Posts: 10311
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: It is official now: 2002 ELO with 1961 characters!

Post by Uri Blass »

I do not understand it.

You say:
"x-2&M tests if the square 2 left from the FROM square x is on the board (it is non-zero, i.e. true, if it is off the board)."

Why do you need to check the square 2 left from the FROM square.

You may want to check a square that is 1 left from the from square to see if the pawn is supprted by a friendly pawn but I see no reason to check difference of 2 squares.

Uri