| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2002-2003 Andi Peredri * |
| 3 | * [email protected] * |
| 4 | * Copyright (C) 2004-2007 Artur Wiebe * |
| 5 | * [email protected] * |
| 6 | * * |
| 7 | * This program is free software; you can redistribute it and/or modify * |
| 8 | * it under the terms of the GNU General Public License as published by * |
| 9 | * the Free Software Foundation; either version 2 of the License, or * |
| 10 | * (at your option) any later version. * |
| 11 | * * |
| 12 | * This program is distributed in the hope that it will be useful, * |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 | * GNU General Public License for more details. * |
| 16 | * * |
| 17 | * You should have received a copy of the GNU General Public License * |
| 18 | * along with this program; if not, write to the * |
| 19 | * Free Software Foundation, Inc., * |
| 20 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 21 | ***************************************************************************/ |
| 22 | #ifndef PDN_H |
| 23 | #define PDN_H |
| 24 | |
| 25 | |
| 26 | #include <QList> |
| 27 | #include <QWidget> |
| 28 | |
| 29 | |
| 30 | #define ENOTATION "1 2 3 4 5 6 7 8 9 1011121314151617181920212223242526272829303132" |
| 31 | //#define ENOTATION "32313029282726252423222120191817161514131211109 8 7 6 5 4 3 2 1 " |
| 32 | #define RNOTATION "B8D8F8H8A7C7E7G7B6D6F6H6A5C5E5G5B4D4F4H4A3C3E3G3B2D2F2H2A1C1E1G1" |
| 33 | |
| 34 | #define ENGLISH 21 |
| 35 | #define RUSSIAN 25 |
| 36 | |
| 37 | |
| 38 | class PdnMove; |
| 39 | class PdnGame; |
| 40 | |
| 41 | |
| 42 | // Portable Draughts Notation Format File parser |
| 43 | class Pdn |
| 44 | { |
| 45 | public: |
| 46 | Pdn(); |
| 47 | virtual ~Pdn(); |
| 48 | |
| 49 | int count() const { return m_database.count(); } |
| 50 | PdnGame* game(int i) { return m_database.at(i); } |
| 51 | PdnGame* newGame(); |
| 52 | |
| 53 | void clear() { m_database.clear(); } |
| 54 | // parent is needed to display a progress dialog. |
| 55 | bool open(const QString& filename, QWidget* parent, |
| 56 | const QString& label, QString& text_to_log); |
| 57 | bool save(const QString& filename); |
| 58 | |
| 59 | private: |
| 60 | QList<PdnGame*> m_database; |
| 61 | }; |
| 62 | |
| 63 | |
| 64 | /* |
| 65 | * m_first, m_second are mandatary. |
| 66 | * comments are optional. |
| 67 | */ |
| 68 | class PdnMove |
| 69 | { |
| 70 | public: |
| 71 | PdnMove(QString whole_line_of_move); |
| 72 | |
| 73 | QString m_first, m_comfirst; |
| 74 | QString m_second, m_comsecond; |
| 75 | }; |
| 76 | |
| 77 | |
| 78 | /* |
| 79 | * represents each game in a pdn-file. |
| 80 | */ |
| 81 | class PdnGame |
| 82 | { |
| 83 | public: |
| 84 | PdnGame(const QString& game_string, QString& text_to_log); |
| 85 | ~PdnGame(); |
| 86 | |
| 87 | enum Tag { Date, Site, Type, Event, Round, White, Black,Result }; |
| 88 | |
| 89 | int item(int i) const { return board[i]; } |
| 90 | void setItem(int i, int set) { board[i]=set; } |
| 91 | |
| 92 | bool isWhite() const { return white; } |
| 93 | void setWhite(bool set) { white=set; } |
| 94 | |
| 95 | void set(Tag tag, const QString& string); |
| 96 | QString get(Tag tag) const; |
| 97 | |
| 98 | int movesCount() const { return m_moves.count(); } |
| 99 | PdnMove* getMove(int i); |
| 100 | PdnMove* addMove(); |
| 101 | void clearMoves() { m_moves.clear(); } |
| 102 | |
| 103 | QString toString(); |
| 104 | |
| 105 | private: |
| 106 | bool parse(const QString& game_string, QString& log_txt); |
| 107 | bool parse(const QString& string, bool side); |
| 108 | bool parse_moves(const QString& moves_line); |
| 109 | |
| 110 | private: |
| 111 | bool white; |
| 112 | int board[32]; |
| 113 | QString pdnDate; |
| 114 | QString pdnSite; |
| 115 | QString pdnType; |
| 116 | QString pdnEvent; |
| 117 | QString pdnRound; |
| 118 | QString pdnWhite; |
| 119 | QString pdnBlack; |
| 120 | QString pdnResult; |
| 121 | QList<PdnMove*> m_moves; |
| 122 | }; |
| 123 | |
| 124 | |
| 125 | #endif |