| 165 | | try { |
|---|
| 166 | | if (cursor.currentNode().has_key('SZ') && strip(cursor.currentNode()['SZ'][0]) != `self.boardsize`) |
|---|
| 167 | | messages.insert('end', 'SGF file '+ f + iColl +\ |
|---|
| 168 | | ' does not contain a %sx%s game. Skipped.\n' \ |
|---|
| 169 | | % (`self.boardsize`, `self.boardsize`)); |
|---|
| 170 | | continue; |
|---|
| 171 | | |
|---|
| 172 | | char playerB[]; |
|---|
| 173 | | char playerW[]; |
|---|
| 174 | | char result; |
|---|
| 175 | | char date[11]; |
|---|
| 176 | | |
|---|
| 177 | | if (cursor.currentNode().has_key('PB')) { |
|---|
| 178 | | playerB = replace(cursor.currentNode()['PB'][0], '|%', ' '); |
|---|
| 179 | | playerB = replace(playerB, '\r', ' '); |
|---|
| 180 | | playerB = replace(playerB, '\n', ' '); |
|---|
| | 152 | try { |
|---|
| | 153 | if (cursor.currentNode().has_key('SZ') && strip(cursor.currentNode()['SZ'][0]) != `self.boardsize`) |
|---|
| | 154 | messages.insert('end', 'SGF file '+ f + iColl +\ |
|---|
| | 155 | ' does not contain a %sx%s game. Skipped.\n' \ |
|---|
| | 156 | % (`self.boardsize`, `self.boardsize`)); |
|---|
| | 157 | continue; |
|---|
| | 158 | |
|---|
| | 159 | char playerB[]; |
|---|
| | 160 | char playerW[]; |
|---|
| | 161 | char result; |
|---|
| | 162 | char date[11]; |
|---|
| | 163 | |
|---|
| | 164 | if (cursor.currentNode().has_key('PB')) { |
|---|
| | 165 | playerB = replace(cursor.currentNode()['PB'][0], '|%', ' '); |
|---|
| | 166 | playerB = replace(playerB, '\r', ' '); |
|---|
| | 167 | playerB = replace(playerB, '\n', ' '); |
|---|
| | 168 | } |
|---|
| | 169 | else playerB = '?'; |
|---|
| | 170 | |
|---|
| | 171 | if (cursor.currentNode().has_key('PW')) { |
|---|
| | 172 | playerW = replace(cursor.currentNode()['PW'][0], '|%', ' '); |
|---|
| | 173 | playerW = replace(playerW, '\r', ' '); |
|---|
| | 174 | playerW = replace(playerW, '\n', ' '); |
|---|
| | 175 | } |
|---|
| | 176 | else playerW = '?'; |
|---|
| | 177 | |
|---|
| | 178 | if (cursor.currentNode().has_key('RE') && strip(cursor.currentNode()['RE'][0])) |
|---|
| | 179 | result = strip(cursor.currentNode()['RE'][0])[0]; |
|---|
| | 180 | else result = '-'; |
|---|
| | 181 | |
|---|
| | 182 | if (cursor.currentNode().has_key('DT') && cursor.currentNode()['DT'][0]) { |
|---|
| | 183 | date_str = cursor.currentNode()['DT'][0]; |
|---|
| | 184 | |
|---|
| | 185 | m = re.search('(^|[^\d])(\d\d\d\d-\d\d-\d\d)($|[^\d])', date_str); |
|---|
| | 186 | |
|---|
| | 187 | try |
|---|
| | 188 | date = m.group(2); |
|---|
| | 189 | catch (AttributeError, ValueError) { |
|---|
| | 190 | m = re.search('(^|[^\d])(\d\d\d\d-\d\d)($|[^\d])', date_str); |
|---|
| | 191 | try |
|---|
| | 192 | date = m.group(2); |
|---|
| | 193 | catch (AttributeError, ValueError) { |
|---|
| | 194 | m = re.search('(^|[^\d])(\d\d\d\d)($|[^\d])', date_str); |
|---|
| | 195 | try |
|---|
| | 196 | date = m.group(2); |
|---|
| | 197 | catch (AttributeError, ValueError) |
|---|
| | 198 | date = ''; |
|---|
| | 199 | // else FIXME |
|---|
| | 200 | // date = '' |
|---|
| | 201 | } |
|---|
| | 202 | } |
|---|
| | 203 | } |
|---|
| | 204 | |
|---|
| | 205 | char signature1[]; |
|---|
| | 206 | char signature2[]; |
|---|
| | 207 | } |
|---|
| | 208 | catch { |
|---|
| | 209 | messages.insert('end', 'SGF Error in root node of game ' + iColl + \ |
|---|
| | 210 | ', file ' + f + ', skipped.\n'); |
|---|
| | 211 | continue; |
|---|
| | 212 | } |
|---|
| | 213 | |
|---|
| | 214 | int counter = -1; |
|---|
| | 215 | |
|---|
| | 216 | try { |
|---|
| | 217 | |
|---|
| | 218 | for(algo in algolist) algo.newgame_process(); |
|---|
| | 219 | |
|---|
| | 220 | b = abstractBoard(); |
|---|
| | 221 | vector<> branchpoints; |
|---|
| | 222 | |
|---|
| | 223 | while(1) { |
|---|
| | 224 | counter++; |
|---|
| | 225 | |
|---|
| | 226 | try { |
|---|
| | 227 | if (cursor.currentNode().has_key('B') || cursor.currentNode().has_key('W')) { |
|---|
| | 228 | if (cursor.currentNode().has_key('B')) co = 'B'; |
|---|
| | 229 | else co = 'W'; |
|---|
| | 230 | |
|---|
| | 231 | char* p = cursor.currentNode()[co][0]; |
|---|
| | 232 | if (strlen(p) != 2) |
|---|
| | 233 | if (!strlen(p)) { |
|---|
| | 234 | messages.insert('end', 'SGF Error in file ' + f + '\n'); |
|---|
| | 235 | break; |
|---|
| | 236 | } |
|---|
| | 237 | assert len(p) == 2; |
|---|
| | 238 | |
|---|
| | 239 | int x = p[0] - oa; |
|---|
| | 240 | int y = p[1] - oa; |
|---|
| | 241 | |
|---|
| | 242 | if (0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize) { |
|---|
| | 243 | if (!b.play((x, y), co)) { |
|---|
| | 244 | messages.insert('end', 'Illegal move in file ' + f \ |
|---|
| | 245 | + ' (' + `counter+1` + ')\n'); |
|---|
| | 246 | break; |
|---|
| | 247 | } |
|---|
| | 248 | } |
|---|
| | 249 | else |
|---|
| | 250 | if (x != 19 || y != 19) { |
|---|
| | 251 | messages.insert('end', 'Invalid move in file '+f+ |
|---|
| | 252 | ' (' + `counter+1` + ')\n'); |
|---|
| | 253 | break; |
|---|
| | 254 | } |
|---|
| | 255 | |
|---|
| | 256 | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| | 257 | |
|---|
| | 258 | if (b.undostack.size()) |
|---|
| | 259 | captures = b.undostack[len(b.undostack)-1][2]; |
|---|
| | 260 | else assert 0; // FIXME? |
|---|
| | 261 | |
|---|
| | 262 | if (counter+1 in [20, 40, 60]) signature1 = signature1 + chr(x + oa) + chr(y + oa); |
|---|
| | 263 | if (counter+1 in [31, 51, 71]) signature2 = signature2 + chr(x + oa) + chr(y + oa); |
|---|
| | 264 | |
|---|
| | 265 | for(algo in algolist) |
|---|
| | 266 | if (co == 'B') algo.B_process(x, y, captures); |
|---|
| | 267 | else algo.W_process(x, y, captures); |
|---|
| | 268 | } |
|---|
| | 269 | else { |
|---|
| | 270 | if (cursor.currentNode().has_key('AB')) |
|---|
| | 271 | for (p in cursor.currentNode()['AB']) { |
|---|
| | 272 | if (strlen(p) != 2) continue; |
|---|
| | 273 | int x = ord(p[0])-oa; |
|---|
| | 274 | int y = ord(p[1])-oa; |
|---|
| | 275 | if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) |
|---|
| | 276 | messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); |
|---|
| | 277 | |
|---|
| | 278 | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| | 279 | b.play((x, y), 'black'); |
|---|
| | 280 | for(algo in algolist) algo.AB_process(x, y); |
|---|
| | 281 | } |
|---|
| | 282 | |
|---|
| | 283 | if (cursor.currentNode().has_key('AW')) |
|---|
| | 284 | for (p in cursor.currentNode()['AW']) { |
|---|
| | 285 | if (strlen(p) != 2) continue; |
|---|
| | 286 | int x = ord(p[0])-oa; |
|---|
| | 287 | int y = ord(p[1])-oa; |
|---|
| | 288 | if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) |
|---|
| | 289 | messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); |
|---|
| | 290 | |
|---|
| | 291 | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| | 292 | b.play((x, y), 'white'); |
|---|
| | 293 | for (algo in algolist) algo.AW_process(x, y); |
|---|
| | 294 | } |
|---|
| | 295 | |
|---|
| | 296 | if (cursor.currentNode().has_key('AE')) |
|---|
| | 297 | for(p in cursor.currentNode()['AE']) { |
|---|
| | 298 | if (strlen(p) != 2) continue; |
|---|
| | 299 | int x = ord(p[0])-oa; |
|---|
| | 300 | int y = ord(p[1])-oa; |
|---|
| | 301 | if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) |
|---|
| | 302 | messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); |
|---|
| | 303 | |
|---|
| | 304 | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| | 305 | assert b.status.has_key((x,y)); |
|---|
| | 306 | |
|---|
| | 307 | if (b.status[(x,y)] == 'black') removed = 'B'; |
|---|
| | 308 | elif (b.status[(x,y)] == 'white') removed = 'W'; |
|---|
| | 309 | b.remove((x, y)); |
|---|
| | 310 | for(algo in algolist) algo.AE_process(x, y, removed); |
|---|
| | 311 | } |
|---|
| | 312 | } |
|---|
| | 313 | } |
|---|
| | 314 | catch AssertionError |
|---|
| | 315 | pass; |
|---|
| | 316 | |
|---|
| | 317 | for(algo in algolist) algo.endOfNode_process(); |
|---|
| | 318 | |
|---|
| | 319 | if (processVariations && cursor.noChildren() > 1) { |
|---|
| | 320 | for (algo in algolist) algo.branchpoint_process(); |
|---|
| | 321 | self.branchpoints.append((cursor.currentN, b.copy(), 0)); |
|---|
| | 322 | } |
|---|
| | 323 | |
|---|
| | 324 | if (!cursor.atEnd()) cursor.next(); |
|---|
| | 325 | else if (self.branchpoints) { |
|---|
| | 326 | for (algo in algolist) algo.endOfVariation_process(); |
|---|
| | 327 | |
|---|
| | 328 | cursor.currentN, b, whichVar = self.branchpoints.pop(); |
|---|
| | 329 | if (whichVar+2 < cursor.noChildren()) { |
|---|
| | 330 | for (algo in algolist) algo.branchpoint_process(); |
|---|
| | 331 | self.branchpoints.append((cursor.currentN, b.copy(), whichVar+1)); |
|---|
| | 332 | } |
|---|
| | 333 | cursor.next(whichVar+1); |
|---|
| | 334 | } |
|---|
| | 335 | else break; |
|---|
| | 336 | } |
|---|
| | 337 | } |
|---|
| | 338 | |
|---|
| | 339 | catch SGFError { |
|---|
| | 340 | messages.insert('end', 'File ' + f +iColl + ': SGF error in node ' + `counter+3` + '.\n'); |
|---|
| | 341 | } |
|---|
| | 342 | catch (*) { |
|---|
| | 343 | messages.insert('end', 'File ' + f + iColl + ': Error in node ' + `counter+3` + '.\n'); |
|---|
| | 344 | } |
|---|
| | 345 | |
|---|
| | 346 | try { |
|---|
| | 347 | XXX while (strlen(signature1) < 6) signature1 += "??"; |
|---|
| | 348 | XXX while (strlen(signature2) < 6) signature2 += "??"; |
|---|
| | 349 | XXX signature = signature1 + signature2; |
|---|
| | 350 | signature = symmetrizeSig(signature); |
|---|
| | 351 | |
|---|
| | 352 | // if (duplicateCheck && (counter > 20 || (counter > 5 && strictDuplicateCheck))) { |
|---|
| | 353 | // duplist = []; |
|---|
| | 354 | // for (sli in range(len(siglist))) |
|---|
| | 355 | // if (siglist[sli] == signature && |
|---|
| | 356 | // (not strictDuplicateCheck || algolist[0].duplicateCheck(sli))) |
|---|
| | 357 | // duplist.append(split(Namelist[sli], '|%')[0]); |
|---|
| | 358 | // |
|---|
| | 359 | // if (gamelist) { // FIXME |
|---|
| | 360 | // for (db in gamelist.DBlist[bsize]) { |
|---|
| | 361 | // if (db.disabled) continue; |
|---|
| | 362 | // for (i in range(len(db.namelist))) { |
|---|
| | 363 | // g = db.namelist[i]; |
|---|
| | 364 | // if (signature == g[4]) |
|---|
| | 365 | // if (!strictDuplicateCheck) |
|---|
| | 366 | // duplist.append(os.path.join(db.sgfpath, g[0])); |
|---|
| | 367 | // else |
|---|
| | 368 | // if (algolist[0].duplicateCheck(i, db.datapath)) |
|---|
| | 369 | // duplist.append(os.path.join(db.sgfpath, g[0])); |
|---|
| | 370 | // } |
|---|
| | 371 | // } |
|---|
| | 372 | // } |
|---|
| | 373 | // |
|---|
| | 374 | // if (strictDuplicateCheck) |
|---|
| | 375 | // char* dupText = " is the same as "; |
|---|
| | 376 | // else |
|---|
| | 377 | // char* dupText = " is probably the same as "; // do we have to delete this? FIXME |
|---|
| | 378 | // |
|---|
| | 379 | // if (duplist.size()) { |
|---|
| | 380 | // ff = join(duplist, ', '); |
|---|
| | 381 | // if (duplicateCheck == 1) |
|---|
| | 382 | // messages.insert('end', 'Duplicate: ' + os.path.split(f)[1] +iColl+ dupText + ff + '.\n'); |
|---|
| | 383 | // else if (duplicateCheck == 3) { |
|---|
| | 384 | // messages.insert('end', 'Duplicate: '+os.path.split(f)[1]+iColl+\ |
|---|
| | 385 | // dupText + ff + ', omitted.\n'); |
|---|
| | 386 | // continue; |
|---|
| | 387 | // } |
|---|
| | 388 | // else if (duplicateCheck == 2) { |
|---|
| | 389 | // if (askyesno('Duplicate', 'File ' +os.path.split(f)[1]+iColl\ |
|---|
| | 390 | // + ' is the same as ' + ff + '. Include it?')) |
|---|
| | 391 | // messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]+iColl\ |
|---|
| | 392 | // + dupText + ff + '\n'); |
|---|
| | 393 | // else { |
|---|
| | 394 | // messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]\ |
|---|
| | 395 | // + dupText + ff + ', omitted.\n'); |
|---|
| | 396 | // continue; |
|---|
| | 397 | // } |
|---|
| | 398 | // } |
|---|
| | 399 | // } |
|---|
| | 400 | // } |
|---|
| | 401 | |
|---|
| | 402 | siglist.append(signature); |
|---|
| | 403 | } |
|---|
| | 404 | |
|---|
| | 405 | XXX catch (*) { |
|---|
| | 406 | XXX messages.insert('end', 'File ' + f +iColl + ': Error computing the Dyer signature.\n'); |
|---|
| | 407 | signature = "????????????"; |
|---|
| | 408 | } |
|---|
| | 409 | |
|---|
| | 410 | for (algo in algolist) algo.endgame_process(); |
|---|
| | 411 | |
|---|
| | 412 | if (os.path.split(f)[1][-4:] == '.sgf') filenameDB = os.path.split(f)[1][:-4]; |
|---|
| | 413 | else if (os.path.split(f)[1][-4:] == '.mgt') filenameDB = os.path.split(f)[1][:-2]; |
|---|
| | 414 | else filenameDB = os.path.split(f)[1] + '.'; |
|---|
| | 415 | |
|---|
| | 416 | Namelist.append(filenameDB + iColl + '|%' + playerB + '|%' + playerW + '|%' \ |
|---|
| | 417 | + result + '|%' + signature + '|%' + date); |
|---|
| | 418 | |
|---|
| | 419 | gameCtr++; |
|---|
| | 420 | } |
|---|
| | 421 | } |
|---|
| | 422 | |
|---|
| | 423 | if (gameCtr) { |
|---|
| | 424 | try { |
|---|
| | 425 | for (algo in algolist) algo.finalize_process(datap); |
|---|
| 217 | | |
|---|
| 218 | | char signature1[]; |
|---|
| 219 | | char signature2[]; |
|---|
| 220 | | } |
|---|
| 221 | | catch { |
|---|
| 222 | | messages.insert('end', 'SGF Error in root node of game ' + iColl + \ |
|---|
| 223 | | ', file ' + f + ', skipped.\n'); |
|---|
| 224 | | continue; |
|---|
| 225 | | } |
|---|
| 226 | | |
|---|
| 227 | | int counter = -1; |
|---|
| 228 | | |
|---|
| 229 | | try { |
|---|
| 230 | | |
|---|
| 231 | | for(algo in algolist) algo.newgame_process(); |
|---|
| 232 | | |
|---|
| 233 | | b = abstractBoard(); |
|---|
| 234 | | vector<> branchpoints; |
|---|
| 235 | | |
|---|
| 236 | | while(1) { |
|---|
| 237 | | counter++; |
|---|
| 238 | | |
|---|
| 239 | | try { |
|---|
| 240 | | if (cursor.currentNode().has_key('B') || cursor.currentNode().has_key('W')) { |
|---|
| 241 | | if (cursor.currentNode().has_key('B')) co = 'B'; |
|---|
| 242 | | else co = 'W'; |
|---|
| 243 | | |
|---|
| 244 | | char* p = cursor.currentNode()[co][0]; |
|---|
| 245 | | if (strlen(p) != 2) |
|---|
| 246 | | if (!strlen(p)) { |
|---|
| 247 | | messages.insert('end', 'SGF Error in file ' + f + '\n'); |
|---|
| 248 | | break; |
|---|
| 249 | | } |
|---|
| 250 | | assert len(p) == 2; |
|---|
| 251 | | |
|---|
| 252 | | int x = p[0] - oa; |
|---|
| 253 | | int y = p[1] - oa; |
|---|
| 254 | | |
|---|
| 255 | | if (0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize) { |
|---|
| 256 | | if (!b.play((x, y), co)) { |
|---|
| 257 | | messages.insert('end', 'Illegal move in file ' + f \ |
|---|
| 258 | | + ' (' + `counter+1` + ')\n'); |
|---|
| 259 | | break; |
|---|
| 260 | | } |
|---|
| 261 | | } |
|---|
| 262 | | else |
|---|
| 263 | | if (x != 19 || y != 19) { |
|---|
| 264 | | messages.insert('end', 'Invalid move in file '+f+ |
|---|
| 265 | | ' (' + `counter+1` + ')\n'); |
|---|
| 266 | | break; |
|---|
| 267 | | } |
|---|
| 268 | | |
|---|
| 269 | | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| 270 | | |
|---|
| 271 | | if (b.undostack.size()) |
|---|
| 272 | | captures = b.undostack[len(b.undostack)-1][2]; |
|---|
| 273 | | else assert 0; // FIXME? |
|---|
| 274 | | |
|---|
| 275 | | if (counter+1 in [20, 40, 60]) signature1 = signature1 + chr(x + oa) + chr(y + oa); |
|---|
| 276 | | if (counter+1 in [31, 51, 71]) signature2 = signature2 + chr(x + oa) + chr(y + oa); |
|---|
| 277 | | |
|---|
| 278 | | for(algo in algolist) |
|---|
| 279 | | if (co == 'B') algo.B_process(x, y, captures); |
|---|
| 280 | | else algo.W_process(x, y, captures); |
|---|
| 281 | | } |
|---|
| 282 | | else { |
|---|
| 283 | | if (cursor.currentNode().has_key('AB')) |
|---|
| 284 | | for (p in cursor.currentNode()['AB']) { |
|---|
| 285 | | if (strlen(p) != 2) continue; |
|---|
| 286 | | int x = ord(p[0])-oa; |
|---|
| 287 | | int y = ord(p[1])-oa; |
|---|
| 288 | | if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) |
|---|
| 289 | | messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); |
|---|
| 290 | | |
|---|
| 291 | | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| 292 | | b.play((x, y), 'black'); |
|---|
| 293 | | for(algo in algolist) algo.AB_process(x, y); |
|---|
| 294 | | } |
|---|
| 295 | | |
|---|
| 296 | | if (cursor.currentNode().has_key('AW')) |
|---|
| 297 | | for (p in cursor.currentNode()['AW']) { |
|---|
| 298 | | if (strlen(p) != 2) continue; |
|---|
| 299 | | int x = ord(p[0])-oa; |
|---|
| 300 | | int y = ord(p[1])-oa; |
|---|
| 301 | | if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) |
|---|
| 302 | | messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); |
|---|
| 303 | | |
|---|
| 304 | | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| 305 | | b.play((x, y), 'white'); |
|---|
| 306 | | for (algo in algolist) algo.AW_process(x, y); |
|---|
| 307 | | } |
|---|
| 308 | | |
|---|
| 309 | | if (cursor.currentNode().has_key('AE')) |
|---|
| 310 | | for(p in cursor.currentNode()['AE']) { |
|---|
| 311 | | if (strlen(p) != 2) continue; |
|---|
| 312 | | int x = ord(p[0])-oa; |
|---|
| 313 | | int y = ord(p[1])-oa; |
|---|
| 314 | | if (!(0 <= x && x < self.boardsize && 0 <= y && y < self.boardsize)) |
|---|
| 315 | | messages.insert('end', 'Invalid position in AE tag, in file ' + f + '\n'); |
|---|
| 316 | | |
|---|
| 317 | | assert 0 <= x < self.boardsize and 0 <= y < self.boardsize; |
|---|
| 318 | | assert b.status.has_key((x,y)); |
|---|
| 319 | | |
|---|
| 320 | | if (b.status[(x,y)] == 'black') removed = 'B'; |
|---|
| 321 | | elif (b.status[(x,y)] == 'white') removed = 'W'; |
|---|
| 322 | | b.remove((x, y)); |
|---|
| 323 | | for(algo in algolist) algo.AE_process(x, y, removed); |
|---|
| 324 | | } |
|---|
| 325 | | } |
|---|
| 326 | | } |
|---|
| 327 | | catch AssertionError |
|---|
| 328 | | pass; |
|---|
| 329 | | |
|---|
| 330 | | for(algo in algolist) algo.endOfNode_process(); |
|---|
| 331 | | |
|---|
| 332 | | if (processVariations && cursor.noChildren() > 1) { |
|---|
| 333 | | for (algo in algolist) algo.branchpoint_process(); |
|---|
| 334 | | self.branchpoints.append((cursor.currentN, b.copy(), 0)); |
|---|
| 335 | | } |
|---|
| 336 | | |
|---|
| 337 | | if (!cursor.atEnd()) cursor.next(); |
|---|
| 338 | | else if (self.branchpoints) { |
|---|
| 339 | | for (algo in algolist) algo.endOfVariation_process(); |
|---|
| 340 | | |
|---|
| 341 | | cursor.currentN, b, whichVar = self.branchpoints.pop(); |
|---|
| 342 | | if (whichVar+2 < cursor.noChildren()) { |
|---|
| 343 | | for (algo in algolist) algo.branchpoint_process(); |
|---|
| 344 | | self.branchpoints.append((cursor.currentN, b.copy(), whichVar+1)); |
|---|
| 345 | | } |
|---|
| 346 | | cursor.next(whichVar+1); |
|---|
| 347 | | } |
|---|
| 348 | | else break; |
|---|
| 349 | | } |
|---|
| 350 | | } |
|---|
| 351 | | |
|---|
| 352 | | catch SGFError { |
|---|
| 353 | | messages.insert('end', 'File ' + f +iColl + ': SGF error in node ' + `counter+3` + '.\n'); |
|---|
| 354 | | } |
|---|
| 355 | | catch (*) { |
|---|
| 356 | | messages.insert('end', 'File ' + f + iColl + ': Error in node ' + `counter+3` + '.\n'); |
|---|
| 357 | | } |
|---|
| 358 | | |
|---|
| 359 | | try { |
|---|
| 360 | | while (strlen(signature1) < 6) signature1 += '??'; |
|---|
| 361 | | while (strlen(signature2) < 6) signature2 += '??'; |
|---|
| 362 | | signature = signature1 + signature2; |
|---|
| 363 | | signature = symmetrizeSig(signature); |
|---|
| 364 | | |
|---|
| 365 | | if (duplicateCheck && (counter > 20 || (counter > 5 && strictDuplicateCheck))) { |
|---|
| 366 | | duplist = []; |
|---|
| 367 | | for (sli in range(len(siglist))) |
|---|
| 368 | | if (siglist[sli] == signature && |
|---|
| 369 | | (not strictDuplicateCheck || algolist[0].duplicateCheck(sli))) |
|---|
| 370 | | duplist.append(split(namelist[sli], '|%')[0]); |
|---|
| 371 | | |
|---|
| 372 | | if (gamelist) { // FIXME |
|---|
| 373 | | for (db in gamelist.DBlist[bsize]) { |
|---|
| 374 | | if (db.disabled) continue; |
|---|
| 375 | | for (i in range(len(db.namelist))) { |
|---|
| 376 | | g = db.namelist[i]; |
|---|
| 377 | | if (signature == g[4]) |
|---|
| 378 | | if (!strictDuplicateCheck) |
|---|
| 379 | | duplist.append(os.path.join(db.sgfpath, g[0])); |
|---|
| 380 | | else |
|---|
| 381 | | if (algolist[0].duplicateCheck(i, db.datapath)) |
|---|
| 382 | | duplist.append(os.path.join(db.sgfpath, g[0])); |
|---|
| 383 | | } |
|---|
| 384 | | } |
|---|
| 385 | | } |
|---|
| 386 | | |
|---|
| 387 | | if (strictDuplicateCheck) |
|---|
| 388 | | char* dupText = " is the same as "; |
|---|
| 389 | | else |
|---|
| 390 | | char* dupText = " is probably the same as "; // do we have to delete this? FIXME |
|---|
| 391 | | |
|---|
| 392 | | if (duplist.size()) { |
|---|
| 393 | | ff = join(duplist, ', '); |
|---|
| 394 | | if (duplicateCheck == 1) |
|---|
| 395 | | messages.insert('end', 'Duplicate: ' + os.path.split(f)[1] +iColl+ dupText + ff + '.\n'); |
|---|
| 396 | | else if (duplicateCheck == 3) { |
|---|
| 397 | | messages.insert('end', 'Duplicate: '+os.path.split(f)[1]+iColl+\ |
|---|
| 398 | | dupText + ff + ', omitted.\n'); |
|---|
| 399 | | continue; |
|---|
| 400 | | } |
|---|
| 401 | | else if (duplicateCheck == 2) { |
|---|
| 402 | | if (askyesno('Duplicate', 'File ' +os.path.split(f)[1]+iColl\ |
|---|
| 403 | | + ' is the same as ' + ff + '. Include it?')) |
|---|
| 404 | | messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]+iColl\ |
|---|
| 405 | | + dupText + ff + '\n'); |
|---|
| 406 | | else { |
|---|
| 407 | | messages.insert('end', 'Duplicate: ' + os.path.split(f)[1]\ |
|---|
| 408 | | + dupText + ff + ', omitted.\n'); |
|---|
| 409 | | continue; |
|---|
| 410 | | } |
|---|
| 411 | | } |
|---|
| 412 | | } |
|---|
| 413 | | } |
|---|
| 414 | | |
|---|
| 415 | | siglist.append(signature); |
|---|
| 416 | | } |
|---|
| 417 | | |
|---|
| 418 | | catch (*) { |
|---|
| 419 | | messages.insert('end', 'File ' + f +iColl + ': Error computing the Dyer signature.\n'); |
|---|
| 420 | | signature = '????????????'; |
|---|
| 421 | | } |
|---|
| 422 | | |
|---|
| 423 | | for (algo in algolist) algo.endgame_process(); |
|---|
| 424 | | |
|---|
| 425 | | if (os.path.split(f)[1][-4:] == '.sgf') filenameDB = os.path.split(f)[1][:-4]; |
|---|
| 426 | | else if (os.path.split(f)[1][-4:] == '.mgt') filenameDB = os.path.split(f)[1][:-2]; |
|---|
| 427 | | else filenameDB = os.path.split(f)[1] + '.'; |
|---|
| 428 | | |
|---|
| 429 | | namelist.append(filenameDB + iColl + '|%' + playerB + '|%' + playerW + '|%' \ |
|---|
| 430 | | + result + '|%' + signature + '|%' + date); |
|---|
| 431 | | |
|---|
| 432 | | gameCtr++; |
|---|
| 433 | | } |
|---|
| 434 | | } |
|---|
| 435 | | |
|---|
| 436 | | if (gameCtr) { |
|---|
| 437 | | try { |
|---|
| 438 | | for (algo in algolist) algo.finalize_process(datap); |
|---|
| 439 | | } |
|---|
| 440 | | catch IOError { |
|---|
| 441 | | messages.insert('end', 'I/O Error: Could not write database files (Directory write-protected?).\n'); |
|---|
| 442 | | return; |
|---|
| 443 | | } |
|---|
| 444 | | |
|---|
| 445 | | try { |
|---|
| 446 | | file = open(os.path.join(datap[0], 'namelist' + datap[1] + '.db'), 'w'); |
|---|
| 447 | | for (s in namelist) |
|---|
| 448 | | file.write(s+'\n'); |
|---|
| 449 | | file.close(); |
|---|
| 450 | | } |
|---|
| 451 | | catch IOError |
|---|
| 452 | | messages.insert('end', 'I/O Error: Could not write namelist.db file.\n'); |
|---|
| 453 | | |
|---|
| 454 | | if (progBar) { |
|---|
| 455 | | progBar.redraw(1); |
|---|
| 456 | | progBar.write('%1.1f seconds' % (time.time() - currentTime)); |
|---|
| 457 | | } |
|---|
| 458 | | |
|---|
| 459 | | messages.insert('end', '%1.1f seconds' % (time.time() - currentTime)); |
|---|
| 460 | | messages.insert('end', '... finished.\n'); |
|---|
| 461 | | |
|---|
| 462 | | datapath = datap; |
|---|
| 463 | | sgfpath = dbpath; |
|---|
| 464 | | algos = algos; // FIXME (algos, algos; auch namelist) |
|---|
| 465 | | namelist = [split(x[:-1], '|%') for x in namelist[2:]]; |
|---|
| 466 | | disabled = 0; |
|---|
| 467 | | current = array('L', range(len(namelist)-2)); |
|---|
| 468 | | results = []; |
|---|
| 469 | | } |
|---|
| | 438 | catch IOError |
|---|
| | 439 | XXX messages.insert('end', 'I/O Error: Could not write namelist.db file.\n'); |
|---|
| | 440 | |
|---|
| | 441 | // if (progBar) { |
|---|
| | 442 | // progBar.redraw(1); |
|---|
| | 443 | // progBar.write('%1.1f seconds' % (time.time() - currentTime)); |
|---|
| | 444 | // } |
|---|
| | 445 | |
|---|
| | 446 | XXX messages.insert('end', '%1.1f seconds' % (time.time() - currentTime)); |
|---|
| | 447 | XXX messages.insert('end', '... finished.\n'); |
|---|
| | 448 | |
|---|
| | 449 | datapath = datap; |
|---|
| | 450 | sgfpath = dbpath; |
|---|
| | 451 | algos = Algos; |
|---|
| | 452 | XXX namelist = [split(x[:-1], '|%') for x in Namelist[2:]]; |
|---|
| | 453 | disabled = 0; |
|---|
| | 454 | XXX current = array('L', range(len(namelist)-2)); |
|---|
| | 455 | results = []; |
|---|
| | 456 | } |
|---|