Rev 68 | Rev 71 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 68 | Rev 69 | ||
---|---|---|---|
Line 22... | Line 22... | ||
22 | 22 | ||
23 | 23 | ||
24 | // prototypes of local functions |
24 | // prototypes of local functions |
25 | static void PGNFile_GameList_Init (int entry_count); |
25 | static void PGNFile_GameList_Init (int entry_count); |
26 | static void PGNFile_GameList_Shutdown (void); |
26 | static void PGNFile_GameList_Shutdown (void); |
- | 27 | static wchar_t *PGNFile_NAGTextFromCode (int nag_code); |
|
27 | static char *sgets (char *destination_line, int max_length, char *source_buffer); |
28 | static char *sgets (char *destination_line, int max_length, char *source_buffer); |
28 | 29 | ||
29 | 30 | ||
30 | bool PGNFile_Load (const wchar_t *pgnfile_pathname) |
31 | bool PGNFile_Load (const wchar_t *pgnfile_pathname) |
31 | { |
32 | { |
Line 126... | Line 127... | ||
126 | // the user didn't want to chose any game at all, so just free the games list and return a success value. |
127 | // the user didn't want to chose any game at all, so just free the games list and return a success value. |
127 | 128 | ||
128 | static wchar_t pgn_comment[65536]; // declared static so as not to reallocate it |
129 | static wchar_t pgn_comment[65536]; // declared static so as not to reallocate it |
129 | 130 | ||
130 | boardmove_t new_move; |
131 | boardmove_t new_move; |
- | 132 | int nag_code; |
|
131 | int length; |
133 | int length; |
132 | int char_index; |
134 | int char_index; |
133 | int fieldstart; |
135 | int fieldstart; |
134 | int fieldstop; |
136 | int fieldstop; |
135 | int variation_depth; |
137 | int variation_depth; |
Line 216... | Line 218... | ||
216 | ConvertCRLFsToSingleSpaces (pgn_comment); // linearize string |
218 | ConvertCRLFsToSingleSpaces (pgn_comment); // linearize string |
217 | 219 | ||
218 | continue; // and proceed to the next data |
220 | continue; // and proceed to the next data |
219 | } |
221 | } |
220 | 222 | ||
221 | // else is it a numeric annotation glyph ? |
223 | // else is it a numeric annotation glyph ? |
222 | else if (pgnfile_data[char_index] == '$') |
224 | else if (pgnfile_data[char_index] == '$') |
223 | { |
225 | { |
- | 226 | nag_code = atoi (&pgnfile_data[char_index + 1]); // read it |
|
- | 227 | ||
- | 228 | // now copy out as a comment |
|
- | 229 | if (pgn_comment[0] != 0) |
|
- | 230 | wcscat_s (pgn_comment, WCHAR_SIZEOF (pgn_comment), L" "); |
|
- | 231 | length = wcslen (pgn_comment); |
|
- | 232 | swprintf_s (&pgn_comment[length], WCHAR_SIZEOF (pgn_comment) - length, L"[NAG: %s]", PGNFile_NAGTextFromCode (nag_code)); |
|
- | 233 | ||
224 | while ((char_index < (int) pgnfile_size) && !isspace (pgnfile_data[char_index])) |
234 | while ((char_index < (int) pgnfile_size) && !isspace (pgnfile_data[char_index])) |
225 | char_index++; // figure out where it stops |
235 | char_index++; // figure out where it stops |
226 | while ((char_index < (int) pgnfile_size) && isspace (pgnfile_data[char_index])) |
236 | while ((char_index < (int) pgnfile_size) && isspace (pgnfile_data[char_index])) |
227 | char_index++; // figure out where the next word starts |
237 | char_index++; // figure out where the next word starts |
228 | 238 | ||
Line 307... | Line 317... | ||
307 | } |
317 | } |
308 | 318 | ||
309 | // save the players' names |
319 | // save the players' names |
310 | wcscpy_s (board->players[COLOR_WHITE].name, WCHAR_SIZEOF (board->players[COLOR_WHITE].name), game->white_str); |
320 | wcscpy_s (board->players[COLOR_WHITE].name, WCHAR_SIZEOF (board->players[COLOR_WHITE].name), game->white_str); |
311 | wcscpy_s (board->players[COLOR_BLACK].name, WCHAR_SIZEOF (board->players[COLOR_BLACK].name), game->black_str); |
321 | wcscpy_s (board->players[COLOR_BLACK].name, WCHAR_SIZEOF (board->players[COLOR_BLACK].name), game->black_str); |
312 | 322 | ||
313 | // we loaded the game we want, we no longer need the games array |
323 | // we loaded the game we want, we no longer need the games array |
314 | PGNFile_GameList_Shutdown (); |
324 | PGNFile_GameList_Shutdown (); |
315 | 325 | ||
316 | // we no longer need the file data space, so free it |
326 | // we no longer need the file data space, so free it |
317 | SAFE_free ((void **) &pgnfile_data); |
327 | SAFE_free ((void **) &pgnfile_data); |
Line 455... | Line 465... | ||
455 | 465 | ||
456 | SAFE_free ((void **) &games); // free the PGN games array |
466 | SAFE_free ((void **) &games); // free the PGN games array |
457 | game_count = 0; |
467 | game_count = 0; |
458 | 468 | ||
459 | return; // finished |
469 | return; // finished |
- | 470 | } |
|
- | 471 | ||
- | 472 | ||
- | 473 | static wchar_t *PGNFile_NAGTextFromCode (int nag_code) |
|
- | 474 | { |
|
- | 475 | // helper function that returns the NAG (numeric annotation glyph) text that corresponds to a particular code |
|
- | 476 | ||
- | 477 | typedef struct nag_s |
|
- | 478 | { |
|
- | 479 | int code; |
|
- | 480 | wchar_t *text; |
|
- | 481 | } nag_t; |
|
- | 482 | nag_t nag_codes[] = |
|
- | 483 | { |
|
- | 484 | { 1, L"good move" }, |
|
- | 485 | { 2, L"poor move or mistake" }, |
|
- | 486 | { 3, L"very good or brilliant move" }, |
|
- | 487 | { 4, L"very poor move or blunder" }, |
|
- | 488 | { 5, L"speculative or interesting move" }, |
|
- | 489 | { 6, L"questionable or dubious move" }, |
|
- | 490 | { 7, L"forced move (all others lose quickly) or only move" }, |
|
- | 491 | { 8, L"singular move (no reasonable alternatives)" }, |
|
- | 492 | { 9, L"worst move" }, |
|
- | 493 | { 10, L"drawish position or even" }, |
|
- | 494 | { 11, L"equal chances, quiet position" }, |
|
- | 495 | { 12, L"equal chances, active position" }, |
|
- | 496 | { 13, L"unclear position" }, |
|
- | 497 | { 14, L"White has a slight advantage" }, |
|
- | 498 | { 15, L"Black has a slight advantage" }, |
|
- | 499 | { 16, L"White has a moderate advantage" }, |
|
- | 500 | { 17, L"Black has a moderate advantage" }, |
|
- | 501 | { 18, L"White has a decisive advantage" }, |
|
- | 502 | { 19, L"Black has a decisive advantage" }, |
|
- | 503 | { 20, L"White has a crushing advantage (Black should resign)" }, |
|
- | 504 | { 21, L"Black has a crushing advantage (White should resign)" }, |
|
- | 505 | { 22, L"White is in zugzwang" }, |
|
- | 506 | { 23, L"Black is in zugzwang" }, |
|
- | 507 | { 24, L"White has a slight space advantage" }, |
|
- | 508 | { 25, L"Black has a slight space advantage" }, |
|
- | 509 | { 26, L"White has a moderate space advantage" }, |
|
- | 510 | { 27, L"Black has a moderate space advantage" }, |
|
- | 511 | { 28, L"White has a decisive space advantage" }, |
|
- | 512 | { 29, L"Black has a decisive space advantage" }, |
|
- | 513 | { 30, L"White has a slight time (development) advantage" }, |
|
- | 514 | { 31, L"Black has a slight time (development) advantage" }, |
|
- | 515 | { 32, L"White has a moderate time (development) advantage" }, |
|
- | 516 | { 33, L"Black has a moderate time (development) advantage" }, |
|
- | 517 | { 34, L"White has a decisive time (development) advantage" }, |
|
- | 518 | { 35, L"Black has a decisive time (development) advantage" }, |
|
- | 519 | { 36, L"White has the initiative" }, |
|
- | 520 | { 37, L"Black has the initiative" }, |
|
- | 521 | { 38, L"White has a lasting initiative" }, |
|
- | 522 | { 39, L"Black has a lasting initiative" }, |
|
- | 523 | { 40, L"White has the attack" }, |
|
- | 524 | { 41, L"Black has the attack" }, |
|
- | 525 | { 42, L"White has insufficient compensation for material deficit" }, |
|
- | 526 | { 43, L"Black has insufficient compensation for material deficit" }, |
|
- | 527 | { 44, L"White has sufficient compensation for material deficit" }, |
|
- | 528 | { 45, L"Black has sufficient compensation for material deficit" }, |
|
- | 529 | { 46, L"White has more than adequate compensation for material deficit" }, |
|
- | 530 | { 47, L"Black has more than adequate compensation for material deficit" }, |
|
- | 531 | { 48, L"White has a slight center control advantage" }, |
|
- | 532 | { 49, L"Black has a slight center control advantage" }, |
|
- | 533 | { 50, L"White has a moderate center control advantage" }, |
|
- | 534 | { 51, L"Black has a moderate center control advantage" }, |
|
- | 535 | { 52, L"White has a decisive center control advantage" }, |
|
- | 536 | { 53, L"Black has a decisive center control advantage" }, |
|
- | 537 | { 54, L"White has a slight kingside control advantage" }, |
|
- | 538 | { 55, L"Black has a slight kingside control advantage" }, |
|
- | 539 | { 56, L"White has a moderate kingside control advantage" }, |
|
- | 540 | { 57, L"Black has a moderate kingside control advantage" }, |
|
- | 541 | { 58, L"White has a decisive kingside control advantage" }, |
|
- | 542 | { 59, L"Black has a decisive kingside control advantage" }, |
|
- | 543 | { 60, L"White has a slight queenside control advantage" }, |
|
- | 544 | { 61, L"Black has a slight queenside control advantage" }, |
|
- | 545 | { 62, L"White has a moderate queenside control advantage" }, |
|
- | 546 | { 63, L"Black has a moderate queenside control advantage" }, |
|
- | 547 | { 64, L"White has a decisive queenside control advantage" }, |
|
- | 548 | { 65, L"Black has a decisive queenside control advantage" }, |
|
- | 549 | { 66, L"White has a vulnerable first rank" }, |
|
- | 550 | { 67, L"Black has a vulnerable first rank" }, |
|
- | 551 | { 68, L"White has a well protected first rank" }, |
|
- | 552 | { 69, L"Black has a well protected first rank" }, |
|
- | 553 | { 70, L"White has a poorly protected king" }, |
|
- | 554 | { 71, L"Black has a poorly protected king" }, |
|
- | 555 | { 72, L"White has a well protected king" }, |
|
- | 556 | { 73, L"Black has a well protected king" }, |
|
- | 557 | { 74, L"White has a poorly placed king" }, |
|
- | 558 | { 75, L"Black has a poorly placed king" }, |
|
- | 559 | { 76, L"White has a well placed king" }, |
|
- | 560 | { 77, L"Black has a well placed king" }, |
|
- | 561 | { 78, L"White has a very weak pawn structure" }, |
|
- | 562 | { 79, L"Black has a very weak pawn structure" }, |
|
- | 563 | { 80, L"White has a moderately weak pawn structure" }, |
|
- | 564 | { 81, L"Black has a moderately weak pawn structure" }, |
|
- | 565 | { 82, L"White has a moderately strong pawn structure" }, |
|
- | 566 | { 83, L"Black has a moderately strong pawn structure" }, |
|
- | 567 | { 84, L"White has a very strong pawn structure" }, |
|
- | 568 | { 85, L"Black has a very strong pawn structure" }, |
|
- | 569 | { 86, L"White has poor knight placement" }, |
|
- | 570 | { 87, L"Black has poor knight placement" }, |
|
- | 571 | { 88, L"White has good knight placement" }, |
|
- | 572 | { 89, L"Black has good knight placement" }, |
|
- | 573 | { 90, L"White has poor bishop placement" }, |
|
- | 574 | { 91, L"Black has poor bishop placement" }, |
|
- | 575 | { 92, L"White has good bishop placement" }, |
|
- | 576 | { 93, L"Black has good bishop placement" }, |
|
- | 577 | { 94, L"White has poor rook placement" }, |
|
- | 578 | { 95, L"Black has poor rook placement" }, |
|
- | 579 | { 96, L"White has good rook placement" }, |
|
- | 580 | { 97, L"Black has good rook placement" }, |
|
- | 581 | { 98, L"White has poor queen placement" }, |
|
- | 582 | { 99, L"Black has poor queen placement" }, |
|
- | 583 | { 100, L"White has good queen placement" }, |
|
- | 584 | { 101, L"Black has good queen placement" }, |
|
- | 585 | { 102, L"White has poor piece coordination" }, |
|
- | 586 | { 103, L"Black has poor piece coordination" }, |
|
- | 587 | { 104, L"White has good piece coordination" }, |
|
- | 588 | { 105, L"Black has good piece coordination" }, |
|
- | 589 | { 106, L"White has played the opening very poorly" }, |
|
- | 590 | { 107, L"Black has played the opening very poorly" }, |
|
- | 591 | { 108, L"White has played the opening poorly" }, |
|
- | 592 | { 109, L"Black has played the opening poorly" }, |
|
- | 593 | { 110, L"White has played the opening well" }, |
|
- | 594 | { 111, L"Black has played the opening well" }, |
|
- | 595 | { 112, L"White has played the opening very well" }, |
|
- | 596 | { 113, L"Black has played the opening very well" }, |
|
- | 597 | { 114, L"White has played the middlegame very poorly" }, |
|
- | 598 | { 115, L"Black has played the middlegame very poorly" }, |
|
- | 599 | { 116, L"White has played the middlegame poorly" }, |
|
- | 600 | { 117, L"Black has played the middlegame poorly" }, |
|
- | 601 | { 118, L"White has played the middlegame well" }, |
|
- | 602 | { 119, L"Black has played the middlegame well" }, |
|
- | 603 | { 120, L"White has played the middlegame very well" }, |
|
- | 604 | { 121, L"Black has played the middlegame very well" }, |
|
- | 605 | { 122, L"White has played the ending very poorly" }, |
|
- | 606 | { 123, L"Black has played the ending very poorly" }, |
|
- | 607 | { 124, L"White has played the ending poorly" }, |
|
- | 608 | { 125, L"Black has played the ending poorly" }, |
|
- | 609 | { 126, L"White has played the ending well" }, |
|
- | 610 | { 127, L"Black has played the ending well" }, |
|
- | 611 | { 128, L"White has played the ending very well" }, |
|
- | 612 | { 129, L"Black has played the ending very well" }, |
|
- | 613 | { 130, L"White has slight counterplay" }, |
|
- | 614 | { 131, L"Black has slight counterplay" }, |
|
- | 615 | { 132, L"White has moderate counterplay" }, |
|
- | 616 | { 133, L"Black has moderate counterplay" }, |
|
- | 617 | { 134, L"White has decisive counterplay" }, |
|
- | 618 | { 135, L"Black has decisive counterplay" }, |
|
- | 619 | { 136, L"White has moderate time control pressure" }, |
|
- | 620 | { 137, L"Black has moderate time control pressure" }, |
|
- | 621 | { 138, L"White has severe time control pressure" }, |
|
- | 622 | { 139, L"Black has severe time control pressure" } |
|
- | 623 | }; |
|
- | 624 | int nag_index; |
|
- | 625 | ||
- | 626 | // cycle through all known NAGs and return the text that corresponds to the requested code |
|
- | 627 | for (nag_index = 0; nag_index < sizeof (nag_codes) / sizeof (nag_t); nag_index++) |
|
- | 628 | if (nag_codes[nag_index].code == nag_code) |
|
- | 629 | return (nag_codes[nag_index].text); // return the text as soon as we find it |
|
- | 630 | ||
- | 631 | return (L"undocumented code"); // not found, return a placeholder string |
|
460 | } |
632 | } |
461 | 633 | ||
462 | 634 | ||
463 | static char *sgets (char *destination_line, int max_length, char *source_buffer) |
635 | static char *sgets (char *destination_line, int max_length, char *source_buffer) |
464 | { |
636 | { |