' vbscript to translate history email file from yahoo games chess to a pgn file that can be read by a chess viewer ' 20070504 ' (c) 2007 Jan Nordgreen 'When you play chess on Yahoo Games you can email yourself the match recorded. Unfortunately it is not in pgn format. ' Here is a program that translates it into pgn format 'if you follow these guidelines carefully. ' * (1) Store the file from Yahoo Games with the moves only in C:\game.txt. An example file. ' * (2) Store the vbs program as C:\p2.vbs. ' * (3) Run the vbs program from the command prompt at C:\. Type cscript p2.vbs and press Enter. ' * (4) The pgn file is created as C:\game.pgn. ' * (5) You have to manually edit the file C:\game.pgn a little bit. Use Notepad or a similar text editor. ' (a) If there was a pawn promotion Yahoo Games does not indicate what the pawn promoted to. ' The program adds =Q by default so e.g. a7-a8 becomes a7-a8=Q. 'Replace =Q with =R, =N, =B if another piece was chosen. ' (b) The program puts the result at the end as 1-0 by default. Change that to 1/2-1/2 or 0-1 if needed. ' (c) Replace the default player information etc at the top. ' remember if the result (1-0 e.g.) has been written to the outputfile result = 0 'store where the pieces are on the board as a 64 character string ' start with a1 and move to the right and up board = "RNBQKBNR" board = board & string(8, "P") board = board & string(32," ") board = board & string(8, "P") board = board & "RNBQKBNR" ' read text file Set FileSystem = CreateObject("Scripting.FileSystemObject") folder = "c:\" ' note the slash should be at the end (c: will not work) Set outputfile = FileSystem.CreateTextFile(folder + "game.pgn", True) Set inputfile = FileSystem.OpenTextFile(folder + "game.txt", 1) outputfile.writeline "[Event ""EVENT""]" outputfile.writeline "[Site ""SITE""]" outputfile.writeline "[Date ""May 3 2007""]" outputfile.writeline "[White ""NAME1""]" outputfile.writeline "[Black ""NAME2""]" outputfile.writeline "[Result ""1-0""]" outputfile.writeline "[Round ""N""]" outputfile.WriteBlankLines(1) 'start loop counter = 0 Do Until inputfile.AtEndOfStream ' split line and replace any ++ with + dummy = Replace(inputfile.readline, "++", "+") myarray = split(dummy) for i = 1 to ubound(myarray) ' instead of using 2 I use this since White may make the last move if myarray(i) = "o-o" then myarray(i) = "0-0" if i = 1 then board = left(board, 5 - 1) & " " & mid(board, 5 + 1) ' remove king board = left(board, 8 - 1) & " " & mid(board, 8 + 1) ' remove rook board = left(board, 7 - 1) & "K" & mid(board, 7 + 1) ' position king board = left(board, 6 - 1) & "R" & mid(board, 6 + 1) ' position rook else board = left(board, 61 - 1) & " " & mid(board, 61 + 1) ' remove king board = left(board, 64 - 1) & " " & mid(board, 64 + 1) ' remove rook board = left(board, 63 - 1) & "K" & mid(board, 63 + 1) ' position king board = left(board, 62 - 1) & "R" & mid(board, 62 + 1) ' position rook end if elseif myarray(i) = "o-o-o" then myarray(i) = "0-0-0" if i = 1 then board = left(board, 5 - 1) & " " & mid(board, 5 + 1) ' remove king board = left(board, 1 - 1) & " " & mid(board, 1 + 1) ' remove rook board = left(board, 3 - 1) & "K" & mid(board, 3 + 1) ' position king board = left(board, 4 - 1) & "R" & mid(board, 4 + 1) ' position rook else board = left(board, 61 - 1) & " " & mid(board, 61 + 1) ' remove king board = left(board, 57 - 1) & " " & mid(board, 57 + 1) ' remove rook board = left(board, 59 - 1) & "K" & mid(board, 59 + 1) ' position king board = left(board, 60 - 1) & "R" & mid(board, 60 + 1) ' position rook end if else 'read startsquare startcolumn = Asc(left(myarray(i), 1)) - 96 ' a=1, b=2, ... startrow = CDbl(mid(myarray(i), 2, 1)) 'find out which piece is on startsquare 'e4 -> '54', 5 col 4 row, (4-1) x 8 + 5 - 1 = 28 th position in board position = (startrow - 1) * 8 + startcolumn piece = mid(board, position, 1) 'clear piece from startsquare board = left(board, position - 1) & " " & mid(board, position + 1) 'read endsquare endcolumn = Asc(mid(myarray(i), 4, 1)) - 96 ' a=1, b=2, ... endrow = CDbl(mid(myarray(i), 5, 1)) 'put piece on endsquare, if queening promote the pawn to queen by default ' I use replace in case the promoted piece gave check so the moved ends with "+" position = (endrow - 1) * 8 + endcolumn if instr(myarray(i), "1") > 0 and piece = "P" then board = left(board, position - 1) & "Q" & mid(board, position + 1) myarray(i) = replace(myarray(i),"1","1=Q") elseif instr(myarray(i), "8") > 0 and piece = "P" then board = left(board, position - 1) & "Q" & mid(board, position + 1) myarray(i) = replace(myarray(i),"8","8=Q") else board = left(board, position - 1) & piece & mid(board, position + 1) end if 'if RNBQK then add that letter to the move if instr("RNBQK", piece) > 0 then myarray(i) = piece & myarray(i) end if end if next ' write to outputfile dummy = "" for i = 0 to ubound(myarray) dummy = dummy & myarray(i) & " " next ' write the default result if White moved last if ubound(myarray) = 1 then dummy = dummy & " 1-0" result = -1 end if outputfile.writeline dummy counter = counter + 1 loop ' write the default result if Black moved last counter = counter + 1 if result <> -1 then outputfile.writeline counter & ". 1-0" end if 'say that we have finished wscript.echo "fin"