File: test.c

package info (click to toggle)
crafty 17.6-1
  • links: PTS
  • area: non-free
  • in suites: potato
  • size: 7,312 kB
  • ctags: 3,207
  • sloc: ansic: 30,329; cpp: 4,158; asm: 728; makefile: 92; sh: 11
file content (167 lines) | stat: -rw-r--r-- 6,652 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "chess.h"
#include "data.h"

/* last modified 10/18/97 */
/*
********************************************************************************
*                                                                              *
*   Test() is used to test the program against a suite of test positions to    *
*   measure its performance on a particular machine, or to evaluate its skill  *
*   after modifying it in some way.                                            *
*                                                                              *
*   the test is initiated by using the "test <filename>" command to read in    *
*   the suite of problems from file <filename>.  the format of this file is    *
*   as follows:                                                                *
*                                                                              *
*   setboard <forsythe-string>:  this sets the board position using the usual  *
*   forsythe notation (see module SetBoard() in setc for a full ex-      *
*   planation of the syntax).                                                  *
*                                                                              *
*   solution <move1> <move2> ... <moven>:  this provides a solution move (or   *
*   set of solution moves if more than one is correct).  if the search finds   *
*   one of these moves, then the prblem is counted as correct, otherwise it    *
*   is counted wrong.                                                          *
*                                                                              *
*   after reading these two lines, the program then searches to whatever time  *
*   or depth limit has been set, when it reaches the end-of-file condition or  *
*   when it reads a record containing the string "end" it then displays the    *
*   number correct and the number missed.                                      *
*                                                                              *
********************************************************************************
*/
void Test(char *filename) {
  FILE *test_input;
  int i, move, right=0, wrong=0, correct;
  int time=0, len;
  double nodes=0.0;
  char *eof;
  float avg_depth=0.0;
  TREE * const tree=local[0];
/*
 ----------------------------------------------------------
|                                                          |
|   read in the position and then the solutions.  after    |
|   executing a search to find the best move (according    |
|   to the program, anyway) compare it against the list    |
|   of solutions and count it right or wrong.              |
|                                                          |
 ----------------------------------------------------------
*/
  if (!(test_input=fopen(filename,"r"))) {
    printf("file %s does not exist.\n",filename);
    return;
  }
  test_mode=1;
  if (book_file) {
    fclose(book_file);
    fclose(books_file);
    book_file=0;
    books_file=0;
  }
  while (1) {
    eof=fgets(buffer,512,test_input);
    if (eof) {
      char *delim;
      delim=strchr(buffer,'\n');
      if (delim) *delim=0;
      delim=strchr(buffer,'\r');
      if (delim) *delim=' ';
    }
    else break;
    nargs=ReadParse(buffer,args," ;");
    if (!strcmp(args[0],"end")) break;
    else if (!strcmp(args[0],"title")) {
      Print(4095,"======================================================================\n");
      Print(4095,"! ");
      len=0;
      for (i=1;i<nargs;i++) {
        Print(4095,"%s ",args[i]);
        len+=strlen(args[i])+1;
        if (len > 65) break;
      }
      for (i=len;i<67;i++) printf(" ");
      Print(4095,"!\n");
      Print(4095,"======================================================================\n");
    }
    else if (strcmp(args[0],"solution")) {
      Option(tree);
    }
    else {
      number_of_solutions=0;
      solution_type=0;
      Print(4095,"solution ");
      for (i=1;i<nargs;i++) {
        if (args[i][strlen(args[i])-1] == '?') {
          solution_type=1;
          args[i][strlen(args[i])-1]='\0';
        }
        else if (*(args+i)[strlen(args[i])-1] == '!') {
          solution_type=0;
          args[i][strlen(args[i])-1]='\0';
        }
        move=InputMove(tree,args[i],0,wtm,0,0);
        if (move) {
          solutions[number_of_solutions]=move;
          Print(4095,"%d. %s",(number_of_solutions++)+1,OutputMove(tree,move,0,wtm));
          if (solution_type==1) Print(4095,"? ");
          else Print(4095,"  ");
        }
        else DisplayChessBoard(stdout,tree->pos);
      }
      Print(4095,"\n");
      InitializeHashTables();
      last_pv.pathd=0;
      largest_positional_score=100;
      thinking=1;
      tree->position[1]=tree->position[0];
      (void) Iterate(wtm,think,0);
      thinking=0;
      nodes+=tree->nodes_searched;
      avg_depth+=(float)iteration_depth;
      time+=(end_time-start_time);
      correct=solution_type;
      for (i=0;i<number_of_solutions;i++) {
        if (!solution_type) {
          if (solutions[i] == tree->pv[1].path[1]) correct=1;
        }
        else
          if (solutions[i] == tree->pv[1].path[1]) correct=0;
      }
      if (correct) {
        right++;
        Print(4095,"----------------------> solution correct (%d/%d).\n",
              right,right+wrong);
      }
      else {
        wrong++;
        Print(4095,"----------------------> solution incorrect (%d/%d).\n",
              right,right+wrong);
      }
    }
  }
/*
 ----------------------------------------------------------
|                                                          |
|   now print the results.                                 |
|                                                          |
 ----------------------------------------------------------
*/
  if (right+wrong) {
    Print(4095,"\n\n\n");
    Print(4095,"test results summary:\n\n");
    Print(4095,"total positions searched..........%12d\n",right+wrong);
    Print(4095,"number right......................%12d\n",right);
    Print(4095,"number wrong......................%12d\n",wrong);
    Print(4095,"percentage right..................%12d\n",right*100/(right+wrong));
    Print(4095,"percentage wrong..................%12d\n",wrong*100/(right+wrong));
    Print(4095,"total nodes searched..............%12.1f\n",nodes);
    Print(4095,"average search depth..............%12.1f\n",avg_depth/(right+wrong));
    Print(4095,"nodes per second..................%12d\n",(int) ((float) nodes/(float) time*100.0));
  }
  input_stream=stdin;
  early_exit=99;
  test_mode=0;
}