def test_decode_line_6(self): line = "1.d4 d5 2.c4 c6 3.Nf3 e6 4.e3 Nf6 5.Nc3 a6 6.c5 b6 7.cxb6 Nbd7 8.Bd2 a5 9.Rc1 Qxb6 10.Na4 Qc7 " + \ "11.Qc2 Bb7 12.Bd3 Be7 13.0-0 Ba6 14.Ne1 Bxd3 15.Nxd3 Rc8 16.Qc3 Bd8 17.f3 0-0 18.Be1 Qa7 19.Bg3 Be7 20.Rc2 Nb6 " + \ "21.Nxb6 Qxb6 22.Rfc1 Nd7 23.Qb3 Qa6 24.Rc3 a4 25.Qc2 Qb5 26.Ne5 Nxe5 27.Bxe5 Bb4 28.Rd3 Rfd8 29.a3 Bd6 30.Bxd6 Rxd6 31.b4 axb3 " + \ "32.Rxb3 Qa6 33.Qc5 Rdd8 34.Kf2 g6 35.Rb6 Qa4 36.Qb4 Ra8 37.Qxa4 Rxa4 38.Rc3 Rda8 39.Rbb3 Kg7 40.Ke2 h5 " + \ "41.Kd2 Kf6 42.Kc2 R4a6 43.Kb2 g5 44.Rb7 g4 45.f4 h4 46.Ka2 Rc8 47.Kb3 Rca8 48.Ka2 Rc8 49.Kb3 Rca8 50.Ka2 1/2" game = decode_game(line)
def parse(filename,proces_id): f = open(filename) gamenumber = 0 players_line = '' date_line = '' for lines in f: if gamenumber%10000 == 0: #print(gamenumber) pass if lines[0:2] == '1.': gamenumber += 1 try: print("Game {0}".format(gamenumber), file=sys.stderr) game = decode_game(lines) gamefile = open('gamebase/game_{0}_{1}'.format(proces_id,gamenumber),'w') gamefile.write('\n') for i in game: gamefile.write('\n'+str(i)) gamefile.close() except Exception as ex: print(players_line + date_line + "Game {0}: exception. {1}\n{2}".format(gamenumber, ex, lines)) elif lines.strip() and lines.strip()[-1] == ']': players_line = lines #print ("Players line: " + players_line + "," + lines) else: if not lines.strip(): continue last_word = lines.strip().split(' ')[-1] try: _ = datetime.strptime(last_word, DATE_FORMAT) date_line = lines except: pass f.close()
def test_decode_line_5(self): line = "1.e4 c6 2.d4 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4 cxd4 30.Rf4 Rb8 " + \ "31.Rxd4 Rxb3 32.Rxd6 Kf7 33.Rd7+ Kxf6 34.Rxh7 g5 35.Rh8 g4 36.Rf8+ Kg5 37.Rf4 Rb1+ 38.Rf1 Rb5 39.h4+" next = "39.h4+ gxh3 40.Kh2 Rf5 " + \ "41.Rxf5+ Kxf5 42.Kxh3 1/2" game_beginning = decode_game(line, raise_if_incomplete=False) board = board_after(game_beginning) print(board)
def _test_1( self ): # fake gameover because we don't predict side effects of e.p. and castling line = "1.e4 c5 2.Nf3 e6 3.d4 cxd4 4.Nxd4 Nf6 5.Nc3 d6 6.Bc4 Be7 7.Be3 0-0 8.Bb3 Na6 9.f3 Nc5 10.Qd2 a6 " + \ "11.0-0-0 Qc7 12.g4 b5 13.a3 Nxb3+ 14.Nxb3 Nd7 15.f4 Bb7 16.g5 Nc5 17.Nxc5 dxc5 18.Qd7 Rac8 19.Qxc7 Rxc7 20.Rhe1 b4 " + \ "21.Na4 bxa3 22.bxa3 Bxe4 23.Bxc5 Bxc2 24.Kxc2 Bxc5 25.Nxc5 Rxc5+ 26.Kd2 Ra5 27.Re3 Ra4 28.Rf1 g6 29.Ke2 Rb8 30.Kf3 Rb2 " + \ "31.Kg3 Ra2 32.Rff3 Rc4 33.Rb3 Rcc2 34.Rfd3 Rg2+ 35.Kf3 Rxh2 36.Rd8+ Kg7 37.Rbb8 Rxa3+ 38.Kg4 h5+ " next = "39.gxh6+ Rxh6 40.Rd7 Kf6 " + \ "41.Rbb7 Rh7 42.Rd6 Rah3 0-1" game_beginning = decode_game(line, raise_if_incomplete=False) board = board_after(game_beginning) print(board)
def test_decode_line_4(self): line = "1.e4 Nf6 2.e5 Nd5 3.d4 d6 4.c4 Nb6 5.exd6 exd6 6.Nc3 Be7 7.Be2 0-0 8.Nf3 Nc6 9.0-0 Bg4 10.b3 Bf6 " + \ "11.Be3 d5 12.c5 Nc8 13.b4 N8e7 14.h3 Bxf3 15.Bxf3 Nxb4 16.Rb1 Nbc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