Rev 33 | Rev 40 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 33 | Rev 39 | ||
---|---|---|---|
Line 92... | Line 92... | ||
92 | // could the init file be opened ? |
92 | // could the init file be opened ? |
93 | if (fp != NULL) |
93 | if (fp != NULL) |
94 | { |
94 | { |
95 | Debug_Log (L"===Found initialization file, parsing...===\n"); |
95 | Debug_Log (L"===Found initialization file, parsing...===\n"); |
96 | 96 | ||
97 | // SMP HACK -- is our engine Crafty ? if so, set the max CPUs to use to core max - 1 |
97 | // SMP HACK -- is our engine Crafty or GNU Chess ? if so, set the max CPUs to use to core max - 1 |
98 | // (the computer will look like hung if all CPU is taken) |
98 | // (the computer will look like hung if all CPU is taken) |
99 | if (wcsistr (options.engine.name, L"Crafty") != NULL) |
99 | if ((wcsistr (options.engine.name, L"Crafty") != NULL) || (wcsistr (options.engine.name, L"GNU Chess") != NULL)) |
100 | { |
100 | { |
101 | GetSystemInfo (&sysinfo); // get the number of cores and build the corresponding engine initialization order |
101 | GetSystemInfo (&sysinfo); // get the number of cores and build the corresponding engine initialization order |
102 |
|
102 | Player_SendBuffer_Add (player, 1000, L"mt %d\n", max (1, sysinfo.dwNumberOfProcessors - 1)); |
103 | Player_SendBuffer_Add (player, 1000, widechar_buffer); |
- | |
104 | } |
103 | } |
105 | 104 | ||
106 | // read line per line |
105 | // read line per line |
107 | while (fgetws (widechar_buffer, WCHAR_SIZEOF (widechar_buffer), fp) != NULL) |
106 | while (fgetws (widechar_buffer, WCHAR_SIZEOF (widechar_buffer), fp) != NULL) |
108 | { |
107 | { |
Line 130... | Line 129... | ||
130 | unsigned long exit_code; |
129 | unsigned long exit_code; |
131 | unsigned long handle_flags; |
130 | unsigned long handle_flags; |
132 | int attempt_index; |
131 | int attempt_index; |
133 | 132 | ||
134 | // send the engine a quit command |
133 | // send the engine a quit command |
135 | Player_SendBuffer_Add (player, 1000 |
134 | Player_SendBuffer_Add (player, 1000, options.engine.command_quit); |
- | 135 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
136 | PlayerEngine_Send (player); |
136 | PlayerEngine_Send (player); |
137 | 137 | ||
138 | // close the pipe handles |
138 | // close the pipe handles |
139 | if (hChessEngineStdinRd) |
139 | if (hChessEngineStdinRd) |
140 | CloseHandle (hChessEngineStdinRd); |
140 | CloseHandle (hChessEngineStdinRd); |
Line 309... | Line 309... | ||
309 | 309 | ||
310 | // is it NOT a hint, are blunders allowed, should we do one now AND can we do one now ? |
310 | // is it NOT a hint, are blunders allowed, should we do one now AND can we do one now ? |
311 | if (!is_hint && (options.engine.blunder_chances > 0) && (rand () % 100 < options.engine.blunder_chances) |
311 | if (!is_hint && (options.engine.blunder_chances > 0) && (rand () % 100 < options.engine.blunder_chances) |
312 | && Move_FindRandomMove (&the_board.moves[the_board.move_count - 1], player->color, &move)) |
312 | && Move_FindRandomMove (&the_board.moves[the_board.move_count - 1], player->color, &move)) |
313 | { |
313 | { |
314 | Player_SendBuffer_Add (player, 1000 |
314 | Player_SendBuffer_Add (player, 1000, options.engine.command_force, Move_BuildString (&move)); // send the blunderous move to the engine |
- | 315 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
- | 316 | if (wcscmp (options.engine.program, L"Crafty") == 0) |
|
315 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
317 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
316 | Debug_Log (L"===Discarding engine move, forcing a blunderous move (%s) instead===\n", Move_BuildString (&move)); // blunder |
318 | Debug_Log (L"===Discarding engine move, forcing a blunderous move (%s) instead===\n", Move_BuildString (&move)); // blunder |
317 | } |
319 | } |
318 | 320 | ||
319 | // mark the engine's selected and hovered squares |
321 | // mark the engine's selected and hovered squares |
320 | Board_SetSelectedAndHovered (&the_board, move.source[0], move.source[1], move.target[0], move.target[1]); |
322 | Board_SetSelectedAndHovered (&the_board, move.source[0], move.source[1], move.target[0], move.target[1]); |
Line 361... | Line 363... | ||
361 | if (the_board.was_setup) |
363 | if (the_board.was_setup) |
362 | { |
364 | { |
363 | Debug_Log (L"===Got board setup notification from interface===\n"); |
365 | Debug_Log (L"===Got board setup notification from interface===\n"); |
364 | 366 | ||
365 | // send a new game command to the chess engine |
367 | // send a new game command to the chess engine |
366 | Player_SendBuffer_Add (player, 1000 |
368 | Player_SendBuffer_Add (player, 1000, options.engine.command_new); |
- | 369 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
367 | 370 | ||
368 | // just set up the board from its Forsyth-Edwards notation |
371 | // just set up the board from its Forsyth-Edwards notation |
369 | Debug_Log (L"===setting up board using FEN string===\n"); |
372 | Debug_Log (L"===setting up board using FEN string===\n"); |
370 | 373 | ||
371 | // instruct it about its allowed search depth BEFORE each table set (this ensures engine will be "ready" to handle the command) |
374 | // instruct it about its allowed search depth BEFORE each table set (this ensures engine will be "ready" to handle the command) |
372 | // then get the current game state in FEN format and feed it to the engine |
375 | // then get the current game state in FEN format and feed it to the engine |
373 | Player_SendBuffer_Add (player, 1000 |
376 | Player_SendBuffer_Add (player, 1000, options.engine.command_sd, options.engine.depth); |
- | 377 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
374 | Player_SendBuffer_Add (player, 1000 |
378 | Player_SendBuffer_Add (player, 1000, options.engine.command_setboard, the_board.moves[the_board.move_count - 1].fen_string); |
- | 379 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
375 | 380 | ||
376 | // and reset current obstinacy |
381 | // and reset current obstinacy |
377 | current_obstinacy = 0; |
382 | current_obstinacy = 0; |
378 | 383 | ||
- | 384 | if (wcscmp (options.engine.program, L"Crafty") == 0) |
|
379 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
385 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
380 | } |
386 | } |
381 | 387 | ||
382 | // have we been notified that players are swapping colors ? (N.B. when this happens in human vs. computer mode, it's always that the human player is *GIVING* his turn) |
388 | // have we been notified that players are swapping colors ? (N.B. when this happens in human vs. computer mode, it's always that the human player is *GIVING* his turn) |
383 | if (the_board.want_playerswap) |
389 | if (the_board.want_playerswap) |
384 | { |
390 | { |
385 | Debug_Log (L"===Got player SWAP notification from interface===\n"); |
391 | Debug_Log (L"===Got player SWAP notification from interface===\n"); |
386 | Player_SendBuffer_Add (player, 1000 |
392 | Player_SendBuffer_Add (player, 1000, options.engine.command_go); // tell engine it's now the current player |
- | 393 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
387 | } |
394 | } |
388 | 395 | ||
389 | // have we been notified that the current player just changed ? |
396 | // have we been notified that the current player just changed ? |
390 | if (the_board.has_playerchanged) |
397 | if (the_board.has_playerchanged) |
391 | { |
398 | { |
Line 395... | Line 402... | ||
395 | if (Board_ColorToMove (&the_board) == player->color) |
402 | if (Board_ColorToMove (&the_board) == player->color) |
396 | { |
403 | { |
397 | // is it NOT a board setup AND has at least one move been played (meaning it was just the other's turn before) ? |
404 | // is it NOT a board setup AND has at least one move been played (meaning it was just the other's turn before) ? |
398 | if (!the_board.was_setup && (the_board.move_count > 1)) |
405 | if (!the_board.was_setup && (the_board.move_count > 1)) |
399 | { |
406 | { |
400 | Debug_Log (L"===Player just played, sending |
407 | Debug_Log (L"===Player just played, sending the chosen move to engine===\n"); |
- | 408 | if (wcscmp (options.engine.program, L"Crafty") == 0) |
|
401 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
409 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
402 | 410 | ||
403 | // instruct it about its allowed search depth BEFORE each move (this ensures engine will be "ready" to handle the command) |
411 | // instruct it about its allowed search depth BEFORE each move (this ensures engine will be "ready" to handle the command) |
404 | // then build the move string, and send the move string to the engine |
412 | // then build the move string, and send the move string to the engine |
405 | Player_SendBuffer_Add (player, 1000 |
413 | Player_SendBuffer_Add (player, 1000, options.engine.command_sd, options.engine.depth); |
- | 414 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
406 | Player_SendBuffer_Add (player, 1000 |
415 | Player_SendBuffer_Add (player, 1000, Move_BuildString (&the_board.moves[the_board.move_count - 1])); |
- | 416 | Player_SendBuffer_Add (player, 1000, L"\n"); // end the send buffer with a carriage return |
|
407 | } |
417 | } |
408 | 418 | ||
409 | // else game has not started yet, but it's our turn |
419 | // else game has not started yet, but it's our turn |
410 | else |
420 | else |
- | 421 | { |
|
411 | Player_SendBuffer_Add (player, 1000 |
422 | Player_SendBuffer_Add (player, 1000, options.engine.command_go); // so let's start the game |
- | 423 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
- | 424 | } |
|
412 | } |
425 | } |
413 | } |
426 | } |
414 | 427 | ||
415 | // END NOTIFICATIONS PROCESSING |
428 | // END NOTIFICATIONS PROCESSING |
416 | /////////////////////////////// |
429 | /////////////////////////////// |
Line 420... | Line 433... | ||
420 | { |
433 | { |
421 | // does our opponent want a hint ? |
434 | // does our opponent want a hint ? |
422 | if (current_player->wants_hint) |
435 | if (current_player->wants_hint) |
423 | { |
436 | { |
424 | current_player->wants_hint = false; // don't ask twice |
437 | current_player->wants_hint = false; // don't ask twice |
425 | Debug_Log (L"===Hint requested, asking |
438 | Debug_Log (L"===Hint requested, asking engine for it===\n"); |
426 | Player_SendBuffer_Add (player, 1000 |
439 | Player_SendBuffer_Add (player, 1000, options.engine.command_hint); // ask for a hint |
- | 440 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
427 | } |
441 | } |
428 | 442 | ||
429 | // does our opponent want to cancel a move ? |
443 | // does our opponent want to cancel a move ? |
430 | if (current_player->wants_cancel) |
444 | if (current_player->wants_cancel) |
431 | { |
445 | { |
432 | current_player->wants_cancel = false; // don't ask twice (remember now before we switch players) |
446 | current_player->wants_cancel = false; // don't ask twice (remember now before we switch players) |
433 | Debug_Log (L"===Move cancellation requested, rebuilding board and telling |
447 | Debug_Log (L"===Move cancellation requested, rebuilding board and telling engine to backup 2 moves===\n"); |
434 | 448 | ||
435 | // rewind game 2 moves back |
449 | // rewind game 2 moves back |
436 | the_board.moves = (boardmove_t *) SAFE_realloc (the_board.moves, the_board.move_count, max (1, the_board.move_count - 2), sizeof (boardmove_t), false); |
450 | the_board.moves = (boardmove_t *) SAFE_realloc (the_board.moves, the_board.move_count, max (1, the_board.move_count - 2), sizeof (boardmove_t), false); |
437 | the_board.move_count = max (1, the_board.move_count - 2); // figure out how many moves we have now |
451 | the_board.move_count = max (1, the_board.move_count - 2); // figure out how many moves we have now |
438 | the_board.viewed_move = the_board.move_count - 1; // take us back to the last move |
452 | the_board.viewed_move = the_board.move_count - 1; // take us back to the last move |
Line 440... | Line 454... | ||
440 | // just set up the board from its Forsyth-Edwards notation |
454 | // just set up the board from its Forsyth-Edwards notation |
441 | Debug_Log (L"===setting up board using FEN string===\n"); |
455 | Debug_Log (L"===setting up board using FEN string===\n"); |
442 | 456 | ||
443 | // instruct it about its allowed search depth BEFORE each table set (this ensures engine will be "ready" to handle the command) |
457 | // instruct it about its allowed search depth BEFORE each table set (this ensures engine will be "ready" to handle the command) |
444 | // then get the current game state in FEN format and feed it to the engine |
458 | // then get the current game state in FEN format and feed it to the engine |
445 | Player_SendBuffer_Add (player, 1000 |
459 | Player_SendBuffer_Add (player, 1000, options.engine.command_sd, options.engine.depth); |
- | 460 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
446 | Player_SendBuffer_Add (player, 1000 |
461 | Player_SendBuffer_Add (player, 1000, options.engine.command_setboard, the_board.moves[the_board.move_count - 1].fen_string); |
- | 462 | Player_SendBuffer_Add (player, 1000, L"\n"); // since the format string was read from the options, don't forget to end it with a carriage return |
|
447 | 463 | ||
- | 464 | if (wcscmp (options.engine.program, L"Crafty") == 0) |
|
448 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
465 | Player_SendBuffer_Add (player, 1000, L"disp\n"); |
449 | 466 | ||
450 | do_update = true; // remember to update the 3D scene |
467 | do_update = true; // remember to update the 3D scene |
451 | } |
468 | } |
452 | } |
469 | } |
453 | 470 |