1 /* 2 3 eboard - chess client 4 http://www.bergo.eng.br/eboard 5 https://github.com/fbergo/eboard 6 Copyright (C) 2000-2016 Felipe Bergo 7 fbergo/at/gmail/dot/com 8 9 This program is free software; you can redistribute it and/or modify 10 it under the terms of the GNU General Public License as published by 11 the Free Software Foundation; either version 2 of the License, or 12 (at your option) any later version. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software 21 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 22 23 */ 24 25 26 27 #ifndef EBOARD_CHESS_H 28 #define EBOARD_CHESS_H 1 29 30 #include "eboard.h" 31 #include "widgetproxy.h" 32 #include "position.h" 33 #include "board.h" 34 #include "movelist.h" 35 #include "clock.h" 36 #include <stdio.h> 37 #include "stl.h" 38 39 // foreign classes 40 class Board; 41 42 class PGNpair { 43 public: 44 PGNpair(); 45 PGNpair(const char *n, const char *v); 46 PGNpair(const char *n, string &v); 47 48 string name; 49 string value; 50 }; 51 52 class PGNheader { 53 public: 54 ~PGNheader(); 55 void set(const char *n,const char *v); 56 void set(const char *n,string &v); 57 void setIfAbsent(const char *n,const char *v); 58 void remove(const char *n); 59 int empty(); 60 int size(); 61 PGNpair *get(int index); 62 const char *get(const char *n); 63 64 private: 65 vector<PGNpair *> header; 66 67 friend ostream &operator<<(ostream &s, PGNheader h); 68 }; 69 70 ostream &operator<<(ostream &s, PGNheader h); 71 72 class ChessGame : public MoveListListener { 73 public: 74 ChessGame(); 75 ChessGame(int _number,int _tyme,int _inc, int _rated,variant _variant, 76 const char *p1,const char *p2); 77 ChessGame(ChessGame *src); 78 virtual ~ChessGame(); 79 80 int operator==(int gnum); 81 82 void updatePosition2(Position &p,int movenum,int blacktomove, 83 int wclockms,int bclockms,const char *infoline, 84 bool sndflag=false); 85 void updateStock(); 86 void updateGame(list<Position> &gamedata); 87 void flipHint(int flip); 88 void setBoard(Board *b); 89 Board * getBoard(); 90 void sendMove(int x1,int y1,int x2,int y2); 91 void sendDrop(piece p, int x, int y); 92 void acknowledgeInfo(); 93 void endGame(const char *reason,GameResult _result); 94 void fireWhiteClock(int wval,int bval); 95 void enableMoving(bool flag); 96 int isOver(); 97 98 void incrementActiveClock(int secs); 99 100 char *getPlayerString(int index); 101 char *getEndReason(); 102 GameResult getResult(); 103 104 void dump(); 105 106 Position & getLastPosition(); 107 Position & getCurrentPosition(); 108 Position & getPreviousPosition(); 109 110 void goBack1(); 111 void goBackAll(); 112 void goForward1(); 113 void goForwardAll(); 114 void openMoveList(); 115 void closeMoveList(); 116 117 void setFree(); 118 119 virtual void moveListClosed(); 120 121 void retreat(int nmoves); 122 static void LoadPGN(char *filename); 123 static bool ParsePgnGame(zifstream &f, 124 char * filename, 125 bool indexonly, 126 int gameid, 127 variant v = REGULAR, 128 ChessGame *updatee = NULL); 129 bool savePGN(char *filename, bool append=false); 130 131 bool loadMoves(); 132 133 bool isFresh(); 134 135 void guessInfoFromPGN(); 136 void guessPGNFromInfo(); 137 138 void editEmpty(); 139 void editStartPos(); 140 141 bool getSideHint(); // true=white to move, used in scratch boards 142 void setSideHint(bool white); 143 144 static const char *variantName(variant v); 145 static variant variantFromName(const char *p); 146 147 int GameNumber; 148 int Rated; 149 variant Variant; 150 char PlayerName[2][64]; 151 char Rating[2][32]; 152 piece MyColor; 153 int StopClock; // for examined games 154 TimeControl timecontrol; 155 156 bool LocalEdit; 157 158 bool Loaded; 159 char PGNSource[256]; 160 long SourceOffset; 161 162 PGNheader pgn; 163 164 GameSource source; 165 string source_data; 166 bool AmPlaying; 167 168 char info0[64]; 169 int clock_regressive; 170 171 int protodata[8]; 172 173 private: 174 void showResult(); 175 void fixExamineZigZag(Position &suspect); 176 void updateClockAndInfo2(int wclockms, int bclockms,int blacktomove, 177 const char *infoline, 178 bool sndflag); 179 180 list<Position> moves; 181 list<Position>::iterator cursor; 182 183 char PrivateString[96]; 184 185 Board *myboard; 186 MoveListWindow *mymovelist; 187 188 Position startpos; 189 190 int last_half_move; 191 int over; 192 GameResult result; 193 char ereason[128]; 194 195 static bool GlyphsInited; 196 static vector<string *> Glyphs; 197 static void initGlyphs(); 198 static void failGlyphs(); 199 200 }; 201 202 class PGNEditInfoDialog : public ModalDialog { 203 public: 204 PGNEditInfoDialog(ChessGame *src); 205 private: 206 ChessGame *obj; 207 GtkWidget *clist,*del; 208 GtkWidget *en[2]; 209 int Selection; 210 211 void populate(); 212 213 friend void pgnedit_set(GtkWidget *w, gpointer data); 214 friend void pgnedit_del(GtkWidget *w, gpointer data); 215 friend void pgnedit_rowsel(GtkCList *w, gint row, gint col, 216 GdkEventButton *eb,gpointer data); 217 friend void pgnedit_rowunsel(GtkCList *w, gint row, gint col, 218 GdkEventButton *eb,gpointer data); 219 }; 220 221 void pgnedit_set(GtkWidget *w, gpointer data); 222 void pgnedit_del(GtkWidget *w, gpointer data); 223 void pgnedit_rowsel(GtkCList *w, gint row, gint col, 224 GdkEventButton *eb,gpointer data); 225 void pgnedit_rowunsel(GtkCList *w, gint row, gint col, 226 GdkEventButton *eb,gpointer data); 227 228 229 #endif 230