Dany1962 / Isa-tuning-

tuning my chess engine using the Texel method
0 stars 0 forks source link

search.c of Isa #12

Open Dany1962 opened 6 years ago

Dany1962 commented 6 years ago

include

include

include

include

include

include "board.h"

include "recherche.h"

include "hash.h"

include "temps.h"

include "bitboards.h"

include "deftypes.h"

include "eval.h"

include "genecoups.h"

include "interface.h"

include "see.h"

/*

void tri_pv(MOVE *ptab, int ctr) { int i;

follow_pv = FAUX;
for(i = 0; i < ctr; ++i)
{
    if ((ptab[i].from == pv[0][prof].from) && (ptab[i].dest == pv[0][prof].dest))
    {
        follow_pv = VRAI;
        ptab[i].evaluation += 20000000;
        return;
    }
}

}

bool ok_pour_nul_move() { int p; p = calcul_phase(); if(p < 16) { return VRAI; } return FAUX; }

void jouer_coup_nul() { //printf("jouer coup nul \n");

hist[hdp].castle = castle;
hist[hdp].ep = ep;
hist[hdp].cinquante = cinquante;
hist[hdp].hash_code = hash_code_position;
hist[hdp].bitboard_blanc = bitboard_pion[BLANC];
hist[hdp].bitboard_noir = bitboard_pion[NOIR];

prof++;
hdp++;

hash_code_position ^=  val_couleur[side];
side = (BLANC + NOIR) - side;
hash_code_position ^=  val_couleur[side];

if(ep != -1)
{
    hash_code_position ^= val_en_passant[ep];
}
ep = -1;
cinquante++;

}

void dejouer_coup_nul() { //printf("dejouer coup nul \n"); side = (BLANC + NOIR) - side; hdp--; prof--;

castle = hist[hdp].castle;
ep = hist[hdp].ep;
cinquante = hist[hdp].cinquante;
hash_code_position = hist[hdp].hash_code;
bitboard_pion[BLANC] = hist[hdp].bitboard_blanc;
bitboard_pion[NOIR] = hist[hdp].bitboard_noir;

}

int quiesce(int alpha, int beta, MOVE * pBestMove, int depth) { int i,j; int val; int movecnt; MOVE moveBuf[200],tmpMove; int see_score; int score;

//controle temps depasse ou non
fin_recherche = controle_si_temps_depasse();
if(fin_recherche)
    return 0;

//evaluation de la position en cours
score = eval();

//longueur pv
long_pv[prof] = prof;
pBestMove->type = COUP_VIDE;

//profondeur limite ateinte : retourne eval()
if(prof >= MAXPLY-1)
    return score;

//stand pat ?
if(score >= beta)
    return beta;
if(alpha < score)
    alpha = score;

//limite qs ateinte
if(depth < QS_LIMITE)
    return score;

//generation captures + promos dame
movecnt = gen_captures_promos(side, moveBuf);

for (i = 0; i < movecnt; ++i)
{
    meilleur_coup_suivant(moveBuf, movecnt, i);

    //SEE prunning
    if(moveBuf[i].piece_from > moveBuf[i].piece_dest)
    {
        if(moveBuf[i].evaluation == 0)
            continue;
    }

    if (jouer_coup(moveBuf[i]))
        continue;

    //compteur de positions
    nodes++;

    //compteur de qs positions
    q_nodes++;

    val = -quiesce(-beta, -alpha, &tmpMove, depth - 1);

    dejouer_coup();

    if (val > alpha)
    {
        if (val >= beta)
            return beta;
        alpha = val;
        *pBestMove = moveBuf[i];

        //mise a jour pv
        pv[prof][prof] = *pBestMove;
        for (j = prof + 1; j < long_pv[prof + 1]; ++j)
        {
            pv[prof][j] = pv[prof + 1][j];
        }
        long_pv[prof] = long_pv[prof + 1];
    }
}
return alpha;

}

void meilleur_coup_suivant(MOVE *ptable, int nb_coups, int debut) { int ms; int mi; int i; MOVE temp;

ms = -MATE;
for(i = debut; i < nb_coups; ++i)
{
    if(ptable[i].evaluation > ms)
    {
        mi = i;
        ms = ptable[i].evaluation;
    }
}

temp = ptable[debut];
ptable[debut] = ptable[mi];
ptable[mi] = temp;

}

int test_see(MOVE *ptab, int ctr) { int f = ptab[ctr].from; int to = ptab[ctr].dest; int coul = couleur[f]; int score = 0; int pto = ptab[ctr].piece_dest;

memset(see_tree, 0, sizeof(see_tree));
memset(gsa, 0, sizeof(gsa));
make_capture(f, to, coul);
coul = OPP(coul);
//affiche_echiquier();
score = val_see[pto] - see(to, coul);
coul = OPP(coul);
unmake_capture(f, to, coul);

return score;

}