Strelka 2.0B + sources

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

Moderator: Ras

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

Re: Strelka 2.0B + sources

Post by Uri Blass »

mjlef wrote:I have spent a little time look at the Strelka source. Very clearly written, so I did not really need the Russian comments to figure out what it is doing. My impressions:

Very, Very Fruit-like. Some of the things identical to Fruit:
Same Trans table
Identical NULL move pruning (R=3, eval>beta, needs a piece, etc.). Same verification search if depth>5. It does correct for side to move bonus, which Fruit does not, since Fruit 2./1 did not have a side to move bonus.
Dual evals (opening and endgame) and interpolated the same way (Fruit uses 256 steps, but given there are only 24 "pawns" of pieces available, this is really the same as Strelka's system)
Same mobility ideas for pieces, although the increments are different. Some seem almost backward from Fruit (for example, having a bigger increment in the opening than the endgame).
Same basic terms for Rook on semi-open file, open file, 7th, and king files, but different values.
Same method of King Safety (but different attack values for the pieces)
Same PVS search

Some difference:
Strelka uses a big array for correcting material values (initial values are along the ratio of P=1, N=B=3, R=5 and Q=10). Strelka uses P=3399, but divides this by 32 at the end of the eval, so really P=106, and so on. Note this table is indexed for pieces and pawns of both sides (but only for up to 1 queen, 2 rooks, 2 bishops, 3 knights and 8 pawns). It has a lot of endgame knowledge (like a draw for KBK--it does this by simply filling in a negative value for if -value[bishop] for example, to pull the score towards 0). My program has used the same idea since the early 1990s, except it only kicked in close to the endgame, due to memory limits (try making a program run in only 640k DOS!). The same array has a bit field for flags to indicate special eval terms (like this is a bishop and pawn endgame). Note Vasik a few years ago posted some code to talkchess showing just this idea (but of course, the magic is in what numbers to put in there).
More extensive passed pawn eval (the regular pawn eval is the same as Fruit, but with different values). The passed pawn eval include things like a bonus for the squares in front of a pawn being cleared.
Uses a lookup table for king safety pawn shielding (indexed by the same side and opponent pawns). This is very fast. It is stored in the pawn hash table. It stores a value for K on 1-c files, e-d files, and f-h files.
Only does check extensions in non-PV nodes. In PV nodes it has check, one reply to check and P to the 7th extensions (using Fruits same criteria of a non negative SEE value). I have tried the same idea in the past, but found s few of the other extensions were useful to also use in non-PV nodes.
See uses a few tricks to terminate early (like if a NxP is being considered, but the pawn is protected by another pawn).
Side to move bonus, but it is very small.

I have no idea if Strelka is close to the original Rybka. It does things in very efficient, clever ways. I did not see any real "tricks" or "secrets", but one idea was new to me. I have not tried writing a bitboard program, so maybe this is common:

In the qsearch, it uses a twist on futility pruning. It starts with a bitboard set for all pieces and pawns. If the eval is significantly under the value of a pawn, it turns off the pawn bits. If under a minor piece worth, it turns them off, etc. Then it uses the new bitmap to indicate opponent pieces and only generates capture big enough to likely find a score high enough to be useful. Perhaps all bitmap programmers already know this.


It also uses one other form of futility I have used for a while. At depth<=3 in non-PV nodes, if the eval is low enough, it tries a qsearch to see if a move can be found. If not, it uses the max(eval-margin,search value) and exits the search. Note it sets the depth of the qsearch to be positive, and the qsearch includes all captures (and not just winning/equal captures) while depth>0. It also includes checks. So this means a regular search is replaced with a capture+checks only search as a way of verifying. Perhaps it should include passed pawn moves as well, but anyway in a lot of tactical positions, this can save a lot of nodes, at some risk of missing quiet moves.

I have read a lot of claims by people who have seen the code (and others who state things with little information!). My conclusion: mostly Fruit, with better values, the tweaks above, and a mystery how the values were determined. I see nothing inaccurate on what the apparent author has stated, or what Vas has stated. People have suggest Vas might have used lots of games to determine things like improved material imbalance scoring, piece value changes based on remaining material, etc. Looking at the numbers in the arrays, that seems to be the case in Strelka too. It would be interesting to zero out this array and see how much strength gain this idea is worth. When I added something similar to my program based on data from lots of gains, it was worth maybe 40 ELO, but I already have a lot of rules to adjust piece values based on remaining material, likely draw conditions etc.

My summary: no magic, just good, solid, bug free and fast code, without a lot of complexity. And a real genius behind the values for that material correction array.

Mark
I wonder how did you understand things so fast.
Can you share us what exactly did you do to understand the code?

I am probably not good in understanding code of other people and I looked only in part of the code in order to understand(I have motivation to understand strelka because it is clearly less files and less code than fruit).

Did you print the code in paper and read it when you skip parts that you do not understand?
Did you compile the code with some changes to check things?

If you read only parts of the code than which parts of the code did you read?

Uri
mjlef
Posts: 1494
Joined: Thu Mar 30, 2006 2:08 pm

Re: Strelka 2.0B + sources

Post by mjlef »

Uri Blass wrote:
I wonder how did you understand things so fast.
Can you share us what exactly did you do to understand the code?

I am probably not good in understanding code of other people and I looked only in part of the code in order to understand(I have motivation to understand strelka because it is clearly less files and less code than fruit).

Did you print the code in paper and read it when you skip parts that you do not understand?
Did you compile the code with some changes to check things?

If you read only parts of the code than which parts of the code did you read?

Uri
I just read it on the computer screen using Notepad. It is good to have all the files opened at once so when say a function calls another function, you can look it up and see what it does. Somrhting like "grep" is good, since it can search a bunhc of files at once to tell you were to look for the function code and callers all at once. I was fortunate since the names of functions were in English, and descriptive themselves. Also, most functions and variable names match Fruit, which I already had studied.

I always start with the Search function, and it this case there were mupliple search functions. One is for the root search (since it has to handle things a bit differently, like reporting current move being searched, etc). Next is the main PV search. It, in turn, can call several other search functions. these include the Non-PV node "full width" search, a "getting out of check" search function, a qsearch (not in check), and an "in check" qsearch. The "non-PV" search has more code, since it does some pruning (NULL, LMR, etc). BTW, Strekla uses a very simple form of LMR with few conditions (no history condition, like Fruit). It just reduces non-cap, non promote moves after search the first 4 moves full depth. I do not even remember if it allows reductions of checks or not..but I can check.

Anyway, I then go through the function calls with enough understanding to figure out what eaach function does. I did not read every line in the move generators, but did understand how it orders moves (hash, winning/equal capture, killers. non-cap then losing captures, like Fruit). I found the bitboard move generation much easier to understand that I thought. Maybe I should write one.

Since functions have descriptive names, it is not that important to figure out precisely how it works, just what is does. I added some comments to some lines for some of the complex parts. Also, there are not so many files and not so many functions in Strelka, so this all goes pretty quickly. I would say in one hour I had a pretty good understanding of how it works. I did not bother trying to read all of the UCI interface code. Also, the code for filling in the material correction array is a bit complex, so I did not try to note all the replationships between pieces and the numbers in the arrays, but I did note the exceptions, like "KNK" is a draw.

Come to think of it, I did not see any real "lazy eval". Maybe I should look again.

Was any of this helpful?

Mark
GeorgeLyapko

Re: Strelka 2.0B + sources

Post by GeorgeLyapko »

mjlef wrote: Come to think of it, I did not see any real "lazy eval". Maybe I should look again.

Was any of this helpful?

Mark
There is no need to look again. Here is comment from "EVAL.C" Line 44
// Здесь была ленивая оценка. В одной из Белок была отключена,
// и вроде получилось лучше, но данных об этом нет.
// Зато такое отключение очень упростило программу,
// а на скорости сказалось не очень заметно.
In English:
// Here was a lazy evaluation. In one of Belka's it was switched off,
// and seemed to turn out better, but no data about it.
// But this simplified the program notedly
// without big decrease in speed.
User avatar
WinPooh
Posts: 276
Joined: Fri Mar 17, 2006 8:01 am
Location: Russia
Full name: Vladimir Medvedev

Re: Strelka 2.0B + sources

Post by WinPooh »

mjlef wrote: Come to think of it, I did not see any real "lazy eval". Maybe I should look again.
There is author's comment in Russian, in which he notes: lazy eval was removed from Strelka because it proved to be useless in Belka (Strelka's derivative by I.Korshunov, WildCat), and without LE both Belka and Strelka are stronger.
Uri Blass
Posts: 10790
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Strelka 2.0B + sources

Post by Uri Blass »

mjlef wrote:
Uri Blass wrote:
I wonder how did you understand things so fast.
Can you share us what exactly did you do to understand the code?

I am probably not good in understanding code of other people and I looked only in part of the code in order to understand(I have motivation to understand strelka because it is clearly less files and less code than fruit).

Did you print the code in paper and read it when you skip parts that you do not understand?
Did you compile the code with some changes to check things?

If you read only parts of the code than which parts of the code did you read?

Uri
I just read it on the computer screen using Notepad. It is good to have all the files opened at once so when say a function calls another function, you can look it up and see what it does. Somrhting like "grep" is good, since it can search a bunhc of files at once to tell you were to look for the function code and callers all at once. I was fortunate since the names of functions were in English, and descriptive themselves. Also, most functions and variable names match Fruit, which I already had studied.

I always start with the Search function, and it this case there were mupliple search functions. One is for the root search (since it has to handle things a bit differently, like reporting current move being searched, etc). Next is the main PV search. It, in turn, can call several other search functions. these include the Non-PV node "full width" search, a "getting out of check" search function, a qsearch (not in check), and an "in check" qsearch. The "non-PV" search has more code, since it does some pruning (NULL, LMR, etc). BTW, Strekla uses a very simple form of LMR with few conditions (no history condition, like Fruit). It just reduces non-cap, non promote moves after search the first 4 moves full depth. I do not even remember if it allows reductions of checks or not..but I can check.

Anyway, I then go through the function calls with enough understanding to figure out what eaach function does. I did not read every line in the move generators, but did understand how it orders moves (hash, winning/equal capture, killers. non-cap then losing captures, like Fruit). I found the bitboard move generation much easier to understand that I thought. Maybe I should write one.

Since functions have descriptive names, it is not that important to figure out precisely how it works, just what is does. I added some comments to some lines for some of the complex parts. Also, there are not so many files and not so many functions in Strelka, so this all goes pretty quickly. I would say in one hour I had a pretty good understanding of how it works. I did not bother trying to read all of the UCI interface code. Also, the code for filling in the material correction array is a bit complex, so I did not try to note all the replationships between pieces and the numbers in the arrays, but I did note the exceptions, like "KNK" is a draw.

Come to think of it, I did not see any real "lazy eval". Maybe I should look again.

Was any of this helpful?

Mark
Yes

It is possible that one of the problem is that I want to be sure that I understand something and guessing without understanding how it works is not enough for me.

I looked for significant time only at strelka1.8 but did not read part of the files.

I can say that I did not read most of the evaluation of strelka and even now I see there are a lot of numbers for specific bitboards like
0x0004020200000000 so it is not exactly code that is written in a way that it is very easy to understand.

Uri
Andrew
Posts: 231
Joined: Thu Mar 09, 2006 12:51 am
Location: Australia

Re: Strelka 2.0B + sources

Post by Andrew »

mjlef
Posts: 1494
Joined: Thu Mar 30, 2006 2:08 pm

Re: Strelka 2.0B + sources

Post by mjlef »

Thos kinds of numbers are just masks for stripping off bits in bitboards. For example, you can use a simple mask to detect if a pawn is passed:

http://chessprogramming.wikispaces.com/Passed+Pawns

I guess I am old enough to think in binary, so visualizing this stuff is not so hard for me. Try reading some of the chess programming pages in the wiki and I bet you will start "getting" things too.

Another technique is not to just "guess" but "theorize" what somethign means. Say a bit passed as a flag. What might it mean? Mayeb it represents being in check, or maybe being a non-PV node. Look at the calling fucntion and see if it matches your theory, then you know.

Mark
Alessandro Scotti

Re: Strelka 2.0B + sources

Post by Alessandro Scotti »

From one side we have opinions here at the CCC that Strelka is an obvious "translation" of Fruit, or that it is at least "very, very Fruit like".

On the other hand Vas has posted on the Rybka forum that Strelka is Rybka but he does not "see obvious signs of other code usage" so he claims Strelka as his own!

Surely there is a contradiction between those views? My head is now spinning... :shock:
IWB
Posts: 1539
Joined: Thu Mar 09, 2006 2:02 pm

Re: Strelka 2.0B + sources

Post by IWB »

Hello

IF (Vasik = TRUE) AND (STRELKA 'good portions of' FRUIT) THEN

RYBKA has to go GPL :idea:


Anything wrong with that assumtion?


Bye
Ingo

PS: Btw, grabing a code, declaring it a Rybka without showing the original is strange. What if any other programmer do this now with the same Strelka code, declaring it is his code!?
mjlef
Posts: 1494
Joined: Thu Mar 30, 2006 2:08 pm

Re: Strelka 2.0B + sources

Post by mjlef »

Vas says he is going to release Strelka under his name, since it contains so much reverse engineered (including data tables) from Rybka 1.0 beta:

http://rybkaforum.net/cgi-bin/rybkaforu ... l?tid=3006

This ends the clone debates for sure!