新浪博客

国际象棋——联众棋谱转成pgn格式详细说明

2007-06-21 10:05阅读:
联众是国内网络上仅有的几个可下国际象棋的去处之一,虽说有系统经常出错、作弊无赖者甚众、界面亲和力差、时间不精确等诸多问题,但由于其中文界面,在国内网络在线游戏的影响,也吸引了一大批国际象棋爱好者,通常在线人数在三、四百人,当然和围棋、中国象棋、斗地主、麻将等动辄数万人没法比,谁让国际象棋是个“舶来品”呢?题外话,推荐www.playchess.com上下棋,不仅在线人数多,而且对弈着比较认真,系统有防作弊系统,时间比较精确,更重要的是棋谱格式就是chessbase系列软件所能打开的格式。英文界面简单易用,不难理解。另有众多好处不一一列举了。
在网上下了一段时间的棋后,不知不觉中就会积攒很多棋谱,如果不加以利用就非常可惜了。下面叙述把联众棋谱保存下来的详细过程
1、合并文件。联众棋谱缺省保存在C:\Program Files\GlobalLink\Game\intChess\目录中,一局棋有两个文件,*.int和*.txt,*.txt文本文件是我们需要的。注意需要在下棋时要设置保存棋谱,否则此目录是没有响应文件的。在命令行方式使用copy *.txt mychess.txt合并此目录下的所有文本文件,产生的mychess.txt就是我们要处理的棋谱文件了。
2、转换。我编写了一个宏,可以完成此功能。用word打开mychess.txt,方法右击文件,选择打开方式。在word中新建一个宏,把下面的内容拷入宏体。如图:
国际象棋——联众棋谱转成pgn格式详细说明
Selection.Find.ClearFormatting
Selecti
on.Find.Replacement.ClearFormatting
With Selection.Find
.Text = '国 际 象 棋 对 局 记 录*比赛日期:2007年'
.Replacement.Text = '[Event ''LianZhong'']^p[Date ''2007.'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll
With Selection.Find
.Text = '5月'
.Replacement.Text = '5.'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = '6月'
.Replacement.Text = '6.'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = '日*时 比赛地点:'
.Replacement.Text = ''']'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = '白 方:'
.Replacement.Text = '[White '''
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = '黑 方:'
.Replacement.Text = '[Black '''
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = ' 耗时:*秒'
.Replacement.Text = ''']'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = _
'比赛结果:白胜 裁判员:^p-------------------------------------------------'
.Replacement.Text = '[Result ''1-0'']'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = _
'比赛结果:黑胜 裁判员:^p-------------------------------------------------'
.Replacement.Text = '[Result ''0-1'']'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = _
'比赛结果:和棋 裁判员:^p-------------------------------------------------'
.Replacement.Text = '[Result '' 1/2-1/2 '']'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll

With Selection.Find
.Text = _
'比赛结果: 裁判员:^p-------------------------------------------------'
.Replacement.Text = '[Result ''?'']'
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll


注意:红色部分需要根据棋谱的年份日期进行修改。
保存宏以后,运行宏,若干时间后,棋谱内容就转换为pgn的格式了。
做完这些工作后,保存为txt文件。
3、修补。用记事本打开txt 文件,用替换功能,把所有的中文字符双引号“”替换成英文字符'。保存。
4、修改后缀名为*.pgn,双击,如果电脑安装过chessbase或其他国际象棋软件,就能打开棋谱文件。合并到chessbase数据库中非常简单,鼠标拖曳即可。
是不是非常简单?这样,你也可以拥有自己的对局库了,若干年以后,你可以轻松的调出以前所下的任一盘棋进行 “观摩”。

我的更多文章

下载客户端阅读体验更佳

APP专享