Debian Codegraph @

src/pdn.cc

raw symbols SCIP
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 #include <QFile>
23 #include <QTextStream>
24 #include <QProgressDialog>
25 #include <QDebug>
26
27 #include "checkers.h"cxx . . $ `<file>/src/checkers.h`/
28 #include "pdn.h"cxx . . $ `<file>/src/pdn.h`/
29
30
31 #define PLAYERcxx . . $ `src/pdn.cc:31:9`! true
32 #define COMPUTERcxx . . $ `src/pdn.cc:32:9`! false
33
34 #define END_OF_MOVELINEcxx . . $ `src/pdn.cc:34:9`! "@."
35
36
37 Pdncxx . . $ Pdn#::Pdncxx . . $ Pdn#Pdn(49f6e7a06ebc5aa8).()
38 {
39 }
40
41
42 Pdncxx . . $ Pdn#::~cxx . . $ Pdn#`~Pdn`(ced63f7c635d850d).Pdncxx . . $ Pdn#()
43 {
44 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(m_databasecxx . . $ Pdn#m_database.);
45 m_databasecxx . . $ Pdn#m_database..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
46 }
47
48
49 bool Pdncxx . . $ Pdn#::opencxx . . $ Pdn#open(c44dbb032bc1e7d3).(const QStringcxx . . $ QString#& filename, QWidgetcxx . . $ QWidget#* parent,
50 const QStringcxx . . $ QString#& label, QStringcxx . . $ QString#& text_to_log)
51 {
52 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(m_databasecxx . . $ Pdn#m_database.);
53 m_databasecxx . . $ Pdn#m_database..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
54
55 QFilecxx . . $ QFile# filecxx . . $ QFile#QFile(3520e46b33348bf6).(filename);
56 if(!file.opencxx . . $ QFile#open(dca164408be960c8).(QFilecxx . . $ QFlags#QFlags(93d577a3e9528307).::ReadOnlycxx . . $ QIODevice#ReadOnly.)) {
57 return false;
58 }
59
60 QTextStreamcxx . . $ QTextStream# tscxx . . $ QTextStream#QTextStream(bebe8f2dee7f9e86).(&file);
61
62 QStringcxx . . $ QString# str1cxx . . $ QString#QString(ced63f7c635d850d)., str2cxx . . $ QString#QString(ced63f7c635d850d).;
63
64 QProgressDialogcxx . . $ QProgressDialog# progresscxx . . $ QProgressDialog#QProgressDialog(872e7b0c281abd8d).(parent);
65 progress.setModalcxx . . $ QDialog#setModal(b45ddcbc8423892c).(true);
66 progress.setLabelTextcxx . . $ QProgressDialog#setLabelText(3520e46b33348bf6).(label);
67 progress.setRangecxx . . $ QProgressDialog#setRange(3e454b8ccf442868).(0, file.sizecxx . . $ QFile#size(98833e9ab7de59a4).());
68 progress.setMinimumDurationcxx . . $ QProgressDialog#setMinimumDuration(d4f767463ce0a6b3).(0);
69
70 unsigned int line_nr = 1;
71 unsigned int game_started = 1;
72 bool in_tags = false;
73 while(!ts.atEndcxx . . $ QTextStream#atEnd(50ce9a9e25b4a850).()) {
74 str1 =cxx . . $ QString#`operator=`(4f35bf974e7f8568). ts.readLinecxx . . $ QTextStream#readLine(20e0a2766677f583).().trimmedcxx . . $ QString#trimmed(30b3b70527b1c61a).();
75 if(ts.atEndcxx . . $ QTextStream#atEnd(50ce9a9e25b4a850).()) {
76 str2 +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). str1;
77 }
78
79 if((str1.lengthcxx . . $ QString#length(455f465bc33b4cdf).() && str1[cxx . . $ QString#`operator[]`(57436120916eb52c).0]==cxx . . $ `operator==`(a468b2f18a3afe8).'['cxx . . $ QChar#QChar(f349c77f591a7878).) || ts.atEndcxx . . $ QTextStream#atEnd(50ce9a9e25b4a850).()) {
80 if(!in_tags) {
81 // tags begin again, so a game is ended.
82 if(str2.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
83 if((m_databasecxx . . $ Pdn#m_database..countcxx . . $ QList#count(455f465bc33b4cdf).()%10)==0) {
84 progress.setValuecxx . . $ QProgressDialog#setValue(d4f767463ce0a6b3).(file.poscxx . . $ QFileDevice#pos(98833e9ab7de59a4).());
85 }
86
87 QStringcxx . . $ QString# log_txtcxx . . $ QString#QString(ced63f7c635d850d).;
88 PdnGamecxx . . $ PdnGame#* game = new PdnGamecxx . . $ PdnGame#PdnGame(7ae9d009a77e8cb0).(str2, log_txt);
89 m_databasecxx . . $ Pdn#m_database..appendcxx . . $ QList#append(77d9f17553126ecb).(game);
90
91 if(log_txt.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
92 text_to_log
93 +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). QStringcxx . . $ QString#QString(85c52e162fed56f9).("%1. game begins at line %2:\n")
94 .argcxx . . $ QString#arg(64ab2ed17cc11715).(m_databasecxx . . $ Pdn#m_database..countcxx . . $ QList#count(455f465bc33b4cdf).())
95 .argcxx . . $ QString#arg(173a29139b43af1f).(game_started);
96 text_to_log +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). log_txt;
97 }
98
99 game_started = line_nr;
100 str2=cxx . . $ QString#`operator=`(d02845eef0c33901)."";
101 }
102
103 in_tags = true;
104 }
105 } else {
106 if(in_tags) {
107 in_tags = false;
108 }
109 }
110
111 str2.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(str1+cxx . . $ operator+(3d22f08efddf8107)."\n");
112
113 if(progress.wasCanceledcxx . . $ QProgressDialog#wasCanceled(50ce9a9e25b4a850).()) {
114 break;
115 }
116
117 line_nr++;
118 }
119
120 file.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).();
121
122 return true;
123 }
124
125
126 bool Pdncxx . . $ Pdn#::savecxx . . $ Pdn#save(e1defb592416720d).(const QStringcxx . . $ QString#& filename)
127 {
128 QFilecxx . . $ QFile# filecxx . . $ QFile#QFile(3520e46b33348bf6).(filename);
129 if(!file.opencxx . . $ QFile#open(dca164408be960c8).(QFilecxx . . $ QFlags#QFlags(93d577a3e9528307).::WriteOnlycxx . . $ QIODevice#WriteOnly.)) {
130 return false;
131 }
132
133 QTextStreamcxx . . $ QTextStream# tscxx . . $ QTextStream#QTextStream(bebe8f2dee7f9e86).(&file);
134
135 foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(PdnGame* game, m_database) {
136 ts <<cxx . . $ QTextStream#`operator<<`(f61e69e0d177108f). game->toStringcxx . . $ PdnGame#toString(4365c3963150523e).() <<cxx . . $ `operator<<`(f27eeb5c966d2dd0). endlcxx . . $ QTextStreamFunctions/endl(e06208c9acdf85a). <<cxx . . $ `operator<<`(f27eeb5c966d2dd0). endlcxx . . $ QTextStreamFunctions/endl(e06208c9acdf85a).;
137 }
138
139 file.closecxx . . $ QFileDevice#close(49f6e7a06ebc5aa8).();
140 return true;
141 }
142
143
144
145 PdnGamecxx . . $ PdnGame#* Pdncxx . . $ Pdn#::newGamecxx . . $ Pdn#newGame(7f8740dfe427848).()
146 {
147 QStringcxx . . $ QString# log_txtcxx . . $ QString#QString(ced63f7c635d850d).; // here: ignore TODO
148 PdnGamecxx . . $ PdnGame#* game = new PdnGamecxx . . $ PdnGame#PdnGame(7ae9d009a77e8cb0).(""cxx . . $ QString#QString(85c52e162fed56f9)., log_txt);
149 m_databasecxx . . $ Pdn#m_database..appendcxx . . $ QList#append(77d9f17553126ecb).(game);
150 return game;
151 }
152
153
154 /***************************************************************************
155 * *
156 * *
157 ***************************************************************************/
158 PdnMovecxx . . $ PdnMove#::PdnMovecxx . . $ PdnMove#PdnMove(7df51288a9ebd664).(QStringcxx . . $ QString# line)
159 {
160 if(line[cxx . . $ QString#`operator[]`(57436120916eb52c).0]==cxx . . $ `operator==`(a468b2f18a3afe8).'{'cxx . . $ QChar#QChar(f349c77f591a7878).) {
161 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("a move must not begin with a comment.");
162 return;
163 }
164
165 // first move.
166 m_firstcxx . . $ PdnMove#m_first. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.sectioncxx . . $ QString#section(6e922cf609fb9683).(' 'cxx . . $ QChar#QChar(f349c77f591a7878)., 0, 0);
167 line =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.midcxx . . $ QString#mid(44b7563da18aea72).(m_firstcxx . . $ PdnMove#m_first..lengthcxx . . $ QString#length(455f465bc33b4cdf).()).trimmedcxx . . $ QString#trimmed(30b3b70527b1c61a).();
168
169 // check for a first comment.
170 if(line[cxx . . $ QString#`operator[]`(57436120916eb52c).0]==cxx . . $ `operator==`(a468b2f18a3afe8).'{'cxx . . $ QChar#QChar(f349c77f591a7878).) {
171 int end = line.indexOfcxx . . $ QString#indexOf(75b556ba78e4903c).('}'cxx . . $ QChar#QChar(f349c77f591a7878)., 1);
172 if(end>=0) {
173 m_comfirstcxx . . $ PdnMove#m_comfirst. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.midcxx . . $ QString#mid(44b7563da18aea72).(1, end-1);
174 line.removecxx . . $ QString#remove(6483560ce2afa901).(0, end+1);
175 line =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).();
176 } else {
177 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("no comment ending of the first comment.");
178 }
179 }
180
181 // second move.
182 m_secondcxx . . $ PdnMove#m_second. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.sectioncxx . . $ QString#section(6e922cf609fb9683).(' 'cxx . . $ QChar#QChar(f349c77f591a7878)., 0, 0);
183 line =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.midcxx . . $ QString#mid(44b7563da18aea72).(m_secondcxx . . $ PdnMove#m_second..lengthcxx . . $ QString#length(455f465bc33b4cdf).()).trimmedcxx . . $ QString#trimmed(30b3b70527b1c61a).();
184
185 // check for a second comment.
186 if(line[cxx . . $ QString#`operator[]`(57436120916eb52c).0]==cxx . . $ `operator==`(a468b2f18a3afe8).'{'cxx . . $ QChar#QChar(f349c77f591a7878).) {
187 int end = line.indexOfcxx . . $ QString#indexOf(75b556ba78e4903c).('}'cxx . . $ QChar#QChar(f349c77f591a7878)., 1);
188 if(end>=0) {
189 m_comsecondcxx . . $ PdnMove#m_comsecond. =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.midcxx . . $ QString#mid(44b7563da18aea72).(1, end-1);
190 } else {
191 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("no comment ending of the second comment.");
192 }
193 }
194 }
195
196
197 /***************************************************************************
198 * *
199 * *
200 ***************************************************************************/
201 PdnGamecxx . . $ PdnGame#::PdnGamecxx . . $ PdnGame#PdnGame(7ae9d009a77e8cb0).(const QStringcxx . . $ QString#& game_string, QStringcxx . . $ QString#& log_txt)
202 {
203 whitecxx . . $ PdnGame#white. = PLAYERcxx . . $ `src/pdn.cc:31:9`!;
204 for(int i=0; i<12; i++) {
205 boardcxx . . $ PdnGame#board.[i]=MAN2cxx . . $ `src/checkers.h:37:9`!;
206 }
207 for(int i=20; i<32; i++) {
208 boardcxx . . $ PdnGame#board.[i]=MAN1cxx . . $ `src/checkers.h:33:9`!;
209 }
210
211 if(!parsecxx . . $ PdnGame#parse(853723320e657e87).(game_string, log_txt)) {
212 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!(" errors occured while processing game."); // TODO
213 }
214 }
215
216
217 PdnGamecxx . . $ PdnGame#::~cxx . . $ PdnGame#`~PdnGame`(ced63f7c635d850d).PdnGamecxx . . $ PdnGame#()
218 {
219 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(m_movescxx . . $ PdnGame#m_moves.);
220 m_movescxx . . $ PdnGame#m_moves..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
221 }
222
223
224 QStringcxx . . $ QString# PdnGamecxx . . $ PdnGame#::getcxx . . $ PdnGame#get(2bba888b79065846).(Tagcxx . . $ PdnGame#Tag# tag) const
225 {
226 switch(tag) {
227 case Datecxx . . $ PdnGame#Date.: return pdnDatecxx . . $ QString#QString(132dd6869045752b).;
228 case Sitecxx . . $ PdnGame#Site.: return pdnSitecxx . . $ QString#QString(132dd6869045752b).;
229 case Typecxx . . $ PdnGame#Type.: return pdnTypecxx . . $ QString#QString(132dd6869045752b).;
230 case Eventcxx . . $ PdnGame#Event.: return pdnEventcxx . . $ QString#QString(132dd6869045752b).;
231 case Roundcxx . . $ PdnGame#Round.: return pdnRoundcxx . . $ QString#QString(132dd6869045752b).;
232 case Whitecxx . . $ PdnGame#White.: return pdnWhitecxx . . $ QString#QString(132dd6869045752b).;
233 case Blackcxx . . $ PdnGame#Black.: return pdnBlackcxx . . $ QString#QString(132dd6869045752b).;
234 default: return pdnResultcxx . . $ QString#QString(132dd6869045752b).;
235 }
236 }
237
238
239 void PdnGamecxx . . $ PdnGame#::setcxx . . $ PdnGame#set(843cca5850ba8ec7).(Tagcxx . . $ PdnGame#Tag# tag, const QStringcxx . . $ QString#& string)
240 {
241 switch(tag) {
242 case Datecxx . . $ PdnGame#Date.: pdnDatecxx . . $ PdnGame#pdnDate.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
243 case Sitecxx . . $ PdnGame#Site.: pdnSitecxx . . $ PdnGame#pdnSite.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
244 case Typecxx . . $ PdnGame#Type.: pdnTypecxx . . $ PdnGame#pdnType.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
245 case Eventcxx . . $ PdnGame#Event.: pdnEventcxx . . $ PdnGame#pdnEvent.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
246 case Roundcxx . . $ PdnGame#Round.: pdnRoundcxx . . $ PdnGame#pdnRound.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
247 case Whitecxx . . $ PdnGame#White.: pdnWhitecxx . . $ PdnGame#pdnWhite.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
248 case Blackcxx . . $ PdnGame#Black.: pdnBlackcxx . . $ PdnGame#pdnBlack.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string; break;
249 default: pdnResultcxx . . $ PdnGame#pdnResult.=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).string;
250 }
251 }
252
253
254 bool PdnGamecxx . . $ PdnGame#::parse_movescxx . . $ PdnGame#parse_moves(e1defb592416720d).(const QStringcxx . . $ QString#& line)
255 {
256 qDeleteAllcxx . . $ qDeleteAll(77d9f17553126ecb).(m_movescxx . . $ PdnGame#m_moves.);
257 m_movescxx . . $ PdnGame#m_moves..clearcxx . . $ QList#clear(49f6e7a06ebc5aa8).();
258
259 QStringListcxx . . $ QStringList# list = line.splitcxx . . $ QString#split(92030b8bf74e4227).(' 'cxx . . $ QChar#QChar(f349c77f591a7878).);
260
261 QStringcxx . . $ QString# current_movecxx . . $ QString#QString(ced63f7c635d850d).;
262 int move_num = 0;
263 bool in_comment = false;
264 foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(QString str, list) {
265 if(str.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("{"cxx . . $ QString#QString(85c52e162fed56f9).)) {
266 in_comment = true;
267 }
268 if(str.endsWithcxx . . $ QString#endsWith(8cce4688c16f48f3).("}"cxx . . $ QString#QString(85c52e162fed56f9).)) {
269 in_comment = false;
270 }
271
272 if(str.endsWithcxx . . $ QString#endsWith(8cce4688c16f48f3).("."cxx . . $ QString#QString(85c52e162fed56f9).) && !in_comment) {
273 if(str!=cxx . . $ QString#`operator!=`(7d4bdb1abc417636).END_OF_MOVELINEcxx . . $ `src/pdn.cc:34:9`!) {
274 if((move_num+1) != str.midcxx . . $ QString#mid(44b7563da18aea72).(0, str.lengthcxx . . $ QString#length(455f465bc33b4cdf).()-1).toIntcxx . . $ QString#toInt(d7972accae11ee1f).()) {
275 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!() <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "Move num expected:" <<cxx . . $ QDebug#`operator<<`(6e3b7ae53f380c3). move_num+1
276 <<cxx . . $ QDebug#`operator<<`(d8a917b173851aad). "received:" <<cxx . . $ QDebug#`operator<<`(4cf17434affdd8). str;
277 return false;
278 }
279 move_num++;
280 }
281
282 current_move =cxx . . $ QString#`operator=`(4f35bf974e7f8568). current_move.trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).();
283 if(current_move.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
284 m_movescxx . . $ PdnGame#m_moves..appendcxx . . $ QList#append(77d9f17553126ecb).(new PdnMovecxx . . $ PdnMove#PdnMove(7df51288a9ebd664).(current_movecxx . . $ QString#QString(132dd6869045752b).));
285 current_move =cxx . . $ QString#`operator=`(d02845eef0c33901). "";
286 }
287 continue;
288 }
289
290 if(str.isEmptycxx . . $ QString#isEmpty(50ce9a9e25b4a850).()) {
291 current_move +=cxx . . $ QString#`operator+=`(d02845eef0c33901). " ";
292 } else {
293 current_move +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). str +cxx . . $ operator+(3d22f08efddf8107). " ";
294 }
295 }
296
297 return true;
298 }
299
300
301 bool PdnGamecxx . . $ PdnGame#::parsecxx . . $ PdnGame#parse(853723320e657e87).(const QStringcxx . . $ QString#& pdngame, QStringcxx . . $ QString#& log_txt)
302 {
303 QStringcxx . . $ QString# fencxx . . $ QString#QString(ced63f7c635d850d).;
304 QStringcxx . . $ QString# movescxx . . $ QString#QString(ced63f7c635d850d).;
305 int num = pdngame.countcxx . . $ QString#count(38964227c2ffb4ec).("\n"cxx . . $ QString#QString(85c52e162fed56f9).); // Number of lines
306
307 for(int i=0; i<=num; i++) {
308 QStringcxx . . $ QString# line = pdngame.sectioncxx . . $ QString#section(6e922cf609fb9683).('\n'cxx . . $ QChar#QChar(f349c77f591a7878).,i ,i);
309 if(!line.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
310 continue;
311 }
312
313 if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("["cxx . . $ QString#QString(85c52e162fed56f9).)) {
314 line.removecxx . . $ QString#remove(6483560ce2afa901).(0, 1);
315 line =cxx . . $ QString#`operator=`(4f35bf974e7f8568). line.trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).();
316
317 if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("GameType"cxx . . $ QString#QString(85c52e162fed56f9).)) {
318 pdnTypecxx . . $ PdnGame#pdnType.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
319 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("FEN"cxx . . $ QString#QString(85c52e162fed56f9).)) {
320 fen=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
321 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("Date"cxx . . $ QString#QString(85c52e162fed56f9).)) {
322 pdnDatecxx . . $ PdnGame#pdnDate.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
323 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("Site"cxx . . $ QString#QString(85c52e162fed56f9).)) {
324 pdnSitecxx . . $ PdnGame#pdnSite.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
325 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("Event"cxx . . $ QString#QString(85c52e162fed56f9).)) {
326 pdnEventcxx . . $ PdnGame#pdnEvent.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
327 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("Round"cxx . . $ QString#QString(85c52e162fed56f9).)) {
328 pdnRoundcxx . . $ PdnGame#pdnRound.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
329 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("White"cxx . . $ QString#QString(85c52e162fed56f9).)) {
330 pdnWhitecxx . . $ PdnGame#pdnWhite.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
331 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("Black"cxx . . $ QString#QString(85c52e162fed56f9).)) {
332 pdnBlackcxx . . $ PdnGame#pdnBlack.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
333 } else if(line.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("Result"cxx . . $ QString#QString(85c52e162fed56f9).)) {
334 pdnResultcxx . . $ PdnGame#pdnResult.=cxx . . $ QString#`operator=`(4f35bf974e7f8568).line.sectioncxx . . $ QString#section(6e922cf609fb9683).('"'cxx . . $ QChar#QChar(f349c77f591a7878).,1,1);
335 } else {
336 ; // Skip other unsupported tags
337 }
338
339 } else {
340 moves +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). " " +cxx . . $ operator+(c75c3ae4eb9af1a8). line;
341 }
342 }
343
344 // parse move section.
345 if(moves.endsWithcxx . . $ QString#endsWith(8cce4688c16f48f3).(pdnResultcxx . . $ PdnGame#pdnResult.)) {
346 moves.truncatecxx . . $ QString#truncate(d4f767463ce0a6b3).(moves.lengthcxx . . $ QString#length(455f465bc33b4cdf).()-pdnResultcxx . . $ PdnGame#pdnResult..lengthcxx . . $ QString#length(455f465bc33b4cdf).());
347 } else {
348 log_txt +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). " +Different result at the end of the movelist:\n"
349 +cxx . . $ operator+(c75c3ae4eb9af1a8). QStringcxx . . $ QString#QString(85c52e162fed56f9).(" \"%1\" expected, got \"%2\"\n")
350 .argcxx . . $ QString#arg(bc823072288cbbb5).(pdnResultcxx . . $ PdnGame#pdnResult.)
351 .argcxx . . $ QString#arg(bc823072288cbbb5).(moves.rightcxx . . $ QString#right(3f3c3d0e9c0eb37f).(pdnResultcxx . . $ PdnGame#pdnResult..lengthcxx . . $ QString#length(455f465bc33b4cdf).()));
352
353 // need to remove the incorrect result.
354 if(moves.endsWithcxx . . $ QString#endsWith(8cce4688c16f48f3).(" *"cxx . . $ QString#QString(85c52e162fed56f9).)) {
355 log_txt +=cxx . . $ QString#`operator+=`(d02845eef0c33901). " => Ignoring \" *\" from the end.\n";
356 moves.truncatecxx . . $ QString#truncate(d4f767463ce0a6b3).(moves.lengthcxx . . $ QString#length(455f465bc33b4cdf).()-2);
357 } else {
358 int pos = moves.lastIndexOfcxx . . $ QString#lastIndexOf(75b556ba78e4903c).('-'cxx . . $ QChar#QChar(f349c77f591a7878).) - 1;
359 bool skip_ws = true;
360 for(int i=pos; i>=0; i--) {
361 if(moves[cxx . . $ QString#`operator[]`(57436120916eb52c).i]==cxx . . $ `operator==`(a468b2f18a3afe8).' 'cxx . . $ QChar#QChar(f349c77f591a7878).) {
362 if(!skip_ws) {
363 log_txt +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). " => Ignoring \""
364 +cxx . . $ operator+(c75c3ae4eb9af1a8). moves.rightcxx . . $ QString#right(3f3c3d0e9c0eb37f).(moves.lengthcxx . . $ QString#length(455f465bc33b4cdf).()-i-1)
365 +cxx . . $ operator+(3d22f08efddf8107). "\" from the end.\n",
366 moves.truncatecxx . . $ QString#truncate(d4f767463ce0a6b3).(i+1);
367 break;
368 }
369 } else {
370 skip_ws = false;
371 }
372 }
373 }
374 }
375
376 if(!parse_movescxx . . $ PdnGame#parse_moves(e1defb592416720d).(moves+cxx . . $ operator+(3d22f08efddf8107)." "END_OF_MOVELINEcxx . . $ `src/pdn.cc:34:9`!)) { // :)
377 log_txt +=cxx . . $ QString#`operator+=`(d02845eef0c33901). "\n +parsing moves failed.";
378 return false;
379 }
380
381 // Translation of the GameType tag
382 switch(pdnTypecxx . . $ PdnGame#pdnType..toIntcxx . . $ QString#toInt(d7972accae11ee1f).()) {
383 case ENGLISHcxx . . $ `src/pdn.h:34:9`!:
384 case RUSSIANcxx . . $ `src/pdn.h:35:9`!:
385 break;
386 default:
387 // log_txt += "\n +setting game type to english.";
388 pdnTypecxx . . $ PdnGame#pdnType..setNumcxx . . $ QString#setNum(6483560ce2afa901).(ENGLISHcxx . . $ `src/pdn.h:34:9`!);
389 break;
390 }
391
392 // Parsing of the Forsyth-Edwards Notation (FEN) tag
393 if(fen.isNullcxx . . $ QString#isNull(50ce9a9e25b4a850).()) {
394 return true;
395 }
396
397 fen=cxx . . $ QString#`operator=`(4f35bf974e7f8568).fen.trimmedcxx . . $ QString#trimmed(dca2c5857e9adf82).();
398
399 for(int i=fen.indexOfcxx . . $ QString#indexOf(a1e52806cd31c200).(" "cxx . . $ QString#QString(85c52e162fed56f9).); i!=-1; i=fen.indexOfcxx . . $ QString#indexOf(a1e52806cd31c200).(" "cxx . . $ QString#QString(85c52e162fed56f9).)) {
400 fen=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).fen.removecxx . . $ QString#remove(6483560ce2afa901).(i,1);
401 }
402
403 if(fen.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("W:W"cxx . . $ QString#QString(85c52e162fed56f9).)) {
404 whitecxx . . $ PdnGame#white.=PLAYERcxx . . $ `src/pdn.cc:31:9`!;
405 } else if(fen.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("B:W"cxx . . $ QString#QString(85c52e162fed56f9).)) {
406 whitecxx . . $ PdnGame#white.=COMPUTERcxx . . $ `src/pdn.cc:32:9`!;
407 } else {
408 return false;
409 }
410
411 QStringcxx . . $ QString# string = fen.midcxx . . $ QString#mid(44b7563da18aea72).(3).sectioncxx . . $ QString#section(eae3fc215228815e).(":B"cxx . . $ QString#QString(85c52e162fed56f9).,0,0);
412 if(!parsecxx . . $ PdnGame#parse(7bc58614ad8ebda3).(string, whitecxx . . $ PdnGame#white.)) {
413 return false;
414 }
415
416 string=cxx . . $ QString#`operator=`(4f35bf974e7f8568).fen.sectioncxx . . $ QString#section(eae3fc215228815e).(":B"cxx . . $ QString#QString(85c52e162fed56f9).,1,1);
417 if(string.endsWithcxx . . $ QString#endsWith(8cce4688c16f48f3).("."cxx . . $ QString#QString(85c52e162fed56f9).)) {
418 string.truncatecxx . . $ QString#truncate(d4f767463ce0a6b3).(string.lengthcxx . . $ QString#length(455f465bc33b4cdf).()-1);
419 }
420 if(!parsecxx . . $ PdnGame#parse(7bc58614ad8ebda3).(string, !whitecxx . . $ PdnGame#white.)) {
421 return false;
422 }
423
424 return true;
425 }
426
427
428 bool PdnGamecxx . . $ PdnGame#::parsecxx . . $ PdnGame#parse(7bc58614ad8ebda3).(const QStringcxx . . $ QString#& str, bool side)
429 {
430 QStringcxx . . $ QString# notationcxx . . $ QString#QString(ced63f7c635d850d).;
431
432 if(pdnTypecxx . . $ PdnGame#pdnType..toIntcxx . . $ QString#toInt(d7972accae11ee1f).() == ENGLISHcxx . . $ `src/pdn.h:34:9`!) {
433 notation=cxx . . $ QString#`operator=`(4f35bf974e7f8568).QStringcxx . . $ QString#QString(85c52e162fed56f9).(ENOTATIONcxx . . $ `src/pdn.h:30:9`!);
434 } else {
435 notation=cxx . . $ QString#`operator=`(4f35bf974e7f8568).QStringcxx . . $ QString#QString(85c52e162fed56f9).(RNOTATIONcxx . . $ `src/pdn.h:32:9`!);
436 }
437
438 QStringListcxx . . $ QStringList# sections = str.splitcxx . . $ QString#split(c8b44a97dcb6200d).(","cxx . . $ QString#QString(85c52e162fed56f9).);
439 foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(QString pos, sections) {
440 bool king=false;
441
442 if(pos.startsWithcxx . . $ QString#startsWith(8cce4688c16f48f3).("K"cxx . . $ QString#QString(85c52e162fed56f9).)) {
443 pos=cxx . . $ QString#`operator=`(b79fde0b0ce9b948).pos.removecxx . . $ QString#remove(6483560ce2afa901).(0,1);
444 king=true;
445 }
446 if(pos.lengthcxx . . $ QString#length(455f465bc33b4cdf).()==1) {
447 pos.appendcxx . . $ QString#append(3a2ffbdf8ecc25e2).(' 'cxx . . $ QChar#QChar(f349c77f591a7878).);
448 }
449 if(pos.lengthcxx . . $ QString#length(455f465bc33b4cdf).()!=2) {
450 return false;
451 }
452
453 int index = notation.indexOfcxx . . $ QString#indexOf(a1e52806cd31c200).(pos);
454 if(index%2) {
455 index=notation.indexOfcxx . . $ QString#indexOf(a1e52806cd31c200).(pos,index+1);
456 }
457 if(index == -1) {
458 return false;
459 }
460
461 if(whitecxx . . $ PdnGame#white.==COMPUTERcxx . . $ `src/pdn.cc:32:9`!) {
462 index=62-index;
463 }
464
465 if(side==PLAYERcxx . . $ `src/pdn.cc:31:9`!) {
466 boardcxx . . $ PdnGame#board.[index/2]=(king ? KING1cxx . . $ `src/checkers.h:34:9`! : MAN1cxx . . $ `src/checkers.h:33:9`!);
467 } else {
468 boardcxx . . $ PdnGame#board.[index/2]=(king ? KING2cxx . . $ `src/checkers.h:36:9`! : MAN2cxx . . $ `src/checkers.h:37:9`!);
469 }
470 }
471 return true;
472 }
473
474
475 PdnMovecxx . . $ PdnMove#* PdnGamecxx . . $ PdnGame#::getMovecxx . . $ PdnGame#getMove(13c520724813e2b0).(int i)
476 {
477 if(i<m_movescxx . . $ PdnGame#m_moves..countcxx . . $ QList#count(455f465bc33b4cdf).()) {
478 return m_movescxx . . $ PdnGame#m_moves..atcxx . . $ QList#at(e2681f9bb6b2f357).(i);
479 }
480
481 // TODO - do we need this?
482 if(i>m_movescxx . . $ PdnGame#m_moves..countcxx . . $ QList#count(455f465bc33b4cdf).()) {
483 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("PdnGame::getMove(%u) m_moves.count()=%u",
484 i, m_movescxx . . $ PdnGame#m_moves..countcxx . . $ QList#count(455f465bc33b4cdf).());
485 }
486
487 PdnMovecxx . . $ PdnMove#* m = new PdnMovecxx . . $ PdnMove#PdnMove(7df51288a9ebd664).(""cxx . . $ QString#QString(85c52e162fed56f9).);
488 m_movescxx . . $ PdnGame#m_moves..appendcxx . . $ QList#append(77d9f17553126ecb).(m);
489 return m;
490 }
491
492
493 QStringcxx . . $ QString# PdnGamecxx . . $ PdnGame#::toStringcxx . . $ PdnGame#toString(4365c3963150523e).()
494 {
495 QStringcxx . . $ QString# fencxx . . $ QString#QString(ced63f7c635d850d).;
496 QStringcxx . . $ QString# movescxx . . $ QString#QString(ced63f7c635d850d).;
497
498 /*
499 * fen
500 */
501 if(!movesCountcxx . . $ PdnGame#movesCount(455f465bc33b4cdf).()) {
502 qDebugcxx . . $ `<external>/10450329605257866924/qlogging.h:164:9`!("FEN tag with lots of errors.");
503
504 QStringcxx . . $ QString# string1cxx . . $ QString#QString(ced63f7c635d850d).;
505 QStringcxx . . $ QString# string2cxx . . $ QString#QString(ced63f7c635d850d).;
506 QStringcxx . . $ QString# notationcxx . . $ QString#QString(ced63f7c635d850d).;
507
508 if(pdnTypecxx . . $ PdnGame#pdnType..toIntcxx . . $ QString#toInt(d7972accae11ee1f).() == ENGLISHcxx . . $ `src/pdn.h:34:9`!) {
509 notation=cxx . . $ QString#`operator=`(4f35bf974e7f8568).QStringcxx . . $ QString#QString(85c52e162fed56f9).(ENOTATIONcxx . . $ `src/pdn.h:30:9`!);
510 } else {
511 notation=cxx . . $ QString#`operator=`(4f35bf974e7f8568).QStringcxx . . $ QString#QString(85c52e162fed56f9).(RNOTATIONcxx . . $ `src/pdn.h:32:9`!);
512 }
513
514 for(int i=0; i<32; i++) {
515 int index=i*2;
516 if(whitecxx . . $ PdnGame#white.==COMPUTERcxx . . $ `src/pdn.cc:32:9`!) {
517 index=62-index;
518 }
519
520 QStringcxx . . $ QString# poscxx . . $ QString#QString(ced63f7c635d850d).;
521
522 switch(boardcxx . . $ PdnGame#board.[i]) {
523 case KING1cxx . . $ `src/checkers.h:34:9`!:
524 pos.appendcxx . . $ QString#append(3a2ffbdf8ecc25e2).('K'cxx . . $ QChar#QChar(f349c77f591a7878).);
525 case MAN1cxx . . $ `src/checkers.h:33:9`!:
526 pos.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(notation.midcxx . . $ QString#mid(44b7563da18aea72).(index,2).trimmedcxx . . $ QString#trimmed(30b3b70527b1c61a).());
527 if(string1.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
528 string1.appendcxx . . $ QString#append(3a2ffbdf8ecc25e2).(','cxx . . $ QChar#QChar(f349c77f591a7878).);
529 }
530 string1.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(pos);
531 break;
532
533 case KING2cxx . . $ `src/checkers.h:36:9`!:
534 pos.appendcxx . . $ QString#append(3a2ffbdf8ecc25e2).('K'cxx . . $ QChar#QChar(f349c77f591a7878).);
535 case MAN2cxx . . $ `src/checkers.h:37:9`!:
536 pos.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(notation.midcxx . . $ QString#mid(44b7563da18aea72).(index,2).trimmedcxx . . $ QString#trimmed(30b3b70527b1c61a).());
537 if(string2.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
538 string2.appendcxx . . $ QString#append(3a2ffbdf8ecc25e2).(','cxx . . $ QChar#QChar(f349c77f591a7878).);
539 }
540 string2.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(pos);
541 default:
542 break;
543 }
544 }
545
546 if(whitecxx . . $ PdnGame#white.==PLAYERcxx . . $ `src/pdn.cc:31:9`!) {
547 fen.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("W:W"+cxx . . $ operator+(c75c3ae4eb9af1a8).string1+cxx . . $ operator+(3d22f08efddf8107).":B"+cxx . . $ operator+(fab9b4f80031f353).string2+cxx . . $ operator+(3d22f08efddf8107).".");
548 } else {
549 fen.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("B:W"+cxx . . $ operator+(c75c3ae4eb9af1a8).string2+cxx . . $ operator+(3d22f08efddf8107).":B"+cxx . . $ operator+(fab9b4f80031f353).string1+cxx . . $ operator+(3d22f08efddf8107).".");
550 }
551 }
552
553 /*
554 * moves
555 */
556 unsigned int count = 1;
557 foreachcxx . . $ `<external>/15045578679651060896/qglobal.h:1145:13`!(PdnMove* move, m_moves) {
558 moves +=cxx . . $ QString#`operator+=`(6a89d0b7f4d2681c). QStringcxx . . $ QString#QString(85c52e162fed56f9).("%1. %2 %3%4%5\n")
559 .argcxx . . $ QString#arg(173a29139b43af1f).(count)
560 .argcxx . . $ QString#arg(bc823072288cbbb5).(move->m_firstcxx . . $ PdnMove#m_first.)
561 .argcxx . . $ QString#arg(bc823072288cbbb5).(move->m_comfirstcxx . . $ PdnMove#m_comfirst..lengthcxx . . $ QString#length(455f465bc33b4cdf).() ? "{"+cxx . . $ operator+(c75c3ae4eb9af1a8).move->m_comfirstcxx . . $ PdnMove#m_comfirst.+cxx . . $ operator+(3d22f08efddf8107)."} " : ""cxx . . $ QString#QString(85c52e162fed56f9).)
562 .argcxx . . $ QString#arg(bc823072288cbbb5).(move->m_secondcxx . . $ PdnMove#m_second.)
563 .argcxx . . $ QString#arg(bc823072288cbbb5).(move->m_comsecondcxx . . $ PdnMove#m_comsecond..lengthcxx . . $ QString#length(455f465bc33b4cdf).() ? " {"+cxx . . $ operator+(c75c3ae4eb9af1a8).move->m_comsecondcxx . . $ PdnMove#m_comsecond.+cxx . . $ operator+(3d22f08efddf8107)."}" : ""cxx . . $ QString#QString(85c52e162fed56f9).);
564 count++;
565 }
566
567
568 /*
569 * create format and write tags+fen+moves.
570 */
571 QStringcxx . . $ QString# strcxx . . $ QString#QString(ced63f7c635d850d).;
572
573 if(pdnEventcxx . . $ PdnGame#pdnEvent..lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
574 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[Event \""+cxx . . $ operator+(c75c3ae4eb9af1a8).pdnEventcxx . . $ PdnGame#pdnEvent.+cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
575 }
576 if(pdnSitecxx . . $ PdnGame#pdnSite..lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
577 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[Site \"" +cxx . . $ operator+(c75c3ae4eb9af1a8).pdnSitecxx . . $ PdnGame#pdnSite. +cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
578 }
579 if(pdnDatecxx . . $ PdnGame#pdnDate..lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
580 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[Date \"" +cxx . . $ operator+(c75c3ae4eb9af1a8).pdnDatecxx . . $ PdnGame#pdnDate. +cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
581 }
582 if(pdnRoundcxx . . $ PdnGame#pdnRound..lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
583 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[Round \""+cxx . . $ operator+(c75c3ae4eb9af1a8).pdnRoundcxx . . $ PdnGame#pdnRound.+cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
584 }
585 if(pdnWhitecxx . . $ PdnGame#pdnWhite..lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
586 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[White \""+cxx . . $ operator+(c75c3ae4eb9af1a8).pdnWhitecxx . . $ PdnGame#pdnWhite.+cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
587 }
588 if(pdnBlackcxx . . $ PdnGame#pdnBlack..lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
589 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[Black \""+cxx . . $ operator+(c75c3ae4eb9af1a8).pdnBlackcxx . . $ PdnGame#pdnBlack.+cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
590 }
591
592 if(fen.lengthcxx . . $ QString#length(455f465bc33b4cdf).()) {
593 str.appendcxx . . $ QString#append(d02845eef0c33901).("[SetUp \"1\"]\n");
594 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[FEN \""+cxx . . $ operator+(c75c3ae4eb9af1a8).fen+cxx . . $ operator+(3d22f08efddf8107)."\"]\n\n");
595 }
596
597 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[Result \""+cxx . . $ operator+(c75c3ae4eb9af1a8).pdnResultcxx . . $ PdnGame#pdnResult.+cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
598 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).("[GameType \""+cxx . . $ operator+(c75c3ae4eb9af1a8).pdnTypecxx . . $ PdnGame#pdnType.+cxx . . $ operator+(3d22f08efddf8107)."\"]\n");
599 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(moves);
600 str.appendcxx . . $ QString#append(6a89d0b7f4d2681c).(pdnResultcxx . . $ PdnGame#pdnResult.+cxx . . $ operator+(3d22f08efddf8107)."\n");
601
602 return strcxx . . $ QString#QString(28715ad661ad3cec).;
603 }