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 | #ifndef _pgn_h_ |
||
| 22 | #define _pgn_h_ |
||
| 23 | |||
| 24 | #include <stdio.h> |
||
| 25 | |||
| 26 | typedef struct |
||
| 27 | { |
||
| 28 | long *index; |
||
| 29 | long indexSize; |
||
| 30 | long numGames; |
||
| 31 | FILE *file; |
||
| 32 | } |
||
| 33 | PGNFile; |
||
| 34 | |||
| 35 | #define PGN_ROASTERLINE_SIZE 256 |
||
| 36 | |||
| 37 | typedef struct |
||
| 38 | { |
||
| 39 | Square from, to; |
||
| 40 | Piece newPiece; |
||
| 41 | Position position; |
||
| 42 | void *previousMove; |
||
| 43 | void *nextMove; |
||
| 44 | void *alternativeMove; |
||
| 45 | |||
| 46 | char *comment, *glyphs; |
||
| 47 | } |
||
| 48 | Gamemove; |
||
| 49 | |||
| 50 | typedef struct |
||
| 51 | { |
||
| 52 | char event[PGN_ROASTERLINE_SIZE]; |
||
| 53 | char site[PGN_ROASTERLINE_SIZE]; |
||
| 54 | char date[PGN_ROASTERLINE_SIZE]; |
||
| 55 | char round[PGN_ROASTERLINE_SIZE]; |
||
| 56 | char white[PGN_ROASTERLINE_SIZE]; |
||
| 57 | char black[PGN_ROASTERLINE_SIZE]; |
||
| 58 | char result[PGN_ROASTERLINE_SIZE]; |
||
| 59 | char setup[PGN_ROASTERLINE_SIZE]; |
||
| 60 | char fen[PGN_ROASTERLINE_SIZE]; |
||
| 61 | char whiteTitle[PGN_ROASTERLINE_SIZE]; |
||
| 62 | char blackTitle[PGN_ROASTERLINE_SIZE]; |
||
| 63 | char whiteElo[PGN_ROASTERLINE_SIZE]; |
||
| 64 | char blackElo[PGN_ROASTERLINE_SIZE]; |
||
| 65 | char eco[PGN_ROASTERLINE_SIZE]; |
||
| 66 | char nic[PGN_ROASTERLINE_SIZE]; |
||
| 67 | char timeControl[PGN_ROASTERLINE_SIZE]; |
||
| 68 | char termination[PGN_ROASTERLINE_SIZE]; |
||
| 69 | |||
| 70 | char *moveText; |
||
| 71 | Gamemove *firstMove, *lastMove; |
||
| 72 | Gamemove moveHeap[1024]; |
||
| 73 | int nextMoveFromHeap; |
||
| 74 | } |
||
| 75 | PGNGame; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Open the PGN file specified by 'filename'. |
||
| 79 | * |
||
| 80 | * @return 0 if the file could be opened without any error |
||
| 81 | */ |
||
| 82 | int openPGNFile(PGNFile * pgnfile, const char *filename); |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Close the PGN file specified by 'pgnfile'. |
||
| 86 | */ |
||
| 87 | void closePGNFile(PGNFile * pgnfile); |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Get the PGNGame specified by 'number'. |
||
| 91 | * |
||
| 92 | * @param number the number of the game to be loaded [1...pgnfile.numGames] |
||
| 93 | * @param pgngame the struct supposed to contain the game data. It is |
||
| 94 | * important to free the memory allocated for the game moves as |
||
| 95 | * soon as the pgngame is no longer needed. |
||
| 96 | * |
||
| 97 | * @return 0 if no errors occured |
||
| 98 | */ |
||
| 99 | PGNGame *getGame(PGNFile * pgnfile, int number); |
||
| 100 | |||
| 101 | /** |
||
| 102 | * Initialize the specified PGNGame. |
||
| 103 | */ |
||
| 104 | void initializePGNGame(PGNGame * game); |
||
| 105 | |||
| 106 | /** |
||
| 107 | * Free all memory allocated for the specified pgn game. |
||
| 108 | */ |
||
| 109 | void resetPGNGame(PGNGame * game); |
||
| 110 | |||
| 111 | /** |
||
| 112 | * Free all memory allocated for the specified pgn game |
||
| 113 | * (including the game itself). |
||
| 114 | */ |
||
| 115 | void freePgnGame(PGNGame * game); |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Generate the SAN notation of the specified move. |
||
| 119 | */ |
||
| 120 | void generateMoveText(Variation * variation, const Move move, char *pgnMove); |
||
| 121 | |||
| 122 | /** |
||
| 123 | * Get the current principal variation of the specified variation. |
||
| 124 | * |
||
| 125 | * @return a newly allocated string |
||
| 126 | */ |
||
| 127 | char *getPrincipalVariation(const Variation * variation); |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Generate the pgn text of the specified game. |
||
| 131 | */ |
||
| 132 | char *generatePgn(PGNGame * game); |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Initialize a variation with the specified game. |
||
| 136 | */ |
||
| 137 | void initializeVariationFromGame(Variation * variation, PGNGame * game); |
||
| 138 | |||
| 139 | /** |
||
| 140 | * Initialize a game with the specified variation. |
||
| 141 | */ |
||
| 142 | void initializeGameFromVariation(const Variation * variation, PGNGame * game, |
||
| 143 | bool copyPv); |
||
| 144 | /** |
||
| 145 | * Convert a gamemove to a move. |
||
| 146 | */ |
||
| 147 | Move gameMove2Move(const Gamemove * gamemove); |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Interpret the given pgn move and return an appropriate Move. |
||
| 151 | */ |
||
| 152 | Move interpretPGNMove(const char *moveText, PGNGame * game); |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Append the specified move to the specified game. If the move |
||
| 156 | * is found to be illegal this call has no effect on the game and |
||
| 157 | * a nonzero value will be returned. |
||
| 158 | * |
||
| 159 | * @return 0 if and only if the specified move was legal |
||
| 160 | */ |
||
| 161 | int appendMove(PGNGame * game, const Move move); |
||
| 162 | |||
| 163 | /** |
||
| 164 | * Take back the last move of the specified game. |
||
| 165 | */ |
||
| 166 | void takebackLastMove(PGNGame * game); |
||
| 167 | |||
| 168 | /** |
||
| 169 | * Initialize this module. |
||
| 170 | * |
||
| 171 | * @return 0 if no errors occurred. |
||
| 172 | */ |
||
| 173 | int initializeModulePgn(void); |
||
| 174 | |||
| 175 | /** |
||
| 176 | * Test this module. |
||
| 177 | * |
||
| 178 | * @return 0 if all tests succeed. |
||
| 179 | */ |
||
| 180 | int testModulePgn(void); |
||
| 181 | |||
| 182 | #endif |