counting similiarities between strelka2.0 and fruit2.1

Discussion of chess software programming and technical issues.

Moderators: hgm, Rebel, chrisw

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

counting similiarities between strelka2.0 and fruit2.1

Post by Uri Blass »

Based on the following thread I would like to count identical stuff
in a way that it is easy to find the identities
http://www.talkchess.com/forum/viewtopi ... 95&start=0

comparison
1)Fruit :protocol.cpp lines 493-507 and Strelka parsc.c lines 628-637
9 identical or equivalent lines



Code: Select all

FRUIT: 
static void parse_setoption( char string []) //1
{ 
const char *name;//2 
char* value; //3

name = strstr(string, "name "); //4
value = strstr(string, "value "); //5
if (name == NULL || value == NULL || name >= value)return;//6 
value[-1] = '\0'; //7
name += 5; //8
value += 6; //9

STRELKA: 
void parse_setoption(char string[]) //1 
{ 
char *name, *value; //2,3
int size; 

name = strstr(string,"name ");//4 
value = strstr(string,"value "); //5
if (name == NULL || value == NULL || name >= value) return; //6
value[-1] = 0; //7
name += 5; //8
value += 6; //9
2)Fruit Posix.cpp lines 39-108
Strelka parse.c lines 77-100

19 identical or equivalent parts

Code: Select all

FRUIT: 
bool input_available() //1
{ 
static bool init = false, is_pipe;//2 
static HANDLE stdin_h; //3
DWORD val, error; //4

if (stdin->_cnt > 0) return true; //5

if (!init)//6 
{ 
init = true;//7 
stdin_h = GetStdHandle(STD_INPUT_HANDLE);//8
is_pipe = !GetConsoleMode(stdin_h, &val); //9

if (!is_pipe) //10
{ 
SetConsoleMode(stdin_h, val & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)); //11
FlushConsoleInputBuffer(stdin_h); //12
} 
} 

if (is_pipe) //13
{ 
if (!PeekNamedPipe(stdin_h, NULL, 0, NULL, &val, NULL)) //14
return true; //15
return val > 0; //16
} 
else 
{ 
GetNumberOfConsoleInputEvents(stdin_h, &val); //17
return val > 1; //18
} 
return false; //19
} 

STRELKA: 
int input_available() //1
{ 
static int init = 0, is_pipe;//2 
static HANDLE stdin_h; //3
DWORD val; //4

if (stdin->_cnt > 0) return 1;//5 

if (!init) //6
{ 
init = 1;//7 
stdin_h = GetStdHandle(STD_INPUT_HANDLE); //8
is_pipe = !GetConsoleMode(stdin_h, &val); //9

if (!is_pipe)  //10
{ 
SetConsoleMode(stdin_h, val & ~(ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT)); //11
FlushConsoleInputBuffer(stdin_h); //12
} 
} 

if (is_pipe) //13
{ 
if (!PeekNamedPipe(stdin_h, NULL, 0, NULL, &val, NULL)) //14
return 1; //15
return val > 0; //16
} 
else 
{ 
GetNumberOfConsoleInputEvents(stdin_h, &val); //17
return val > 1; //18
} 
return 0; //19
} 
Total number of similiarities so far 28 when I am not sure if it is fair to count all of them as similiarities because I also have the function input_available() that is written different but I also have for example
if (stdin->_cnt > 0) return 1;

Note that I did not copy input_available() from fruit because movei's code was written before fruit but people clearly helped me with the code of input_available() and unlike some genius people who claim that they did not start from code of other people I have no chance to write input_available() from scratch without code of other people.

I hope somebody can continue the analysis.

Uri
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: counting similiarities between strelka2.0 and fruit2.1

Post by bob »

For the record, my recorded IQ would put me in the genius category. But that has nothing to do with this discussion. And also for the record, I don't "claim" that I started from scratch, I _categorically state" that I started from scratch. Blitz was a member of USCF in 1972. It played its first move 4 years prior to that. Who/What would I have copied? In 1994 when I started Crafty, I was only aware of gnuchess as a viable open-source program. There were a very few others, such as chess 0.5 published in Byte or whatever. But feel free to find the earliest version of Crafty you can get your hands on and compare it to gnuchess to see if you find _any_ similarities whatsoever. You won't.

I know that some started with gnuchessx. I believe Bruce said this on his web site, before moving on to 0x88 and such. I know Slate started from scratch. And Thompson. Ans Scherzer. And Schwartz. And Schaeffer. And Newborn. And Marsland. And Kozdrowicki. And Greenblatt. And Truscott. So many have done this and it is not impossible. Nor does it require "genius". Just some work.
User avatar
sje
Posts: 4675
Joined: Mon Mar 13, 2006 7:43 pm

Starting from scratch

Post by sje »

All of my chess programs have been written without using any sources except that my later code has drawn from my earlier code. And I started programming in 1969, although my real chess programming started a few years later.

But is that really starting from scratch? My thought is that ideas are more important than program source, and even back in the early 1970s there were plenty of good ideas in print. Many of the ones I've used came to me from Arthur Samuel's checker program papers -- not from his source, which I've never seen. And a few years later in college I came across Frey's first edition of _Chess Skill in Man and Machine_; that was loaded with ideas, but no source. And in the late 1980s I came across the ICCA, ordered all of the back issues of the ICCA Journal, and read about plenty of ideas including more than a few that I had independently developed.

I suppose I'm not so concerned about "starting from scratch" status, just like I'm not too concerned about who has the fastest, strongest, or flashiest program. New ideas are what really matters.
Uri Blass
Posts: 10311
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Starting from scratch

Post by Uri Blass »

sje wrote:All of my chess programs have been written without using any sources except that my later code has drawn from my earlier code. And I started programming in 1969, although my real chess programming started a few years later.

But is that really starting from scratch? My thought is that ideas are more important than program source, and even back in the early 1970s there were plenty of good ideas in print. Many of the ones I've used came to me from Arthur Samuel's checker program papers -- not from his source, which I've never seen. And a few years later in college I came across Frey's first edition of _Chess Skill in Man and Machine_; that was loaded with ideas, but no source. And in the late 1980s I came across the ICCA, ordered all of the back issues of the ICCA Journal, and read about plenty of ideas including more than a few that I had independently developed.

I suppose I'm not so concerned about "starting from scratch" status, just like I'm not too concerned about who has the fastest, strongest, or flashiest program. New ideas are what really matters.
No idea is going to help me to calculate the time.
I need to copy from some source(not have to be a chess program).

No idea is going to help me to teach my program if it got input from the interface.
I need to copy from some source(again it does not have to be a chess program).

Uri
Aleks Peshkov
Posts: 892
Joined: Sun Nov 19, 2006 9:16 pm
Location: Russia

Re: Starting from scratch

Post by Aleks Peshkov »

I tried to keep myself away from infinite Rybka/Strelka/Fruit threads in General Topics, but the plague seed also in Technical Discussions. :(

I will put here somewhat different thoughts.

1) From past history of Unix-clones it looks that rewriting every line from copyrighted source code makes the clone legally clean, whatever it origins.

2) Most open source chess code looks very similar in style, naming conventions and such, even if it behaves different. I find that almost all open source programs are too similar to each other. Fruit looks like many other less successful programs too. I do not understand the noise around Fruit at all.

3) Similar input_available() can be found in more then 75% of all open source programs.
Michael Sherwin
Posts: 3196
Joined: Fri May 26, 2006 3:00 am
Location: WY, USA
Full name: Michael Sherwin

Re: Starting from scratch

Post by Michael Sherwin »

Such as they are, I figured out the following things for myself:

How to program in bitboards.

Hash tables.

keeping and retrieving the principle variation.

The evaluation.

Move ordering.

Null move. (I had the idea long before I read about it)

Learning.

And to a large extent the alpha-beta search itself. (however, I looked at TSCP to make it into negamax, my previous program Carnivor is not negamax) Edit: Just to clarify, I did read about mini/max and alpha/beta before I wrote Carnivor.

And I also figured out the I/O myself with the MSDN documentation that came with MSVC 6. (Now, I am not a genius, but then my I/O does not work perfectly either. And it did take alot of work and struggle. Maybe I should just copy it.)

RomiChess is a very original work and I am not a genius. I just worked really hard and never gave up trying.

BUT,

does that mean that what I have done is special somehow. That it is better than someone that started from an open source program and managed to make it much better. Not at all. Both paths are just as valid and noble. If people were not allowed to improve upon other peoples work by using it as a foundation for future progress then we would all be living in the stoneage.

So, copy the mundane (I/O), then work like crazy to substantially rewrite and improve the chess playing algorithim and all will be fine. JMO.
If you are on a sidewalk and the covid goes beep beep
Just step aside or you might have a bit of heat
Covid covid runs through the town all day
Can the people ever change their ways
Sherwin the covid's after you
Sherwin if it catches you you're through
bob
Posts: 20943
Joined: Mon Feb 27, 2006 7:30 pm
Location: Birmingham, AL

Re: Starting from scratch

Post by bob »

Uri Blass wrote:
sje wrote:All of my chess programs have been written without using any sources except that my later code has drawn from my earlier code. And I started programming in 1969, although my real chess programming started a few years later.

But is that really starting from scratch? My thought is that ideas are more important than program source, and even back in the early 1970s there were plenty of good ideas in print. Many of the ones I've used came to me from Arthur Samuel's checker program papers -- not from his source, which I've never seen. And a few years later in college I came across Frey's first edition of _Chess Skill in Man and Machine_; that was loaded with ideas, but no source. And in the late 1980s I came across the ICCA, ordered all of the back issues of the ICCA Journal, and read about plenty of ideas including more than a few that I had independently developed.

I suppose I'm not so concerned about "starting from scratch" status, just like I'm not too concerned about who has the fastest, strongest, or flashiest program. New ideas are what really matters.
No idea is going to help me to calculate the time.
I need to copy from some source(not have to be a chess program).

No idea is going to help me to teach my program if it got input from the interface.
I need to copy from some source(again it does not have to be a chess program).

Uri
Why don't you do what I did? Pick up a manual and find out how to check the time, or (in unix) to use the select() system call to check for input available, or to use malloc() to allocate memory, or to use fork() to create a new process, or to use open() to create a new file or access an old one. Etc.???
Uri Blass
Posts: 10311
Joined: Thu Mar 09, 2006 12:37 am
Location: Tel-Aviv Israel

Re: Starting from scratch

Post by Uri Blass »

I simply did not consider searching for important information about it.
When I look about it now I see that at least for time I can find the following example in the help file
I guess that it is least ok if I copy something from examples like that
because without copying from some source I have no chance to do things
but I also think that if everybody has to invent the same wheel of measuring time and checking for input the progress in computer chess is going to be slower because people may need significant time to do it

Code: Select all

// crt_times.c
// compile with: /W1
// This program demonstrates these time and date functions:
//      time         _ftime    ctime_s     asctime_s
//      _localtime64_s    _gmtime64_s    mktime    _tzset
//      _strtime_s     _strdate_s  strftime
//
// Also the global variable:
//      _tzname
//

#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

int main&#40;)
&#123;
    char tmpbuf&#91;128&#93;, timebuf&#91;26&#93;, ampm&#91;&#93; = "AM";
    time_t ltime;
    struct _timeb tstruct;
    struct tm today, gmt, xmas = &#123; 0, 0, 12, 25, 11, 93 &#125;;
    errno_t err;

    // Set time zone from TZ environment variable. If TZ is not set,
    // the operating system is queried to obtain the default value 
    // for the variable. 
    //
    _tzset&#40;);

    // Display operating system-style date and time. 
    _strtime_s&#40; tmpbuf, 128 );
    printf&#40; "OS time&#58;\t\t\t\t%s\n", tmpbuf );
    _strdate_s&#40; tmpbuf, 128 );
    printf&#40; "OS date&#58;\t\t\t\t%s\n", tmpbuf );

    // Get UNIX-style time and display as number and string. 
    time&#40; &ltime );
    printf&#40; "Time in seconds since UTC 1/1/70&#58;\t%ld\n", ltime );
    err = ctime_s&#40;timebuf, 26, &ltime&#41;;
    if &#40;err&#41;
    &#123;
       printf&#40;"ctime_s failed due to an invalid argument.");
       exit&#40;1&#41;;
    &#125;
    printf&#40; "UNIX time and date&#58;\t\t\t%s", timebuf );

    // Display UTC. 
    err = _gmtime64_s&#40; &gmt, &ltime );
    if &#40;err&#41;
    &#123;
       printf&#40;"_gmtime64_s failed due to an invalid argument.");
    &#125;
    err = asctime_s&#40;timebuf, 26, &gmt&#41;;
    if &#40;err&#41;
    &#123;
       printf&#40;"asctime_s failed due to an invalid argument.");
       exit&#40;1&#41;;
    &#125;
    printf&#40; "Coordinated universal time&#58;\t\t%s", timebuf );

    // Convert to time structure and adjust for PM if necessary. 
    err = _localtime64_s&#40; &today, &ltime );
    if &#40;err&#41;
    &#123;
       printf&#40;"_localtime64_s failed due to an invalid argument.");
       exit&#40;1&#41;;
    &#125;
    if&#40; today.tm_hour >= 12 )
    &#123;
   strcpy_s&#40; ampm, sizeof&#40;ampm&#41;, "PM" );
   today.tm_hour -= 12;
    &#125;
    if&#40; today.tm_hour == 0 )  // Adjust if midnight hour.
   today.tm_hour = 12;

    // Convert today into an ASCII string 
    err = asctime_s&#40;timebuf, 26, &today&#41;;
    if &#40;err&#41;
    &#123;
       printf&#40;"asctime_s failed due to an invalid argument.");
       exit&#40;1&#41;;
    &#125;

    // Note how pointer addition is used to skip the first 11 
    // characters and printf is used to trim off terminating 
    // characters.
    //
    printf&#40; "12-hour time&#58;\t\t\t\t%.8s %s\n",
       timebuf + 11, ampm );

    // Print additional time information. 
    _ftime&#40; &tstruct ); // C4996
    // Note&#58; _ftime is deprecated; consider using _ftime_s instead
    printf&#40; "Plus milliseconds&#58;\t\t\t%u\n", tstruct.millitm );
    printf&#40; "Zone difference in hours from UTC&#58;\t%u\n", 
             tstruct.timezone/60 );
    printf&#40; "Time zone name&#58;\t\t\t\t%s\n", _tzname&#91;0&#93; ); //C4996
    // Note&#58; _tzname is deprecated; consider using _get_tzname
    printf&#40; "Daylight savings&#58;\t\t\t%s\n", 
             tstruct.dstflag ? "YES" &#58; "NO" );

    // Make time for noon on Christmas, 1993. 
    if&#40; mktime&#40; &xmas ) != &#40;time_t&#41;-1 )
    &#123;
       err = asctime_s&#40;timebuf, 26, &xmas&#41;;
       if &#40;err&#41;
       &#123;
          printf&#40;"asctime_s failed due to an invalid argument.");
          exit&#40;1&#41;;
       &#125;
       printf&#40; "Christmas\t\t\t\t%s\n", timebuf );
    &#125;

    // Use time structure to build a customized time string. 
    err = _localtime64_s&#40; &today, &ltime );
    if &#40;err&#41;
    &#123;
        printf&#40;" _localtime64_s failed due to invalid arguments.");
        exit&#40;1&#41;;
    &#125;

    // Use strftime to build a customized time string. 
    strftime&#40; tmpbuf, 128,
         "Today is %A, day %d of %B in the year %Y.\n", &today );
    printf&#40; tmpbuf );
&#125;

Code: Select all

// crt_spawn.c
// This program accepts a number in the range
// 1-8 from the command line. Based on the number it receives,
// it executes one of the eight different procedures that
// spawn the process named child. For some of these procedures,
// the CHILD.EXE file must be in the same directory; for
// others, it only has to be in the same path.
//

#include <stdio.h>
#include <process.h>

char *my_env&#91;&#93; =
&#123;
   "THIS=environment will be",
   "PASSED=to child.exe by the",
   "_SPAWNLE=and",
   "_SPAWNLPE=and",
   "_SPAWNVE=and",
   "_SPAWNVPE=functions",
   NULL
&#125;;

int main&#40; int argc, char *argv&#91;&#93; )
&#123;
   char *args&#91;4&#93;;

   // Set up parameters to be sent&#58; 
   args&#91;0&#93; = "child";
   args&#91;1&#93; = "spawn??";
   args&#91;2&#93; = "two";
   args&#91;3&#93; = NULL;

   if &#40;argc <= 2&#41;
   &#123;
      printf&#40; "SYNTAX&#58; SPAWN <1-8> <childprogram>\n" );
      exit&#40; 1 );
   &#125;

   switch &#40;argv&#91;1&#93;&#91;0&#93;)   // Based on first letter of argument 
   &#123;
   case '1'&#58;
      _spawnl&#40; _P_WAIT, argv&#91;2&#93;, argv&#91;2&#93;, "_spawnl", "two", NULL );
      break;
   case '2'&#58;
      _spawnle&#40; _P_WAIT, argv&#91;2&#93;, argv&#91;2&#93;, "_spawnle", "two", 
               NULL, my_env );
      break;
   case '3'&#58;
      _spawnlp&#40; _P_WAIT, argv&#91;2&#93;, argv&#91;2&#93;, "_spawnlp", "two", NULL );
      break;
   case '4'&#58;
      _spawnlpe&#40; _P_WAIT, argv&#91;2&#93;, argv&#91;2&#93;, "_spawnlpe", "two", 
                NULL, my_env );
      break;
   case '5'&#58;
      _spawnv&#40; _P_OVERLAY, argv&#91;2&#93;, args );
      break;
   case '6'&#58;
      _spawnve&#40; _P_OVERLAY, argv&#91;2&#93;, args, my_env );
      break;
   case '7'&#58;
      _spawnvp&#40; _P_OVERLAY, argv&#91;2&#93;, args );
      break;
   case '8'&#58;
      _spawnvpe&#40; _P_OVERLAY, argv&#91;2&#93;, args, my_env );
      break;
   default&#58;
      printf&#40; "SYNTAX&#58; SPAWN <1-8> <childprogram>\n" );
      exit&#40; 1 );
   &#125;
   printf&#40; "from SPAWN!\n" );
&#125;
tvrzsky
Posts: 128
Joined: Sat Sep 23, 2006 7:10 pm
Location: Prague

Re: Starting from scratch

Post by tvrzsky »

I just second that. My guides when i started writing a chess program about eight years ago was a very informative book Chess on PC by Chessbase's Frederic Friedel and Dieter Steinwender and then primers on C programming which I had many :-).
Yet I had to learn and figure lot of things by myself (note that I am neither programmer nor scientist or engineer) and surely I was "reinventing the wheel" most of the time but I do not regret it. I remember the certain feel of proudness (please take it with humour) when I realized that MY system of storing the board is also well known as 0x88 (for example). So it is a matter of choice, you can use somebody's source and have strong engine virtually for nothing from which you can launch or spend hundreds and maybe thousands hours of hard work only to end with perhaps just mediocre one but YOUR OWN one. However it is definitely possible to do it without making any copy/past things.
Filip
User avatar
Graham Banks
Posts: 41473
Joined: Sun Feb 26, 2006 10:52 am
Location: Auckland, NZ

Re: Starting from scratch

Post by Graham Banks »

Aleks Peshkov wrote:I tried to keep myself away from infinite Rybka/Strelka/Fruit threads in General Topics, but the plague seed also in Technical Discussions. :(
It's probably where the discussions belong anyway. :wink:
gbanksnz at gmail.com