2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #define MAX_PV_STRING_SIZE 2048
26 int follow_pv
; /* if we are following PV searched by previous
28 int abort_search
; /* TRUE if search should be stopped by some reason */
29 int fail_high_root
; /* fail high at first ply */
33 /* iterative deeping */
45 char pv_string
[MAX_PV_STRING_SIZE
];
47 start_time
= get_time();
49 int max_time
= get_engine_value(&e
.max_time
);
50 int time_bonus
= leave_book
== 1? max_time
: 0;
52 set_engine_value((int *)&e
.stop_time
, start_time
+ \
53 max_time
+ time_bonus
); /* when stop search */
54 set_engine_value((int *)&e
.max_stop_time
, start_time
+ \
55 e
.max_time
* 3 + time_bonus
); /* when stop longest search */
57 /* initialize some data */
66 best_score
= -MATE_VALUE
;
69 fail_high_root
= FALSE
;
72 char fen_position
[256];
73 fprintf(stdout
, "setboard %s\n", current_fen_position(fen_position
));
76 engine_xboard
= get_engine_value(&e
.xboard_mode
);
77 /* if we have the only one move, don't think about it */
78 if (gen_legal_moves(&moves
) == 1)
82 printf("ply nodes score pv\n");
87 for (i_depth
= 1; i_depth
<= get_engine_value(&e
.max_depth
); i_depth
++) {
89 score
= search_root(-MATE_VALUE
, +MATE_VALUE
, i_depth
, \
95 /* save best move from last successful iteration */
100 /* get string PV representation (for 'Show Thinking' option or console
102 if (get_engine_value(&e
.san_notation
) || !engine_xboard
)
103 get_pv_string_san(pv_string
);
105 get_pv_string_coord(pv_string
);
107 assert(score
>= -MATE_VALUE
&& score
<= MATE_VALUE
);
109 if (!engine_xboard
&& pv
[0][0])
110 fprintf(stdout
, "%3d %10llu %5s%.2f %5u %s", i_depth
, \
111 counters
.searched_nodes
, score
>= 0? "+" : "-", \
112 abs(score
) / (float)100, get_time() - start_time
, pv_string
);
113 else if (engine_xboard
&& get_engine_value(&e
.post_mode
) && \
114 ((i_depth
> 5) || SCORE_IS_MATE(score
))) {
115 fprintf(stdout
, "%3d %7d %5u %10llu %s", i_depth
, score
, \
116 get_time() - start_time
, counters
.searched_nodes
, pv_string
);
119 if (SCORE_IS_MATE(score
) && i_depth
> 1)
120 /* don't search further if we have confirmed mate */
122 /* if it's not fixed time search and we used more than 50% of the
124 if (!get_engine_value(&e
.fixed_time
) && ((get_time() - start_time
) / \
125 (double)(get_engine_value((int *)&e
.stop_time
) - start_time
) > 0.5))
127 /* if it's not fixed time search and we used more than 30% of the
129 if (!get_engine_value(&e
.fixed_time
) && ((get_time() - start_time
) / \
130 (double)(get_engine_value((int *)&e
.stop_time
) - start_time
) > 0.33))
134 if (get_engine_value(&e
.play_computer
) && get_engine_value(&e
.post_mode
))
135 fprintf(stdout
, "tellics kibitz %.2f [%d], %dkNPS, PV = %s", (double)
136 best_score
/100, best_depth
, (int)((counters
.searched_nodes
/ 1000) / ((get_time() -
137 start_time
) / (double)100)), pv_string
);
139 /* should we resign? */
140 if (get_engine_value(&e
.resign
) && (best_score
<= \
141 get_engine_value(&e
.resign_value
))) {
142 if (++e
.hopeless_moves
>= 3)
145 e
.hopeless_moves
= 0;
148 print_stats(get_time() - start_time
);