Computer Chess Club Archives


Search

Terms

Messages

Subject: Crafty changes to egtb.cpp - long post

Author: Vincent Diepeveen

Date: 12:47:55 12/04/00


Nalimov >>
"If so, how it happened that you included other
person's code without prior contacting him? Please note that under USA law
"source code available" doesn't mean "public domain". There is still a
copyright."

First of all never heart of this. Secondly you never mentionned anything
when i emailed you *never ever* you said something about this.

Last i downloaded crafty and have so far
indeed used egtb.cpp of it.

As far as i know i can use that code for any
purpose as far as i post the changes made to it.

I'll not post egtb.cpp as i didn't do changes to it.

Hereby the file a .c file which i use to
connect to it, you get it for free!

Hoping to have been complete - Vincent

-------- the c file -------------

/* proben in de EGTB
*/

#include <stdio.h>

#include <string.h>

#include <stdlib.h>



#include "diep.h"

#include "function.h"

#include "data.h"



#define  XX  127

#define  C_PIECES  3  /* Maximum # of pieces of one color OTB */



typedef unsigned int INDEX;

typedef unsigned int square;



/* Those declarations necessary because Diep is C, not C++ program */



#if defined (_MSC_VER)

#define  TB_FASTCALL  __fastcall

#else

#define  TB_FASTCALL

#endif



#define pageL       65536

#define tbbe_ssL    ((pageL-4)/2)

#define bev_broken  (tbbe_ssL+1)  /* illegal or busted */

#define bev_mi1     tbbe_ssL      /* mate in 1 move */

#define bev_mimin   1               /* mate in max moves */

#define bev_draw    0               /* draw */

#define bev_limax   (-1)            /* mated in max moves */

#define bev_li0     (-tbbe_ssL)   /* mated in 0 moves */



typedef INDEX (TB_FASTCALL * PfnCalcIndex) (square*, square*, square, int
fInverse);



extern int IInitializeTb(char *);

extern int FTbSetCacheSize(void *,unsigned long);

extern int IDescFindFromCounters(int *);

extern int FRegisteredFun(int,int);

extern PfnCalcIndex PfnIndCalcFun(int,int);

extern int TB_FASTCALL L_TbtProbeTable(int,int,INDEX);



#define PfnIndCalc PfnIndCalcFun

#define FRegistered FRegisteredFun



void InitNalimov(void);

void AskNalimov(char *);

int  AskQuickNalimov(int,int);



//extern int TB_CRC_CHECK;

extern int cbEGTBCompBytes;



int donecolor[2][8];  //indien true dan is wit al gedaan voor die kleur

void *EGTB_cache = (void *)NULL;



void InitNalimov(void) { /* initialiseren van de nalimov databases */



  /* open de file egtb.ini anders probeer c:\diep\nalimov */

  int i,ti,size;

  FILE *tbini;

  char inifile[256];

  char bp[256];

  char npath[10000];



  if( ProcessNumber ) {

    FlagEGTB = true;

    if( tree->EngineFlags&engine_noegtb )

      FlagEGTB = false;

  }



  if( !FlagEGTB ) {

    mprint("EGTB turned off\n");

    return;

  }



  AddDiepDir(inifile,"egtb.ini");

  i = 0;

  tbini = fopen(inifile,"rt");

  if( tbini != NULL ) {

    while( fgets(bp,255,tbini) ) {

      if( bp[0] != ';' && (size = strlen(bp)) ) {

        if( bp[size-1] == '\n' ) {

          bp[size-1] = '\0';

          size--;

        }

        for( ti = 0 ; ti < size ; ti++ )

          npath[i++] = bp[ti];

        npath[i++] = ';';

      }

    }

    fclose(tbini);

  }

  npath[i] = '\0';

  mprint("Initializing from %s Nalimov Compr. EGTB in dirs:\n  %s\n",

   inifile,npath);

  MaxEGTB = (int)IInitializeTb(npath);

  // maxegtb bevat maximaal aantal stukken egtb, 5 voor 5 stukken.



  if( MaxEGTB > 0 ) {

    EGTB_cache = (void *)malloc(tree->CacheSizeEGTB);

    FTbSetCacheSize(EGTB_cache,tree->CacheSizeEGTB);

    mprint("%lu used for TB indices and decompression
tables\n",cbEGTBCompBytes);

  }

  mprint("Found at most %i pieces EGTB\n",MaxEGTB);

}



void AskNalimov(char *buf) { /* vraagt een stelling op vanuit de interface */

  int i,rgicounters[10],piece,iTb;



  int    side;

  int    fInvert;

  square *psqW;

  square *psqB;

  square rgsqWhite[C_PIECES*5+1], rgsqBlack[C_PIECES*5+1];

  square sqEnP;

  INDEX  ind;



  int    c;



  for( i = 0 ; i < 8 ; i++ )

    donecolor[0][i] = donecolor[1][i] = 0;



  for( i = 0 ; i < 10 ; i++ )

    rgicounters[i] = 0;



  for( i = 0 ; i < 64 ; i++ ) {

    if( (piece=partij->bord[i]) ) {

      c = partij->kleur[i];

      if( c == white )

        rgsqWhite[((piece-1)*C_PIECES)+donecolor[white][piece]++] = (square)i;

      else

        rgsqBlack[((piece-1)*C_PIECES)+donecolor[black][piece]++] = (square)i;



      if( piece != king )

        rgicounters[(5*c)+piece-1]++;

    }

  }



  iTb = IDescFindFromCounters (rgicounters);

  if( iTb != 0 ) {

    mprint("egtb available!\n");

    if( iTb > 0 ) {

      side = partij->aanzet;

      fInvert = false;

      /* assumption order of pieces = P,N,B,R,Q,K ??? */

      psqW = rgsqWhite;//pointer to locations of white squares;

      psqB = rgsqBlack;//pointer to locations of black squares;

    }

    else {

      side = partij->aanzet^1;

      fInvert = true;

      psqW = rgsqBlack;//pointer to locations of black squares;

      psqB = rgsqWhite;//pointer to locations of white squares;

      iTb = -iTb;

    }



    if( !FRegistered(iTb, side) )

      sprintf(buf,"Error retreiving EGTB\n");

    else {

      int score;

      sqEnP = XX; // square of en-passant capture, IF IT'S POSSIBLE, or XX

      ind = (PfnIndCalc(iTb, side) (psqW,psqB,sqEnP,fInvert));

     // printf("index = %u iTb=%i\n",ind,iTb);

      score = L_TbtProbeTable(iTb,side,ind);



      if( bev_broken == score )

        sprintf(buf,"EGTB score is illegal\n");

      else if( score > 0 )

        sprintf(buf,"EGTB score side to move mates in %i
moves\n",(bev_mi1-score+1));

      else if( score < 0 )

        sprintf(buf,"EGTB score side to move loses in %i
moves\n",(bev_mi1+score));

      else

        sprintf(buf,"EGTB score is a draw\n");

    }

  }

  else

    sprintf(buf,"EGTB not available!\n");

}



int AskQuickNalimov(int c,int realply) {

 /* vraagt een stelling op vanuit de search

  * retourneert een matscore, remise score, of DIEPINFINITE indien geen egtb van
toepassing */

  int
i,rgicounters[10],piece,iTb,side,fInvert,*psq,sq,donewhite[6],doneblack[6];

  square *psqW;

  square *psqB;

  square rgsqWhite[C_PIECES*5+1], rgsqBlack[C_PIECES*5+1];

  square sqEnP;

  INDEX  ind;



  if( PieceCnt[white]+PieceCnt[black] >= 4 )

    return DIEPINFINITE; /* bij 6 pieces of meer, dan direct terug */



  for( i = 0 ; i < 6 ; i++ )

    donewhite[i] = doneblack[i] = 0;



  for( i = 0 ; i < 10 ; i++ )

    rgicounters[i] = 0;



  psq = PieceList[white];

  sq = *psq++;

  do {

    if( sq != 64 ) {

      piece = board[sq]-1;

      rgsqWhite[(piece*C_PIECES)+(donewhite[piece]++)] = (square)sq;

      if( piece != 5 )

        rgicounters[piece]++;

    }

  } while( (sq=*psq++) != 128 );



  psq = PieceList[black];

  sq=*psq++;

  do {

    if( sq != 64 ) {

      piece = board[sq]-1;

      rgsqBlack[(piece*C_PIECES)+(doneblack[piece]++)] = (square)sq;

      if( piece != 5 )

        rgicounters[5+piece]++;

    }

  } while( (sq=*psq++) != 128 );



  iTb = IDescFindFromCounters(rgicounters);

  if( iTb != 0 ) {

    if( iTb > 0 ) {

      side = c;

      fInvert = false;

      /* assumption order of pieces = P,N,B,R,Q,K ??? */

      psqW = rgsqWhite;//pointer to locations of white squares;

      psqB = rgsqBlack;//pointer to locations of black squares;

    }

    else {

      side = c^1;

      fInvert = true;

      psqW = rgsqBlack;//pointer to locations of black squares;

      psqB = rgsqWhite;//pointer to locations of white squares;

      iTb = -iTb;

    }



    if( !FRegistered(iTb, side) )

      return(DIEPINFINITE);

    else {

      int score;

      sqEnP = XX; // square of en-passant capture, IF IT'S POSSIBLE, or XX

      ind = (PfnIndCalc(iTb, side) (psqW,psqB,sqEnP,fInvert));

     // printf("index = %u iTb=%i\n",ind,iTb);

      score = L_TbtProbeTable(iTb,side,ind);



      if( bev_broken == score ) {

        //mprint("EGTB broken score ==> mate\n");

        return(MATEVALUE-realply);

      }

      else if( score > 0 ) {

        //mprint("EGTB score side to move mates in %i
moves\n",(bev_mi1-score+1));

        return(MATEVALUE-realply-((bev_mi1-score+1)*2));

      }

      else if( score < 0 ) {

        //mprint("EGTB score side to move loses in %i moves\n",(bev_mi1+score));

        return(-MATEVALUE+realply+((bev_mi1+score)*2));

      }

      else {

       // mprint("EGTB score is a draw\n");

        return(Contempt[c]);

      }



    }

  }

  else {

    return(DIEPINFINITE);

  }

}





/* EOF egbridge.c */

egtb.cpp is already included in crafty!





This page took 0.01 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.