per test
[rattatechess.git] / search.h
bloba0619ff982910fd68622722ad72b2cb78b5eeae6
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 PLUTO_SIZE 277177
31 #define MP(x) ((int)(((unsigned int)(x))%PLUTO_SIZE))
33 #define CAPT_INDEX(m) ({Move _m=(m);_m.capture*128*128 + _m.from*128 + _m.to;})
34 #define PLUTO_INDEX(a,b) MP(CAPT_INDEX(a)*9829+CAPT_INDEX(b))
35 #define PLUTO2_INDEX(a,b,c) MP(CAPT_INDEX(a)*9829+CAPT_INDEX(b)*67+CAPT_INDEX(c))
36 //#define PLUTO2_INDEX(a,b,c) (CAPT_INDEX(a)*9829+CAPT_INDEX(b)*49+CAPT_INDEX(c))%PLUTO_SIZE
38 #define PLUTO1(a) MP(CAPT_INDEX(a)*9829)
39 #define PLUTO2(a,b) MP(CAPT_INDEX(a)*9829+CAPT_INDEX(b)*67)
40 #define FAST_PLUTO(p,m) MP(p+m)
42 #define HISTORY_SIZE (64*64)
43 #define HISTORY_INDEX(m) (SQUARE_TO_64(m.from)*64 + SQUARE_TO_64(m.to))
45 #define WORST_MATE (INF-5000)
47 class SearchRoot
49 public:
50 class SearchStack
52 public:
53 Move *moves; /* generated moves */
54 int num_moves; /* num of moves */
55 int curr_move; /* the move being currently analyzed */
56 bool under_check;
57 int best_move;
58 SaveBuf save_buf;
59 Move null_threat;
60 bool null_threat_dangerous;
61 uint8_t escape_from[2];
64 Move mv_stack[200*MAX_PV];
65 int mv_stack_top;
66 SearchStack stack[MAX_PV];
67 Move mv_pv[MAX_PV];
68 int mv_pv_top;
70 int base_depth;
72 SearchGui *search_gui;
73 Engine *engine;
74 Board board;
76 static uint16_t pluto_tot[PLUTO_SIZE];
77 static uint16_t pluto_hit[PLUTO_SIZE];
78 static uint16_t pluto2_tot[PLUTO_SIZE];
79 static uint16_t pluto2_hit[PLUTO_SIZE];
80 static uint16_t history_tot[HISTORY_SIZE];
81 static uint16_t history_hit[HISTORY_SIZE];
83 bool check_draw(int curr_ply);
84 bool check_repetition(int curr_ply, int nfold);
85 bool null_move_ok();
86 void moves_heuristic(Move *mv, int num_mv, bool pv, int ply,
87 int orig_depth, Move best_mv_hash, bool quiesce,
88 Move* prev, int* overall_extensions,
89 int p1, int p2);
90 void moves_quiescence_heuristic(Move *mv, int num_mv, const Move& hash,
91 int static_eval, int alpha, int beta, int depth, Move* prev);
92 int16_t search(int ply, int depth, bool pv,
93 int16_t alpha, int16_t beta, bool expect_allbad);
94 SearchRoot(Engine* e, const Board& b);
95 ~SearchRoot();
98 #endif //__SEARCH_H__