~ubuntu-branches/ubuntu/precise/gcompris/precise

« back to all changes in this revision

Viewing changes to src/chess_computer-activity/gnuchess/test.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2010-06-27 22:51:30 UTC
  • mfrom: (1.1.16 upstream) (5.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100627225130-mf7h4m5r8m7bd9fb
Tags: 9.3-1
* New upstream release.
* Drop GTK_DISABLE_DEPRECATED patch, useless for now.
* Provide RELEASE_NOTE_9.3.txt downloaded from sourceforge.
* New voice package for Asturian.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* GNU Chess 5.0 - test.c - testing code
 
2
   Copyright (c) 1999-2002 Free Software Foundation, Inc.
 
3
 
 
4
   GNU Chess is based on the two research programs 
 
5
   Cobalt by Chua Kong-Sian and Gazebo by Stuart Cracraft.
 
6
 
 
7
   GNU Chess is free software; you can redistribute it and/or modify
 
8
   it under the terms of the GNU General Public License as published by
 
9
   the Free Software Foundation; either version 2, or (at your option)
 
10
   any later version.
 
11
 
 
12
   GNU Chess is distributed in the hope that it will be useful,
 
13
   but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
   GNU General Public License for more details.
 
16
 
 
17
   You should have received a copy of the GNU General Public License
 
18
   along with GNU Chess; see the file COPYING.  If not, write to
 
19
   the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
20
   Boston, MA 02111-1307, USA.
 
21
 
 
22
   Contact Info: 
 
23
     bug-gnu-chess@gnu.org
 
24
     cracraft@ai.mit.edu, cracraft@stanfordalumni.org, cracraft@earthlink.net
 
25
*/
 
26
 
 
27
#include <config.h>
 
28
#include <stdio.h>
 
29
#include <sys/time.h>
 
30
 
 
31
#include "common.h"
 
32
 
 
33
void TestMoveGenSpeed (void)
 
34
/**************************************************************************
 
35
 *
 
36
 *   This routine benchmarks the speed of the bitmap move generation.
 
37
 *   The test case is BK.epd, the 24 positions from the Brat-Kopec test
 
38
 *   suite.
 
39
 *
 
40
 **************************************************************************/
 
41
{
 
42
   unsigned long i;
 
43
   struct timeval t1, t2;
 
44
   double et;
 
45
   short side, xside;
 
46
 
 
47
   GenCnt = 0;
 
48
   et = 0;
 
49
/*
 
50
   while (ReadEPDFile ("../test/wac.epd", 0))
 
51
   {
 
52
*/
 
53
      gettimeofday (&t1, NULL);
 
54
      side = board.side;
 
55
      xside = 1^side;
 
56
      for (i = 0; i < 2000000; i++)
 
57
      {
 
58
         TreePtr[2] = TreePtr[1];
 
59
         GenMoves (1);
 
60
      }
 
61
      gettimeofday (&t2, NULL);
 
62
      et += (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1e6;
 
63
      printf ("Time = %f\n", et);
 
64
/*
 
65
   }
 
66
*/
 
67
   printf ("No. of moves generated = %lu\n", GenCnt);
 
68
   printf ("Time taken = %f secs\n", et);
 
69
   if (et > 0)
 
70
      printf ("Rate = %f moves/sec.\n", GenCnt / et);
 
71
}
 
72
 
 
73
 
 
74
 
 
75
void TestNonCaptureGenSpeed (void)
 
76
/**************************************************************************
 
77
 *
 
78
 *   This routine benchmarks the speed of the bitmap move generation
 
79
 *   for non capturing moves.
 
80
 *   The test case is BK.epd, the 24 positions from the Brat-Kopec test
 
81
 *   suite.
 
82
 *
 
83
 **************************************************************************/
 
84
{
 
85
   unsigned long i;
 
86
   struct timeval t1, t2;
 
87
   double et;
 
88
 
 
89
   GenCnt = 0;
 
90
   et = 0;
 
91
   while (ReadEPDFile ("../test/wac.epd", 0))
 
92
   {
 
93
      gettimeofday (&t1, NULL);
 
94
      for (i = 0; i < 100000; i++)
 
95
      {
 
96
         TreePtr[2] = TreePtr[1];
 
97
         GenNonCaptures (1);
 
98
      }
 
99
      gettimeofday (&t2, NULL);
 
100
      et += (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1e6;
 
101
      printf ("Time = %f\n", et);
 
102
   }
 
103
   printf ("No. of moves generated = %lu\n", GenCnt);
 
104
   printf ("Time taken = %f\n", et);
 
105
   if (et > 0)
 
106
      printf ("Rate = %f\n", GenCnt / et);  
 
107
}
 
108
 
 
109
 
 
110
void TestCaptureGenSpeed (void)
 
111
/**************************************************************************
 
112
 *
 
113
 *   This routine benchmarks the speed of the bitmap move generation
 
114
 *   for captures.
 
115
 *   The test case is BK.epd, the 24 positions from the Brat-Kopec test
 
116
 *   suite.
 
117
 *
 
118
 **************************************************************************/
 
119
{
 
120
   unsigned long i;
 
121
   struct timeval t1, t2;
 
122
   double et;
 
123
 
 
124
   GenCnt = 0;
 
125
   et = 0;
 
126
   while (ReadEPDFile ("../test/wac.epd", 0))
 
127
   {
 
128
      gettimeofday (&t1, NULL);
 
129
      for (i = 0; i < 200000; i++)
 
130
      {
 
131
         TreePtr[2] = TreePtr[1];
 
132
         GenCaptures (1);
 
133
      }
 
134
      gettimeofday (&t2, NULL);
 
135
      et += (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1e6;
 
136
      printf ("Time = %f\n", et);
 
137
   }
 
138
   printf ("No. of moves generated = %lu\n", GenCnt);
 
139
   printf ("Time taken = %f\n", et);
 
140
   if (et > 0)
 
141
      printf ("Rate = %f\n", GenCnt / et);  
 
142
}
 
143
 
 
144
 
 
145
void TestMoveList (void)
 
146
/****************************************************************************
 
147
 *  
 
148
 *  This routine reads in a *.epd file (EPD notation) and prints the legal
 
149
 *  moves for that position.  
 
150
 *
 
151
 ****************************************************************************/
 
152
{
 
153
   while (ReadEPDFile ("TEST/GMG1.epd", 0))
 
154
   {
 
155
      ShowBoard (); 
 
156
      GenCnt = 0;
 
157
      TreePtr[2] = TreePtr[1];
 
158
      GenMoves (1);
 
159
      FilterIllegalMoves (1);
 
160
      ShowMoveList (1); 
 
161
      printf ("No. of moves generated = %lu\n\n", GenCnt);
 
162
   }
 
163
}
 
164
 
 
165
 
 
166
void TestNonCaptureList (void)
 
167
/****************************************************************************
 
168
 *  
 
169
 *  This routine reads in a *.epd file (EPD notation) and prints the 
 
170
 *  non-capturing moves for that position.  
 
171
 *
 
172
 ****************************************************************************/
 
173
{
 
174
   while (ReadEPDFile ("TEST/GMG1.epd", 0))
 
175
   {
 
176
      ShowBoard (); 
 
177
      GenCnt = 0;
 
178
      TreePtr[2] = TreePtr[1];
 
179
      GenNonCaptures (1);
 
180
      FilterIllegalMoves (1);
 
181
      ShowMoveList (1); 
 
182
      printf ("No. of moves generated = %lu\n\n", GenCnt);
 
183
   }
 
184
}
 
185
 
 
186
 
 
187
void TestCaptureList (void)
 
188
/****************************************************************************
 
189
 *  
 
190
 *  This routine reads in a *.epd file (EPD notation) and prints the capture
 
191
 *  moves for that position.  
 
192
 *
 
193
 ****************************************************************************/
 
194
{
 
195
   while (ReadEPDFile ("TEST/GMG1.epd", 0))
 
196
   {
 
197
      ShowBoard (); 
 
198
      GenCnt = 0;
 
199
      TreePtr[2] = TreePtr[1];
 
200
      GenCaptures (1);
 
201
      FilterIllegalMoves (1);
 
202
      ShowMoveList (1); 
 
203
      printf ("No. of moves generated = %lu\n\n", GenCnt);
 
204
   }
 
205
}
 
206
 
 
207
 
 
208
#define NEVALS 30000
 
209
 
 
210
void TestEvalSpeed (void)
 
211
/***************************************************************************
 
212
 *
 
213
 *  This routine reads in the BK.epd and test the speed of the 
 
214
 *  evaluation routines.
 
215
 *
 
216
 ***************************************************************************/
 
217
{
 
218
   unsigned long i;
 
219
   struct timeval t1, t2;
 
220
   double et;
 
221
 
 
222
   et = 0;
 
223
   EvalCnt = 0;
 
224
   while (ReadEPDFile ("../test/wac.epd", 0))
 
225
   {
 
226
      gettimeofday (&t1, NULL);
 
227
      for (i = 0; i < NEVALS; i++)
 
228
      {
 
229
         (void) Evaluate (-INFINITY, INFINITY);
 
230
      }
 
231
      gettimeofday (&t2, NULL);
 
232
      et += (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec)/1e6;
 
233
      printf ("Time = %f\n", et);
 
234
   }
 
235
   printf ("No. of positions evaluated = %lu\n", EvalCnt);
 
236
   printf ("Time taken = %f\n", et);
 
237
   if (et > 0)
 
238
      printf ("Rate = %f\n", EvalCnt / et);  
 
239
}
 
240
 
 
241
 
 
242
 
 
243
void TestEval (void)
 
244
/**************************************************************************
 
245
 *
 
246
 *  To test the evaluation routines,  read from the BK.epd test file.
 
247
 *  Print out the score.  This can be improved by being more verbose
 
248
 *  and printing out salient features of the board, e.g. King safety,
 
249
 *  double bishops, rook on seventh rank, weak pawns, doubled pawns,
 
250
 *  bad bishops, passwd pawns, etc etc.
 
251
 *
 
252
 ***************************************************************************/
 
253
{
 
254
   int score;
 
255
 
 
256
   SET (flags, TESTT);
 
257
   while (ReadEPDFile ("../test/wac.epd", 0))
 
258
   {
 
259
      ShowBoard ();
 
260
      score = Evaluate (-INFINITY, INFINITY);
 
261
      printf (board.side == white ? "W : " : "B : ");
 
262
      printf ("score = %d\n\n", score);
 
263
   }
 
264
   CLEAR (flags, TESTT);
 
265
}
 
266