/* Pepito v1.59  -- file: initeval.c --
   Copyright (c) 2000-02 Carlos del Cacho

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2, or (at your option)
   any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; see the file COPYING.  If not, write to
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
   Boston, MA 02111-1307, USA.

   Contact the author: guggenjaimito@yahoo.com
*/

#ifndef UNIQUE_SOURCE_FILE
#  include "datos.h"
#endif

void            InitMaskPeones(entero64 aislado[8], entero64 pasado[2][64])
{
    int             i,
                    j;
    for (i = 0; i < 8; i++) {
        aislado[i] = 0;
        if (i > 0)
            aislado[i] |= COLUMNA[i - 1];
        if (i < 7)
            aislado[i] |= COLUMNA[i + 1];
    }
    for (i = 0; i < 64; i++) {
        j = i & 7;
        pasado[0][i] = ENTRE[i][56 + j];
        pasado[1][i] = ENTRE[i][j];
        if (j > 0) {
            pasado[0][i] |= ENTRE[i - 1][55 + j];
            pasado[1][i] |= ENTRE[i - 1][j - 1];
        }
        if (j < 7) {
            pasado[0][i] |= ENTRE[i + 1][57 + j];
            pasado[1][i] |= ENTRE[i + 1][j + 1];
        }
    }
}

//---------------------------------------------------------------------

void            InitRayos(entero64 * N, entero64 * S, entero64 * O, entero64 * E,
                 entero64 * SE, entero64 * SO, entero64 * NE, entero64 * NO)
{
    int             i,
                    j;

    for (i = 0; i < 64; i++) {
        for (j = i - 8, N[i] = 0; j >= 0; j -= 8)
            N[i] |= MASK[j];

        for (j = i + 8, S[i] = 0; j < 64; j += 8)
            S[i] |= MASK[j];

        for (j = i - 1, O[i] = 0; (j & 7) != 7; j--)
            O[i] |= MASK[j];

        for (j = i + 1, E[i] = 0; (j & 7) != 0; j++)
            E[i] |= MASK[j];

        for (j = i - 9, NO[i] = 0; (j & 7) != 7 && j >= 0; j -= 9)
            NO[i] |= MASK[j];

        for (j = i - 7, NE[i] = 0; (j & 7) != 0 && j >= 0; j -= 7)
            NE[i] |= MASK[j];

        for (j = i + 7, SO[i] = 0; (j & 7) != 7 && j < 64; j += 7)
            SO[i] |= MASK[j];

        for (j = i + 9, SE[i] = 0; (j & 7) != 0 && j < 64; j += 9)
            SE[i] |= MASK[j];
    }
}
//---------------------------------------------------------------------
void InitPasAlejados(entero64 * pas_alejaD, entero64 * pas_alejaI)
{
    int i,j;

    for (i=0;i<8;i++)
      for (j=0,pas_alejaI[i] = 0, pas_alejaD[i] = 0;j<8;j++)
      {
          if ((j-i)==1 || j<i)
             pas_alejaI[i] |= COLUMNA[j];
          if ((i-j)==1 || i<j)
             pas_alejaD[i] |= COLUMNA[j];
      }
/*    for (i=0;i<8;i++)
    {
      PintaBitBoard(pas_alejaD[i]);
      PintaBitBoard(pas_alejaI[i]);
    }*/
}
//-----------------------------------------------------------------------
void InitCasillaPeon()
{
  int i, j;

  for (i=0; i < 64; i++)
  {
     for (j = 0; j < 64; j++)
     {
        if (7 - (i >> 3) < Distancia((i&7)+A1,j))
           CASILLA_PEON_N[i] |= Mask(j);
        if ((i >> 3) < Distancia(i&7,j))
           CASILLA_PEON_B[i] |= Mask(j);
     }
  }

  for (i = 0; i < 8; i++)
  {
     CASILLA_PEON_N[A7+i] = CASILLA_PEON_N[A6+i];
     CASILLA_PEON_B[A2+i] = CASILLA_PEON_B[A3+i];

     RAYO_N_AMPLIO[i] = 0;
     RAYO_S_AMPLIO[i] = 0;

     for (j=0; j < 8; j++)
     {
         if (j >= i) RAYO_S_AMPLIO[i] |= FILA[j];
         if (j <= i) RAYO_N_AMPLIO[i] |= FILA[j];
     }

  }
}


