Added support for eco codes, for setting variables and various cleanups.
[rattatechess.git] / search.h
blob3eba32b7d45893c397b2f98a8eccfcee8f918c56
1 /***************************************************************************
2 platform.h - Platoform dependent utilities
3 -------------------
4 begin : Sun Oct 07 2007
5 copyright : (C) 2007 by Maurizio Monge
6 email : monge@linuz.sns.it
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef __SEARCH_H__
19 #define __SEARCH_H__
21 #include "engine.h"
23 #define MAX_PV 80
24 #define PLY 100
26 /* a prime number. Probably no good reason, i just like primes */
27 // #define PLUTO_SIZE ((1<<16)+1)
28 // #define MP(_x) ({int x = _x; x = (x - (x>>16))&0xffff; x<0?x+PLUTO_SIZE:x;})
29 #define PLUTO_SIZE 577177
30 #define MP(x) (((unsigned int)(x))%PLUTO_SIZE)
32 #define CAPT_INDEX(m) ({Move _m=(m);_m.capture*128*128 + _m.from*128 + _m.to;})
33 #define PLUTO_INDEX(a,b) MP(CAPT_INDEX(a)*9829+CAPT_INDEX(b))
34 #define PLUTO2_INDEX(a,b,c) MP(CAPT_INDEX(a)*9829+CAPT_INDEX(b)*67+CAPT_INDEX(c))
35 //#define PLUTO2_INDEX(a,b,c) (CAPT_INDEX(a)*9829+CAPT_INDEX(b)*49+CAPT_INDEX(c))%PLUTO_SIZE
37 #define PLUTO1(a) MP(CAPT_INDEX(a)*9829)
38 #define PLUTO2(a,b) MP(CAPT_INDEX(a)*9829+CAPT_INDEX(b)*67)
39 #define FAST_PLUTO(p,m) MP(p+m)
41 #define HISTORY_SIZE (64*64)
42 #define HISTORY_INDEX(m) (SQUARE_TO_64(m.from)*64 + SQUARE_TO_64(m.to))
44 #define WORST_MATE (INF-5000)
46 class SearchRoot
48 public:
49 class SearchStack
51 public:
52 Move *moves; /* generated moves */
53 int num_moves; /* num of moves */
54 int curr_move; /* the move being currently analyzed */
55 bool under_check;
56 int best_move;
57 SaveBuf save_buf;
58 Move null_threat;
59 bool null_threat_dangerous;
60 uint8_t escape_from[2];
63 Move mv_stack[200*MAX_PV];
64 int mv_stack_top;
65 SearchStack stack[MAX_PV];
67 Engine *engine;
68 Board board;
70 uint16_t pluto_tot[PLUTO_SIZE];
71 uint16_t pluto_hit[PLUTO_SIZE];
72 uint16_t pluto2_tot[PLUTO_SIZE];
73 uint16_t pluto2_hit[PLUTO_SIZE];
74 uint16_t history_tot[HISTORY_SIZE];
75 uint16_t history_hit[HISTORY_SIZE];
77 void print_pv(const Move& m);
78 bool check_draw(int curr_ply);
79 bool check_repetition(int curr_ply, int nfold);
80 bool null_move_ok();
81 void moves_heuristic(Move *mv, int num_mv, bool pv, int ply,
82 int orig_depth, Move best_mv_hash, bool quiesce,
83 Move* prev, int* overall_extensions, bool expect_allbad,
84 int p1, int p2);
85 void moves_quiescence_heuristic(Move *mv, int num_mv, const Move& hash,
86 int static_eval, int alpha, int beta, int depth, Move* prev);
87 int16_t search(int ply, int depth, bool pv,
88 int16_t alpha, int16_t beta, bool expect_allbad);
89 SearchRoot(Engine* e, const Board& b);
90 ~SearchRoot();
93 #endif //__SEARCH_H__