⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 解剖大象的眼睛——中国象棋程序设计探索(七):开局库.htm

📁 象棋程序设计全资料集(介绍编写象棋程序的方法思路)
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0052)http://www.elephantbase.net/computer/eleeye_book.htm -->
<HTML><HEAD><TITLE>解剖大象的眼睛——中国象棋程序设计探索(七):开局库</TITLE>
<META http-equiv=Content-Type content="text/html; charset=gb_2312-80">
<META content="MSHTML 6.00.3790.536" name=GENERATOR></HEAD>
<BODY background=解剖大象的眼睛——中国象棋程序设计探索(七):开局库_files/background.gif>
<DL>
  <DIV align=center>
  <CENTER>
  <DT><FONT face=隶书 size=6>解剖大象的眼睛</FONT><FONT 
  size=6><STRONG>——</STRONG></FONT><FONT face=隶书 size=6>中国象棋程序设计探索</FONT> 
  </CENTER></DT></DIV>
  <DIV align=center>
  <CENTER>
  <DT>  </CENTER></DT></DIV>
  <DIV align=center>
  <CENTER>
  <DT>黄晨 <FONT face="Times New Roman">*</FONT> <FONT 
  face="Times New Roman">2005</FONT>年<FONT 
  face="Times New Roman">6</FONT>月初稿,<FONT 
  face="Times New Roman">2005</FONT>年<FONT face="Times New Roman">11</FONT>月修订 
  </CENTER></DT></DIV>
  <DIV align=center>
  <CENTER>
  <DT><FONT face="Times New Roman">( * </FONT>联系地址:复旦大学化学系表面化学实验室,<FONT 
  face="Times New Roman">eMail</FONT>:<A 
  href="mailto:webmaster@elephantbase.net"><FONT 
  face="Times New Roman">webmaster@elephantbase.net</FONT></A><FONT 
  face="Times New Roman">)</FONT> </CENTER></DT></DIV>
  <DT>  
  <DT><FONT face=Arial size=5><STRONG>(</STRONG></FONT><FONT face=楷体_GB2312 
  size=5><STRONG>七</STRONG></FONT><FONT face=Arial size=5><STRONG>) 
  </STRONG></FONT><FONT face=楷体_GB2312 size=5><STRONG>开局库</STRONG></FONT> 
  <DT>  
  <DT>  在阅读本章前,建议读者先阅读《<A href="http://www.elephantbase.net/" 
  target=_blank>象棋百科全书</A>》网站中《<A 
  href="http://www.elephantbase.net/computer/outline.htm" 
  target=_blank>对弈程序基本技术</A>》专题的以下几篇译文: 
  <DT>  <FONT face="Times New Roman">(1) </FONT><A 
  href="http://www.elephantbase.net/computer/advanced_aspiration.htm" 
  target=_blank>其他策略——开局库</A><FONT face="Times New Roman">(Martin Fierz)</FONT>。 

  <DT>  
  <DT><FONT face=Arial size=4><STRONG>7.1 </STRONG></FONT><FONT face=楷体_GB2312 
  size=4><STRONG>象棋程序对开局库的处理</STRONG></FONT> 
  <DT>  
  <DT>  开局库是象棋程序中知识含量最多的部分,各种程序的棋力会因为开局库的不同而有所差距。互联网上介绍国际象棋开局库的文章很多,而中国象棋开局库的原理和国际象棋是完全一样的,因此笔者就不作太多的介绍了。 

  <DT>  很多国际象棋的程序中,开局库并不被引擎处理,而是由界面来完成的,棋局进入中局脱离棋谱后,才让引擎作搜索。<FONT 
  face="Times New Roman">ChessBase</FONT>的系列软件<FONT 
  face="Times New Roman">Junior</FONT>和<FONT 
  face="Times New Roman">Fritz</FONT>,以及支持<FONT 
  face="Times New Roman">UCI</FONT>协议的<FONT 
  face="Times New Roman">Shredder</FONT>,都使用这种工作方式,由于它们使用同一套<FONT 
  face="Times New Roman">ChessBase</FONT>的界面,因此开局库格式是统一的。由于<FONT 
  face="Times New Roman">WinBoard</FONT>本身并不能处理开局库,因此支持<FONT 
  face="Times New Roman">WinBoard</FONT>的引擎都具有处理开局库的能力,而且每个引擎都有各自的开局库格式。 
  <DT>  而中国象棋目前没有统一的界面,因此也没有统一的开局库格式。<FONT 
  face="Times New Roman">ElephantEye</FONT>的开局库具有非常明显的特点——它是文本格式的,每一行记录一个着法,依次是着法<FONT 
  face="Times New Roman">(</FONT>红色部分<FONT 
  face="Times New Roman">)</FONT>、权重<FONT 
  face="Times New Roman">(</FONT>绿色部分<FONT 
  face="Times New Roman">)</FONT>和局面<FONT 
  face="Times New Roman">(</FONT>紫色部分<FONT face="Times New Roman">)</FONT>: 
  <DD>  
  <DD><FONT color=#ff0000>b2e2</FONT> <FONT color=#008000>5895</FONT> <FONT 
  color=#800080>rnbakabnr/9/1c5c1/p1p1p1p1p/9/9/P1P1P1P1P/1C5C1/9/RNBAKABNR w - 
  - 0 1</FONT> 
  <DT>  
  <DT>  由于记录局面时使用<FONT 
  face="Times New Roman">FEN</FONT>串,这就增加了开局库的可读性,但同时使开局库变得特别庞大,<FONT 
  face="Times New Roman">ElephantEye</FONT>的开局库<FONT 
  face="Times New Roman">(BOOK.DAT)</FONT>仅有<FONT 
  face="Times New Roman">20,000</FONT>多个着法却达到了<FONT 
  face="Times New Roman">1.6M</FONT>。 
  <DT>  开局库的类型大致分为树型和局面型,<FONT 
  face="Times New Roman">ElephantEye</FONT>的开局库显然属于后者。对于局面型的开局库来说,把它导入置换表是最合适的,<FONT 
  face="Times New Roman">ElephantEye</FONT>的置换表标志除了<FONT 
  face="Times New Roman">HASH_ALPHA</FONT>、<FONT 
  face="Times New Roman">HASH_PV</FONT>、<FONT 
  face="Times New Roman">HASH_BETA</FONT>外,还专门为开局库局面增设<FONT 
  face="Times New Roman">BOOK_UNIQUE(</FONT>局面只有一个开局库着法<FONT 
  face="Times New Roman">)</FONT>和<FONT 
  face="Times New Roman">BOOK_MULTI(</FONT>局面有多个开局库着法<FONT 
  face="Times New Roman">)</FONT>两项。开局库中大多数局面只有唯一着法,因此着法直接存入置换表项的最佳着法区域内,而多个着法则需要另设一个专门的数据结构来保存各种着法及其权重。 

  <DT>  <FONT face="Times New Roman">ElephantEye</FONT>处理开局库的代码在<FONT 
  face="Times New Roman">&lt;hashbook.cpp&gt;</FONT>中,<FONT 
  face="Times New Roman">LoadBook()</FONT>函数用来导入开局库,<FONT 
  face="Times New Roman">GetBookMove()</FONT>函数用来读取开局库。如果局面没有在置换表中找到,那么程序将进行搜索,搜索的时候会把置换表中的开局库局面覆盖掉。因此,当棋局重新开始时,开局库要重新导入。 

  <DT>  
  <DT><FONT face=Arial size=4><STRONG>7.2 </STRONG></FONT><FONT face=楷体_GB2312 
  size=4><STRONG>开局库的制作</STRONG></FONT> 
  <DT>  
  <DT>  <FONT 
  face="Times New Roman">ElephantEye</FONT>现有的开局库是从《象棋百科全书》网站上收录的<FONT 
  face="Times New Roman">8000</FONT>多局对局中整理出来的,这些对局涵盖了<FONT 
  face="Times New Roman">1990</FONT>年到<FONT 
  face="Times New Roman">2004</FONT>年的全国顶级象棋比赛<FONT 
  face="Times New Roman">(</FONT>团体赛、个人赛、甲级联赛和五羊杯<FONT 
  face="Times New Roman">)</FONT>,因此具有代表性。由于笔者没有为<FONT 
  face="Times New Roman">ElephantEye</FONT>写开局库制作程序,因此开局库的制作是在数据库管理软件的帮助下手工完成的<FONT 
  face="Times New Roman">(</FONT>笔者使用的是<FONT 
  face="Times New Roman">FoxPro)</FONT>,现在简要介绍一下开局库的制作流程。 
  <DT>  <FONT face="Times New Roman">(1) </FONT>编写一个<FONT 
  face="Times New Roman">PGN2FEN</FONT>程序<FONT 
  face="Times New Roman">(</FONT>能把<FONT 
  face="Times New Roman">PGN</FONT>文件的每个出现的局面转换成<FONT 
  face="Times New Roman">FEN</FONT>串、后续着法和胜负信息,并对每个局面作一份翻转棋盘的拷贝<FONT 
  face="Times New Roman">)</FONT>,对《象棋百科全书》网站上收录的<FONT 
  face="Times New Roman">8000</FONT>多个<FONT 
  face="Times New Roman">PGN</FONT>文件转换为一个<FONT 
  face="Times New Roman">FEN</FONT>列表文件; 
  <DT>  <FONT face="Times New Roman">(2) </FONT>把<FONT 
  face="Times New Roman">FEN</FONT>列表文件转换为数据库,数据库包括<FONT 
  face="Times New Roman">FEN</FONT>串、着法、胜局数、和棋局数、负局数这几个域<FONT 
  face="Times New Roman">(</FONT>根据胜负情况,对胜局数、和棋局数或负局数置<FONT 
  face="Times New Roman">1)</FONT>; 
  <DT>  <FONT face="Times New Roman">(3) </FONT>按照“<FONT 
  face="Times New Roman">FEN</FONT>串<FONT 
  face="Times New Roman">+</FONT>着法”为索引合并重复记录,对胜局数、和棋局数、负局数分别合计; 
  <DT>  <FONT face="Times New Roman">(4) </FONT>增加权重这个域,按照笔者观点,权重 <FONT 
  face="Times New Roman">= </FONT>胜局数 <FONT face="Times New Roman">x 3 + 
  </FONT>和棋局数 <FONT face=Symbol>-</FONT><FONT face="Times New Roman"> 
  </FONT>负局数; 
  <DT>  <FONT face="Times New Roman">(5) </FONT>过滤掉权重小于<FONT 
  face="Times New Roman">4</FONT>的着法<FONT 
  face="Times New Roman">(</FONT>即收入开局库的着法至少是一胜一和的<FONT 
  face="Times New Roman">)</FONT>; 
  <DT>  <FONT face="Times New Roman">(6) </FONT>按照着法、权重和<FONT 
  face="Times New Roman">FEN</FONT>串的顺序,按权重排序导出为开局库文件<FONT 
  face="Times New Roman">(BOOK.DAT)</FONT>。 
  <DT>  
  <DT>  这个流程使得<FONT face="Times New Roman">ElephantEye</FONT>现有的开局库存在很多问题,主要有: 
  <DT>  <FONT face="Times New Roman">(1) </FONT>用文本格式太浪费空间,用<FONT 
  face="Times New Roman">Zobrist</FONT>键值取代<FONT 
  face="Times New Roman">FEN</FONT>串,并采用二进制格式记录,那么每个着法只需要<FONT 
  face="Times New Roman">12</FONT>个字节<FONT 
  face="Times New Roman">(Zobrist</FONT>键值<FONT 
  face="Times New Roman">4</FONT>字节,<FONT 
  face="Times New Roman">Zobrist</FONT>锁<FONT 
  face="Times New Roman">4</FONT>字节,着法<FONT 
  face="Times New Roman">2</FONT>字节,权重<FONT 
  face="Times New Roman">2</FONT>字节<FONT 
  face="Times New Roman">)</FONT>,这样就可以节省大量空间; 
  <DT>  <FONT face="Times New Roman">(2) </FONT>仅由<FONT 
  face="Times New Roman">8000</FONT>多局对局整理出的开局库是远远不够的,顶尖象棋软件的开局库一般是从<FONT 
  face="Times New Roman">100,000</FONT>局以上的对局中整理出来的,这些对局大都是高水平的网络对局; 
  <DT>  <FONT face="Times New Roman">(3) </FONT>需要一个开局库制作程序,权重可以根据自己的需要来设定<FONT 
  face="Times New Roman">(</FONT>笔者的权重计算方法并不一定合理<FONT 
  face="Times New Roman">)</FONT>,读者有兴趣的话,可以在数据库平台上自己设计这样的开局库制作程序; 
  <DT>  <FONT face="Times New Roman">(4) </FONT>开局库中存在一些可能导致长将的着法,笔者已经发现<FONT 
  face="Times New Roman">ElephantEye</FONT>在开局库阶段就走出长将的不合理着法了,这些着法应该被过滤掉。 
</DT></DL>
<DIR>
<LI>上一篇 <A 
href="http://www.elephantbase.net/computer/eleeye_parallel.htm">中国象棋程序设计探索<FONT 
face="Times New Roman">(</FONT>六<FONT 
face="Times New Roman">)</FONT>:并行搜索技术探索</A> 
<LI>下一篇 <A 
href="http://www.elephantbase.net/computer/eleeye_ponder.htm">中国象棋程序设计探索<FONT 
face="Times New Roman">(</FONT>八<FONT 
face="Times New Roman">)</FONT>:后台思考和时间策略</A> 
<LI>返 回 <A href="http://www.elephantbase.net/computer.htm">象棋百科全书——电脑象棋</A> 
</LI></DIR>
<DIV align=center>
<CENTER>
<TABLE border=0>
  <TBODY>
  <TR>
    <TD>
      <P align=center><A href="http://www.elephantbase.net/" target=_blank><IMG 
      height=31 src="解剖大象的眼睛——中国象棋程序设计探索(七):开局库_files/elephantbase.gif" width=88 
      border=0></A></P></TD></TR>
  <TR>
    <TD><A href="http://www.elephantbase.net/" target=_blank><FONT face=Arial 
      size=2><STRONG>www.elephantbase.net</STRONG></FONT></A></TD></TR></TBODY></TABLE></CENTER></DIV></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -