Rev 171 | Rev 179 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 171 | Rev 177 | ||
---|---|---|---|
Line 803... | Line 803... | ||
803 | 803 | ||
804 | return; // finished |
804 | return; // finished |
805 | } |
805 | } |
806 | 806 | ||
807 | 807 | ||
- | 808 | void Debug_LogMove (boardmove_t *move, const wchar_t *fmt, ...) |
|
- | 809 | { |
|
- | 810 | // helper function for debug logging |
|
- | 811 | ||
- | 812 | FILE *fp; |
|
- | 813 | va_list argptr; |
|
- | 814 | int i; |
|
- | 815 | int j; |
|
- | 816 | ||
- | 817 | // open the log file in append mode |
|
- | 818 | _wfopen_s (&fp, logfile_pathname, L"ab"); |
|
- | 819 | if (fp != NULL) |
|
- | 820 | { |
|
- | 821 | va_start (argptr, fmt); |
|
- | 822 | vfwprintf_s (fp, fmt, argptr); // concatenate all the arguments in one string |
|
- | 823 | va_end (argptr); |
|
- | 824 | ||
- | 825 | // capture and encode the move |
|
- | 826 | fwprintf (fp, L"\t+---+---+---+---+---+---+---+---+\n"); |
|
- | 827 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
|
- | 828 | { |
|
- | 829 | fwprintf (fp, L"\t|"); |
|
- | 830 | for (j = 0; j < 8; j++) |
|
- | 831 | { |
|
- | 832 | if (move->slots[i][j].part == PART_ROOK) fwprintf (fp, (move->slots[i][j].color == COLOR_WHITE ? L" R |" : L" r |")); |
|
- | 833 | else if (move->slots[i][j].part == PART_KNIGHT) fwprintf (fp, (move->slots[i][j].color == COLOR_WHITE ? L" N |" : L" n |")); |
|
- | 834 | else if (move->slots[i][j].part == PART_BISHOP) fwprintf (fp, (move->slots[i][j].color == COLOR_WHITE ? L" B |" : L" b |")); |
|
- | 835 | else if (move->slots[i][j].part == PART_QUEEN) fwprintf (fp, (move->slots[i][j].color == COLOR_WHITE ? L" Q |" : L" q |")); |
|
- | 836 | else if (move->slots[i][j].part == PART_KING) fwprintf (fp, (move->slots[i][j].color == COLOR_WHITE ? L" K |" : L" k |")); |
|
- | 837 | else if (move->slots[i][j].part == PART_PAWN) fwprintf (fp, (move->slots[i][j].color == COLOR_WHITE ? L" P |" : L" p |")); |
|
- | 838 | else fwprintf (fp, L" |"); |
|
- | 839 | } |
|
- | 840 | fwprintf (fp, L"\n"); |
|
- | 841 | fwprintf (fp, L"\t+---+---+---+---+---+---+---+---+\n"); |
|
- | 842 | } |
|
- | 843 | ||
- | 844 | fclose (fp); // flush buffers and close it |
|
- | 845 | } |
|
- | 846 | ||
- | 847 | return; // finished |
|
- | 848 | } |
|
- | 849 | ||
- | 850 | ||
808 | bool Debug_SendLogToAuthor (bool should_include_description) |
851 | bool Debug_SendLogToAuthor (char *reason, bool should_include_description) |
809 | { |
852 | { |
810 | // this function upload the engine history to the remote server for debug purposes. |
853 | // this function upload the engine history to the remote server for debug purposes. |
811 | 854 | ||
812 | static wchar_t descriptionfile_pathname[MAX_PATH]; |
855 | static wchar_t descriptionfile_pathname[MAX_PATH]; |
813 | static char log_buffer[512 * 1024]; |
856 | static char log_buffer[512 * 1024]; |
Line 838... | Line 881... | ||
838 | _wfopen_s (&fp, logfile_pathname, L"rb"); |
881 | _wfopen_s (&fp, logfile_pathname, L"rb"); |
839 | if (fp != NULL) |
882 | if (fp != NULL) |
840 | { |
883 | { |
841 | fseek (fp, 0, SEEK_END); |
884 | fseek (fp, 0, SEEK_END); |
842 | length = ftell (fp); // get file size |
885 | length = ftell (fp); // get file size |
843 | fseek (fp, 0, SEEK_SET); |
- | |
844 | if (length > sizeof (log_base64buffer) - 1) |
886 | if (length > sizeof (log_base64buffer) - 1) |
- | 887 | swprintf_s ((wchar_t *) log_base64buffer, WCHAR_SIZEOF (log_base64buffer), L"Log file at \"%s\" too big (> %d bytes).", logfile_pathname, sizeof (log_base64buffer) - 1); // history file too big |
|
- | 888 | else |
|
- | 889 | { |
|
845 |
|
890 | fseek (fp, 0, SEEK_SET); |
846 | fread (log_base64buffer, 1, length, fp); |
891 | fread (log_base64buffer, 1, length, fp); |
847 | log_base64buffer[length] = 0; // terminate buffer ourselves |
892 | log_base64buffer[length] = 0; // terminate buffer ourselves |
- | 893 | } |
|
848 | fclose (fp); |
894 | fclose (fp); |
849 | ConvertTo7BitASCII (log_buffer, sizeof (log_buffer), (wchar_t *) log_base64buffer); |
- | |
850 | } |
895 | } |
851 | else |
896 | else |
- | 897 | swprintf_s ((wchar_t *) log_base64buffer, WCHAR_SIZEOF (log_base64buffer), L"Couldn't open log file at \"%s\".", logfile_pathname); // couldn't open game history log file |
|
852 |
|
898 | ConvertTo7BitASCII (log_buffer, sizeof (log_buffer), (wchar_t *) log_base64buffer); |
853 | 899 | ||
854 | // should the user include a problem report ? |
900 | // should the user include a problem report ? |
855 | if (should_include_description) |
901 | if (should_include_description) |
856 | { |
902 | { |
857 | // have the user describe his problem with Notepad |
903 | // have the user describe his problem with Notepad |
Line 886... | Line 932... | ||
886 | return (false); // history file too big, return an error condition |
932 | return (false); // history file too big, return an error condition |
887 | fread (description_base64buffer, 1, length, fp); |
933 | fread (description_base64buffer, 1, length, fp); |
888 | description_base64buffer[length] = 0; // terminate buffer ourselves |
934 | description_base64buffer[length] = 0; // terminate buffer ourselves |
889 | fclose (fp); |
935 | fclose (fp); |
890 | _wunlink (descriptionfile_pathname); // as soon as it's read, DELETE the error description file |
936 | _wunlink (descriptionfile_pathname); // as soon as it's read, DELETE the error description file |
891 | ConvertTo7BitASCII (description_buffer, sizeof (description_buffer), (wchar_t *) description_base64buffer); |
- | |
892 | } |
937 | } |
893 | else |
938 | else |
- | 939 | swprintf_s ((wchar_t *) description_base64buffer, WCHAR_SIZEOF (description_base64buffer), L"Couldn't open error description file at \"%s\".", descriptionfile_pathname); // couldn't open error description file |
|
894 |
|
940 | ConvertTo7BitASCII (description_buffer, sizeof (description_buffer), (wchar_t *) description_base64buffer); |
895 | } |
941 | } |
896 | else |
942 | else |
897 | description_buffer[0] = 0; // no description |
943 | description_buffer[0] = 0; // no description |
- | 944 | ||
- | 945 | // append the program-given reason to the description buffer |
|
- | 946 | strcat_s (description_buffer, sizeof (description_buffer), "\n\nChess Giants reason: "); |
|
- | 947 | strcat_s (description_buffer, sizeof (description_buffer), reason); |
|
898 | 948 | ||
899 | // capture and encode the board |
949 | // capture and encode the board |
900 | strcpy_s (board_buffer, sizeof (board_buffer), "+---+---+---+---+---+---+---+---+\n"); |
950 | strcpy_s (board_buffer, sizeof (board_buffer), "+---+---+---+---+---+---+---+---+\n"); |
901 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
951 | for (i = 7; i >= 0; i--) // lines are in reverse order in this stupid program of mine >.< |
902 | { |
952 | { |