File: draw.c

package info (click to toggle)
crafty 15.20-2
  • links: PTS
  • area: main
  • in suites: slink
  • size: 6,952 kB
  • ctags: 2,538
  • sloc: ansic: 26,610; asm: 793; makefile: 101; csh: 15
file content (63 lines) | stat: -rw-r--r-- 2,670 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include "chess.h"
#include "data.h"

/* last modified 06/05/98 */
/*
********************************************************************************
*                                                                              *
*   DrawScore() is used to determine how good or bad a draw is in the current  *
*   game situation.  It depends on several factors, including the stage of the *
*   game (opening [draw=bad], middlegame [draw=somewhat bad] and endgames      *
*   [draw=default_draw_score.])  Additionally, it looks at the opponent's time *
*   remaining in the game, and if it's low, it will eschew the draw and press  *
*   the opponent to win before his flag falls.                                 *
*                                                                              *
********************************************************************************
*/
int DrawScore(int crafty_is_white)
{
  register int draw_score;
/*
 ----------------------------------------------------------
|                                                          |
|   first, set the draw score based on the phase of the    |
|   game, as would be done normally, anyway.               |
|                                                          |
 ----------------------------------------------------------
*/
  if (!draw_score_normal) {
    if (move_number <= 30) 
      draw_score=default_draw_score-66;
    else if (middle_game)
      draw_score=default_draw_score-33;
    else
      draw_score=default_draw_score;
/*
 ----------------------------------------------------------
|                                                          |
|   now that the base draw score has been set, look at the |
|   opponent's remaining time and set the draw score to a  |
|   lower value if his time is low.                        |
|                                                          |
 ----------------------------------------------------------
*/
    if (tc_increment == 0) {
      if (tc_time_remaining_opponent < 3000)
        draw_score=default_draw_score-50;
      if (tc_time_remaining_opponent < 1500)
        draw_score=default_draw_score-100;
    }
  }
/*
 ----------------------------------------------------------
|                                                          |
|   if playing a computer, return the default draw score   |
|   regardless of the phase of the game or time left.      |
|                                                          |
 ----------------------------------------------------------
*/
  else draw_score=default_draw_score;
  if (crafty_is_white) return(draw_score);
  else return(-draw_score);
}