[go: up one dir, main page]

Menu

[r1123]: / src / pgn.h  Maximize  Restore  History

Download this file

183 lines (152 with data), 4.6 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
/*
Protector -- a UCI chess engine
Copyright (C) 2009-2010 Raimund Heid (Raimund_Heid@yahoo.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _pgn_h_
#define _pgn_h_
#include <stdio.h>
typedef struct
{
long *index;
long indexSize;
long numGames;
FILE *file;
}
PGNFile;
#define PGN_ROASTERLINE_SIZE 256
typedef struct
{
Square from, to;
Piece newPiece;
Position position;
void *previousMove;
void *nextMove;
void *alternativeMove;
char *comment, *glyphs;
}
Gamemove;
typedef struct
{
char event[PGN_ROASTERLINE_SIZE];
char site[PGN_ROASTERLINE_SIZE];
char date[PGN_ROASTERLINE_SIZE];
char round[PGN_ROASTERLINE_SIZE];
char white[PGN_ROASTERLINE_SIZE];
char black[PGN_ROASTERLINE_SIZE];
char result[PGN_ROASTERLINE_SIZE];
char setup[PGN_ROASTERLINE_SIZE];
char fen[PGN_ROASTERLINE_SIZE];
char whiteTitle[PGN_ROASTERLINE_SIZE];
char blackTitle[PGN_ROASTERLINE_SIZE];
char whiteElo[PGN_ROASTERLINE_SIZE];
char blackElo[PGN_ROASTERLINE_SIZE];
char eco[PGN_ROASTERLINE_SIZE];
char nic[PGN_ROASTERLINE_SIZE];
char timeControl[PGN_ROASTERLINE_SIZE];
char termination[PGN_ROASTERLINE_SIZE];
char *moveText;
Gamemove *firstMove, *lastMove;
Gamemove moveHeap[1024];
int nextMoveFromHeap;
}
PGNGame;
/**
* Open the PGN file specified by 'filename'.
*
* @return 0 if the file could be opened without any error
*/
int openPGNFile(PGNFile * pgnfile, const char *filename);
/**
* Close the PGN file specified by 'pgnfile'.
*/
void closePGNFile(PGNFile * pgnfile);
/**
* Get the PGNGame specified by 'number'.
*
* @param number the number of the game to be loaded [1...pgnfile.numGames]
* @param pgngame the struct supposed to contain the game data. It is
* important to free the memory allocated for the game moves as
* soon as the pgngame is no longer needed.
*
* @return 0 if no errors occured
*/
PGNGame *getGame(PGNFile * pgnfile, int number);
/**
* Initialize the specified PGNGame.
*/
void initializePGNGame(PGNGame * game);
/**
* Free all memory allocated for the specified pgn game.
*/
void resetPGNGame(PGNGame * game);
/**
* Free all memory allocated for the specified pgn game
* (including the game itself).
*/
void freePgnGame(PGNGame * game);
/**
* Generate the SAN notation of the specified move.
*/
void generateMoveText(Variation * variation, const Move move, char *pgnMove);
/**
* Get the current principal variation of the specified variation.
*
* @return a newly allocated string
*/
char *getPrincipalVariation(const Variation * variation);
/**
* Generate the pgn text of the specified game.
*/
char *generatePgn(PGNGame * game);
/**
* Initialize a variation with the specified game.
*/
void initializeVariationFromGame(Variation * variation, PGNGame * game);
/**
* Initialize a game with the specified variation.
*/
void initializeGameFromVariation(const Variation * variation, PGNGame * game,
bool copyPv);
/**
* Convert a gamemove to a move.
*/
Move gameMove2Move(const Gamemove * gamemove);
/**
* Interpret the given pgn move and return an appropriate Move.
*/
Move interpretPGNMove(const char *moveText, PGNGame * game);
/**
* Append the specified move to the specified game. If the move
* is found to be illegal this call has no effect on the game and
* a nonzero value will be returned.
*
* @return 0 if and only if the specified move was legal
*/
int appendMove(PGNGame * game, const Move move);
/**
* Take back the last move of the specified game.
*/
void takebackLastMove(PGNGame * game);
/**
* Initialize this module.
*
* @return 0 if no errors occurred.
*/
int initializeModulePgn(void);
/**
* Test this module.
*
* @return 0 if all tests succeed.
*/
int testModulePgn(void);
#endif