Subversion Repositories Games.Chess Giants

Rev

Rev 192 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 192 Rev 193
Line 136... Line 136...
136
bool PlayerEngine_Think (player_t *player)
136
bool PlayerEngine_Think (player_t *player)
137
{
137
{
138
   // this function reads and writes any necessary data from and to the chess engine. Returns TRUE if scene needs to be updated.
138
   // this function reads and writes any necessary data from and to the chess engine. Returns TRUE if scene needs to be updated.
139
 
139
 
140
   engineprogram_t *program;
140
   engineprogram_t *program;
141
   wchar_t line_buffer[1024];
141
   wchar_t line_buffer[1024] = L"";
142
   wchar_t *line_pointer;
142
   wchar_t *line_pointer;
143
   wchar_t *move_string;
143
   wchar_t *move_string;
144
   int64_t exit_code;
144
   int64_t exit_code;
145
   int engine_index;
145
   int engine_index;
146
   int char_index;
146
   int char_index;
Line 335... Line 335...
335
         continue; // if string is too short to be a move, skip it
335
         continue; // if string is too short to be a move, skip it
336
 
336
 
337
      // there must be valid move data on that line.
337
      // there must be valid move data on that line.
338
 
338
 
339
      // evaluate the engine move string
339
      // evaluate the engine move string
-
 
340
      memset (&move, 0, sizeof (move));
340
      memcpy (move.slots, the_board.moves[the_board.move_count - 1].slots, sizeof (move.slots));
341
      memcpy (move.slots, the_board.moves[the_board.move_count - 1].slots, sizeof (move.slots));
341
      char_index = 0;
342
      char_index = 0;
342
      while ((move_string[char_index] != 0) && !iswspace (move_string[char_index]))
343
      while ((move_string[char_index] != 0) && !iswspace (move_string[char_index]))
343
      {
344
      {
344
         move.pgntext[char_index] = move_string[char_index];
345
         move.pgntext[char_index] = move_string[char_index];
Line 565... Line 566...
565
}
566
}
566
 
567
 
567
 
568
 
568
int wcs_replace (wchar_t *haystack, wchar_t *needle, wchar_t *replacement)
569
int wcs_replace (wchar_t *haystack, wchar_t *needle, wchar_t *replacement)
569
{
570
{
-
 
571
   // FIXME: REWRITE TAKING IN ACCOUNT MAX BUF SIZE
-
 
572
 
570
   size_t replacement_length;
573
   size_t replacement_length;
571
   size_t replacement_count;
574
   size_t replacement_count;
572
   size_t pattern_length;
575
   size_t pattern_length;
573
   wchar_t *line_pointer;
576
   wchar_t *line_pointer;
574
 
577
 
575
   replacement_count = 0;
578
   replacement_count = 0;
-
 
579
   pattern_length = wcslen (needle);
-
 
580
   replacement_length = wcslen (replacement);
576
   while ((line_pointer = wcsstr (haystack, needle)) != NULL)
581
   while ((line_pointer = wcsstr (haystack, needle)) != NULL)
577
   {
582
   {
578
      pattern_length = wcslen (needle);
-
 
579
      replacement_length = wcslen (replacement);
-
 
580
      memmove (&line_pointer[replacement_length], &line_pointer[pattern_length], (wcslen (&line_pointer[pattern_length]) + 1) * sizeof (wchar_t));
583
      memmove (&line_pointer[replacement_length], &line_pointer[pattern_length], (wcslen (&line_pointer[pattern_length]) + 1) * sizeof (wchar_t));
581
      memcpy (line_pointer, replacement, replacement_length * sizeof (wchar_t));
584
      memcpy (line_pointer, replacement, replacement_length * sizeof (wchar_t));
582
      replacement_count++;
585
      replacement_count++;
583
   }
586
   }
584
 
587