/* Pepito v1.53  -- file: tipos.h --
   Copyright (c) 2000-01 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
*/

#include "macros.h"
#include <time.h>

#ifdef LINUX
  typedef unsigned long long entero64;
#else
  typedef unsigned __int64 entero64;
#endif
typedef unsigned int       entero32;

typedef enum
  {
    A8, B8, C8, D8, E8, F8, G8, H8,
    A7, B7, C7, D7, E7, F7, G7, H7,
    A6, B6, C6, D6, E6, F6, G6, H6,
    A5, B5, C5, D5, E5, F5, G5, H5,
    A4, B4, C4, D4, E4, F4, G4, H4,
    A3, B3, C3, D3, E3, F3, G3, H3,
    A2, B2, C2, D2, E2, F2, G2, H2,
    A1, B1, C1, D1, E1, F1, G1, H1
  } casillas;



typedef struct
  {
     char tab[64];
     int alpaso;
     int turno;
     int num_jug;

     unsigned short pos_status;    /*
                                    ---------------1     posibilidad de enroque corto blancas
                                    --------------1-          "      "      "   largo   "
                                    -------------1--          "      "      "   corto negras
                                    ------------1---          "      "      "   largo   "
                                    ------XXXXXX----     casilla de posible captura al paso
                                    -----1----------     rey blanco enrocado corto
                                    ----1-----------      "    "       "     largo
                                    ---1------------     rey negro enrocado corto
                                    --1-------------      "    "       "    largo
                                 */

     entero64        hash_peones;
     entero64        hash_global;

     entero64 piezascolor[2];
     entero64 *pos_piezas;
     entero64 rotado45;
     entero64 rotado315;
     entero64 rotado90;

     int reyblanco;
     int reynegro;
     int material[2];
     int piezas[2];
     int peones[2];
  } posicion;

typedef struct
  {
    entero32 jug;
    int pieza_mov;
  } jugada_ext;

typedef struct
  {
    jugada_ext mov;
    unsigned int rep_count;
  } killer_type;

typedef struct
  {
    entero64 low;
    entero64 high;
  } entrada_hash;

typedef struct
  {
    entero64 key;
    int eval_peones;
    unsigned char pasadosB;
    unsigned char pasadosN;
    unsigned char debilB;
    unsigned char debilN;
    signed   char alejados;
    signed   char candipasa;
  } entrada_hash_p;

typedef struct
{
  entero64 hash;
  entero32 jug;
  entero64 hash_p;
  unsigned int status;
  int last_cap;
  unsigned char alpaso;
  unsigned char depth;
  short score;
  unsigned short time;
} historial;


typedef struct
{
  entero32 jug;
  long valor;
} list_jug;


typedef struct
{
   entero64 key;
   int valor;
   char tipo;
} ecache;

typedef struct
  {
    posicion pos;
    int jug_limit;
    int opp_bk_limit, my_bk_limit;
    int rnum_jug, rturno;
    int profmax;
    int time_up;
    int pondering, guessed;
    jugada_ext ponder_mv;
    int rpiezasB, rpiezasN;
    int rmat_diff;
	entero32 time_limit;
    int have_book_move;
    int book_retry;
    int analyzing;

    time_t t_inicio;

    unsigned long egtb_probes, egtb_hits, eval_hits;
    unsigned long nodos_buscados, nodos_quies, nodos_jug_raiz, nodos_control;
    unsigned long last_report, null_cuts;
    unsigned long null_attempts, internal_iter;
    unsigned long hash_hits, hash_used, hash_trys, p_hash_hits, p_hash_trys;

    unsigned long fut_cuts;
    unsigned long first_succ;
    unsigned long beta_cutoffs;
    unsigned long chk_extensions;
    unsigned long moreland_extensions;
    unsigned long recap_extensions;
    unsigned long evals;
    unsigned long lazy_evals;

    list_jug jug_stack[MOV_STACK_SIZE];
    list_jug *max_stack[MAX_PROF];

    unsigned int jug_hash[MAX_PROF];
    
    historial hist[MAXMOV];

    killer_type killer[MAX_PROF][2];
    char jaque[MAX_PROF];
    char purge_list[MAX_PROF];
    char proxima_fase[MAX_PROF];
    int extensiones[MAX_PROF];
    int poda[MAX_PROF];
    
    unsigned long history[4096][2];

    int edad;    
    entrada_hash *trans_tab;
    entrada_hash_p *trans_tab_p;
    ecache *eval_cache;
  } partida;

typedef struct
{
  entero32 my_clock, opp_clock;
  int ponder_on;
  int my_color;
  int mv_ctrl;
  int base, inc;
  int depth;
  int active;
  int post;
  int force;
} xboard_type;

typedef struct nodo
  {
    entero32 jug;
    struct nodo *sig;
  } nodo_jug;

typedef struct {

    entero64 bitmap;
    unsigned char chessmen[16];
    entero64 position_id;
    int pm_move_number, ce;
    int er_move_number, acd;
    entero64 Hash;

} epd_t;

typedef struct {

    int acd;
    int ce;
    nodo_jug *bm;
    nodo_jug *pv;

} epd_info;



typedef struct {

    int player_id;
    int fics_id;
    char name[256];
    char country[3];
    int ro;
    char birthdate[256];
    char sex;

} player_t;


typedef struct {

    int game_id;
    int white_id;
    int black_id;
    char event[80];
    char site[80];
    char date[80];
    int round;
    char result[8];
    int plycount;

} pgn_game_tag_t;

typedef struct {
    char *language;
    char pieces[6];
} lang_str_t;

typedef struct {

    char *str;
    int  (*exec)(int argc);

} command_t;

typedef struct {

    int ncommands;
    const command_t *cmnd;

} command_group_t;

