Details | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 112 | pmbaty | 1 | /* |
| 2 | Protector -- a UCI chess engine |
||
| 3 | |||
| 4 | Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com) |
||
| 5 | |||
| 6 | This program is free software: you can redistribute it and/or modify |
||
| 7 | it under the terms of the GNU General Public License as published by |
||
| 8 | the Free Software Foundation, either version 3 of the License, or |
||
| 9 | (at your option) any later version. |
||
| 10 | |||
| 11 | This program is distributed in the hope that it will be useful, |
||
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
| 14 | GNU General Public License for more details. |
||
| 15 | |||
| 16 | You should have received a copy of the GNU General Public License |
||
| 17 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 18 | |||
| 19 | */ |
||
| 20 | |||
| 21 | #include <stdio.h> |
||
| 22 | #include <stdlib.h> |
||
| 23 | #include <string.h> |
||
| 24 | #include <assert.h> |
||
| 25 | #include "tools.h" |
||
| 26 | #include "io.h" |
||
| 27 | #include "protector.h" |
||
| 28 | #include "bitboard.h" |
||
| 29 | #include "position.h" |
||
| 30 | #include "fen.h" |
||
| 31 | #include "movegeneration.h" |
||
| 32 | #include "matesearch.h" |
||
| 33 | #include "search.h" |
||
| 34 | #include "hash.h" |
||
| 35 | #include "test.h" |
||
| 36 | #include "pgn.h" |
||
| 37 | #include "evaluation.h" |
||
| 38 | #include "coordination.h" |
||
| 39 | #include "xboard.h" |
||
| 40 | #include "book.h" |
||
| 41 | #ifdef INCLUDE_TABLEBASE_ACCESS |
||
| 42 | #include "tablebase.h" |
||
| 43 | #endif |
||
| 44 | |||
| 45 | const char *programVersionNumber = "1.9.0"; |
||
| 46 | |||
| 47 | int _distance[_64_][_64_]; |
||
| 48 | int _horizontalDistance[_64_][_64_]; |
||
| 49 | int _verticalDistance[_64_][_64_]; |
||
| 50 | int _taxiDistance[_64_][_64_]; |
||
| 51 | int castlingsOfColor[2]; |
||
| 52 | const int colorSign[2] = { 1, -1 }; |
||
| 53 | |||
| 54 | CommandlineOptions commandlineOptions; |
||
| 55 | UINT64 statCount1, statCount2; |
||
| 56 | int debugOutput = FALSE; |
||
| 57 | |||
| 58 | static void initializeModuleProctector() |
||
| 59 | { |
||
| 60 | int sq1, sq2; |
||
| 61 | |||
| 62 | ITERATE(sq1) |
||
| 63 | { |
||
| 64 | ITERATE(sq2) |
||
| 65 | { |
||
| 66 | _horizontalDistance[sq1][sq2] = abs(file(sq1) - file(sq2)); |
||
| 67 | _verticalDistance[sq1][sq2] = abs(rank(sq1) - rank(sq2)); |
||
| 68 | _distance[sq1][sq2] = |
||
| 69 | max(_horizontalDistance[sq1][sq2], _verticalDistance[sq1][sq2]); |
||
| 70 | _taxiDistance[sq1][sq2] = |
||
| 71 | _horizontalDistance[sq1][sq2] + _verticalDistance[sq1][sq2]; |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | castlingsOfColor[WHITE] = WHITE_00 | WHITE_000; |
||
| 76 | castlingsOfColor[BLACK] = BLACK_00 | BLACK_000; |
||
| 77 | |||
| 78 | initializeModuleIo(); |
||
| 79 | initializeModuleTools(); |
||
| 80 | initializeModuleCoordination(); |
||
| 81 | initializeModuleBitboard(); |
||
| 82 | initializeModulePosition(); |
||
| 83 | initializeModuleFen(); |
||
| 84 | initializeModuleMovegeneration(); |
||
| 85 | initializeModuleMatesearch(); |
||
| 86 | initializeModuleSearch(); |
||
| 87 | initializeModuleHash(); |
||
| 88 | initializeModuleTest(); |
||
| 89 | initializeModulePgn(); |
||
| 90 | #ifdef INCLUDE_TABLEBASE_ACCESS |
||
| 91 | initializeModuleTablebase(); |
||
| 92 | #endif |
||
| 93 | initializeModuleEvaluation(); |
||
| 94 | initializeModuleXboard(); |
||
| 95 | #ifdef USE_BOOK |
||
| 96 | initializeModuleBook(); |
||
| 97 | #endif |
||
| 98 | } |
||
| 99 | |||
| 100 | static void reportSuccess(const char *moduleName) |
||
| 101 | { |
||
| 102 | logDebug("Module %s tested successfully.\n", moduleName); |
||
| 103 | } |
||
| 104 | |||
| 105 | static int testModuleProtector() |
||
| 106 | { |
||
| 107 | assert(_horizontalDistance[C2][E6] == 2); |
||
| 108 | assert(_verticalDistance[C2][E6] == 4); |
||
| 109 | assert(_distance[C3][H8] == 5); |
||
| 110 | assert(_taxiDistance[B2][F7] == 9); |
||
| 111 | |||
| 112 | if (testModuleIo() != 0) |
||
| 113 | { |
||
| 114 | return -1; |
||
| 115 | } |
||
| 116 | else |
||
| 117 | { |
||
| 118 | reportSuccess("Io"); |
||
| 119 | } |
||
| 120 | |||
| 121 | if (testModuleTools() != 0) |
||
| 122 | { |
||
| 123 | return -1; |
||
| 124 | } |
||
| 125 | else |
||
| 126 | { |
||
| 127 | reportSuccess("Tools"); |
||
| 128 | } |
||
| 129 | |||
| 130 | if (testModuleCoordination() != 0) |
||
| 131 | { |
||
| 132 | return -1; |
||
| 133 | } |
||
| 134 | else |
||
| 135 | { |
||
| 136 | reportSuccess("Coordination"); |
||
| 137 | } |
||
| 138 | |||
| 139 | if (testModuleBitboard() != 0) |
||
| 140 | { |
||
| 141 | return -1; |
||
| 142 | } |
||
| 143 | else |
||
| 144 | { |
||
| 145 | reportSuccess("Bitboard"); |
||
| 146 | } |
||
| 147 | |||
| 148 | if (testModulePosition() != 0) |
||
| 149 | { |
||
| 150 | return -1; |
||
| 151 | } |
||
| 152 | else |
||
| 153 | { |
||
| 154 | reportSuccess("Position"); |
||
| 155 | } |
||
| 156 | |||
| 157 | if (testModuleFen() != 0) |
||
| 158 | { |
||
| 159 | return -1; |
||
| 160 | } |
||
| 161 | else |
||
| 162 | { |
||
| 163 | reportSuccess("Fen"); |
||
| 164 | } |
||
| 165 | |||
| 166 | if (testModuleMovegeneration() != 0) |
||
| 167 | { |
||
| 168 | return -1; |
||
| 169 | } |
||
| 170 | else |
||
| 171 | { |
||
| 172 | reportSuccess("Movegeneration"); |
||
| 173 | } |
||
| 174 | |||
| 175 | if (testModuleHash() != 0) |
||
| 176 | { |
||
| 177 | return -1; |
||
| 178 | } |
||
| 179 | else |
||
| 180 | { |
||
| 181 | reportSuccess("Hash"); |
||
| 182 | } |
||
| 183 | |||
| 184 | if (testModuleMatesearch() != 0) |
||
| 185 | { |
||
| 186 | return -1; |
||
| 187 | } |
||
| 188 | else |
||
| 189 | { |
||
| 190 | reportSuccess("Matesearch"); |
||
| 191 | } |
||
| 192 | |||
| 193 | if (testModuleSearch() != 0) |
||
| 194 | { |
||
| 195 | return -1; |
||
| 196 | } |
||
| 197 | else |
||
| 198 | { |
||
| 199 | reportSuccess("Search"); |
||
| 200 | } |
||
| 201 | |||
| 202 | if (testModulePgn() != 0) |
||
| 203 | { |
||
| 204 | return -1; |
||
| 205 | } |
||
| 206 | else |
||
| 207 | { |
||
| 208 | reportSuccess("Pgn"); |
||
| 209 | } |
||
| 210 | |||
| 211 | if (testModuleEvaluation() != 0) |
||
| 212 | { |
||
| 213 | return -1; |
||
| 214 | } |
||
| 215 | else |
||
| 216 | { |
||
| 217 | reportSuccess("Evaluation"); |
||
| 218 | } |
||
| 219 | |||
| 220 | if (testModuleXboard() != 0) |
||
| 221 | { |
||
| 222 | return -1; |
||
| 223 | } |
||
| 224 | else |
||
| 225 | { |
||
| 226 | reportSuccess("Xboard"); |
||
| 227 | } |
||
| 228 | |||
| 229 | #ifdef USE_BOOK |
||
| 230 | if (testModuleBook() != 0) |
||
| 231 | { |
||
| 232 | return -1; |
||
| 233 | } |
||
| 234 | else |
||
| 235 | { |
||
| 236 | reportSuccess("Book"); |
||
| 237 | } |
||
| 238 | #endif |
||
| 239 | |||
| 240 | #ifdef INCLUDE_TABLEBASE_ACCESS |
||
| 241 | if (testModuleTablebase() != 0) |
||
| 242 | { |
||
| 243 | return -1; |
||
| 244 | } |
||
| 245 | else |
||
| 246 | { |
||
| 247 | reportSuccess("Tablebase"); |
||
| 248 | } |
||
| 249 | #endif |
||
| 250 | |||
| 251 | if (testModuleTest() != 0) |
||
| 252 | { |
||
| 253 | return -1; |
||
| 254 | } |
||
| 255 | else |
||
| 256 | { |
||
| 257 | reportSuccess("Test"); |
||
| 258 | } |
||
| 259 | |||
| 260 | logDebug("\nModuletest finished successfully.\n"); |
||
| 261 | |||
| 262 | return 0; |
||
| 263 | } |
||
| 264 | |||
| 265 | static void parseOptions(int argc, char **argv, CommandlineOptions * options) |
||
| 266 | { |
||
| 267 | int i; |
||
| 268 | |||
| 269 | options->processModuleTest = FALSE; |
||
| 270 | options->xboardMode = TRUE; |
||
| 271 | options->dumpEvaluation = FALSE; |
||
| 272 | options->testfile = 0; |
||
| 273 | options->bookfile = 0; |
||
| 274 | options->tablebasePath = 0; |
||
| 275 | |||
| 276 | for (i = 0; i < argc; i++) |
||
| 277 | { |
||
| 278 | const char *currentArg = argv[i]; |
||
| 279 | |||
| 280 | if (strcmp(currentArg, "-m") == 0) |
||
| 281 | { |
||
| 282 | options->processModuleTest = TRUE; |
||
| 283 | options->xboardMode = FALSE; |
||
| 284 | } |
||
| 285 | |||
| 286 | if (strcmp(currentArg, "-d") == 0) |
||
| 287 | { |
||
| 288 | options->dumpEvaluation = TRUE; |
||
| 289 | } |
||
| 290 | |||
| 291 | if (strcmp(currentArg, "-t") == 0 && i < argc - 1) |
||
| 292 | { |
||
| 293 | options->testfile = argv[++i]; |
||
| 294 | options->xboardMode = FALSE; |
||
| 295 | } |
||
| 296 | |||
| 297 | if (strcmp(currentArg, "-e") == 0 && i < argc - 1) |
||
| 298 | { |
||
| 299 | options->tablebasePath = argv[++i]; |
||
| 300 | } |
||
| 301 | |||
| 302 | if (strcmp(currentArg, "-b") == 0 && i < argc - 1) |
||
| 303 | { |
||
| 304 | options->bookfile = argv[++i]; |
||
| 305 | } |
||
| 306 | |||
| 307 | if (strcmp(currentArg, "-v") == 0) |
||
| 308 | { |
||
| 309 | printf("Protector %s", programVersionNumber); |
||
| 310 | } |
||
| 311 | } |
||
| 312 | } |
||
| 313 | |||
| 314 | int main(int argc, char **argv) |
||
| 315 | { |
||
| 316 | |||
| 317 | parseOptions(argc, argv, &commandlineOptions); |
||
| 318 | initializeModuleProctector(); |
||
| 319 | /* logDebug("protector initialized\n"); */ |
||
| 320 | |||
| 321 | if (commandlineOptions.xboardMode) |
||
| 322 | { |
||
| 323 | acceptGuiCommands(); |
||
| 324 | |||
| 325 | return 0; |
||
| 326 | } |
||
| 327 | |||
| 328 | if (commandlineOptions.processModuleTest) |
||
| 329 | { |
||
| 330 | if (testModuleProtector() != 0) |
||
| 331 | { |
||
| 332 | logDebug("\n##### Moduletest failed! #####\n"); |
||
| 333 | getKeyStroke(); |
||
| 334 | |||
| 335 | return -1; |
||
| 336 | } |
||
| 337 | } |
||
| 338 | |||
| 339 | if (commandlineOptions.testfile != 0) |
||
| 340 | { |
||
| 341 | if (processTestsuite(commandlineOptions.testfile) != 0) |
||
| 342 | { |
||
| 343 | return -1; |
||
| 344 | } |
||
| 345 | } |
||
| 346 | |||
| 347 | if (commandlineOptions.bookfile != 0) |
||
| 348 | { |
||
| 349 | createEmptyBook(&globalBook); |
||
| 350 | appendBookDatabase(&globalBook, commandlineOptions.bookfile, 50); |
||
| 351 | closeBook(&globalBook); |
||
| 352 | } |
||
| 353 | |||
| 354 | logDebug("Main thread terminated.\n"); |
||
| 355 | |||
| 356 | return 0; |
||
| 357 | } |