NNGS围棋服务器如何挂GNUGO程序 作者: YKL 在IGS、NNGS等围棋站点上有机器人对弈程序可以与人类对手对弈。 这个机器人对弈程序就是gnugo。目前它的棋力约有18k*~16k*。棋力 虽然低了点,但正好适合围棋新手练兵,而且机器人永远在线,也可以 略微提升一下网站的人气:)。所以,在你的nngs服务器上挂几个gnugo 机器人也是个不错的选择。 往nngs服务器上挂载gnugo机器人的过程并不复杂,下面是具体的操作步骤: 1.先备齐原料的说:)。 在nngs服务器上挂载gnugo机器人需要三个软件: gungo3.2(1965KB),人机对弈程序,这个当然是必需的了:),可以从 http://ftp.gnu.org/gnu/gnugo或http://www.flygo.net站点下载。 gnugoclient-2.0(24.8KB),把gnugo挂载到围棋服务器上去的软件, 可以从http://www.lysator.liu.se/~gunnar/gnugo/gnugoclient站点下载。 pike-7.2.239(4.0MB),gnugoclient-2.0的运行需要pike语言的支持, 可以从http://pike.ida.liu.se/download站点下载。 2.首先安装gnugo3.2: tar xvzf gnugo-3.2.tar.gz cd gnugo-3.2 ./configure --prefix=$install directory your want --enable-cache-size=16 --enable-level=1 make make install ./configure的--prefix参数说明了你要把软件装在哪一个路径下, 如果你不加--prefix参数,软件默认会安装在/usr/local目录下。 --enable-cache-size参数说明了你打算给gnugo分配多少内存供它使用, 如果你不加这个参数,默认值是8M。大内存能使它跑的更快,但是设的 太大以至于频繁使用硬盘缓冲区的话反而不好,这个就要看你的机器的 具体情况了。--enable-level参数设置了gnugo的难度等级,可在1~10 之间选择,数字越大,棋力越高,但是运行越慢,如果你不加这个参数, 默认值是10。你可以阅读一下gnugo的readme和install文件,那里面有 一些更详细的解释。 现在gnugo3.2已经安装完毕,你可以运行以下命令测试一下你的gnugo: cd $install directory your want/bin ./gnugo 值得一提的是,运行gnugo时你还可以加--cache-size n和--level n 参数来临时指定分配给它多少内存以及它的难度等级。例如,这一次我想 分配给它24M内存以及让它以难度等级5运行,我可以运行如下命令: ./gnugo --cache-size 24 --level 5 3.安装pike-7.2.239: tar xvzf pike-7.2.239.tar.gz cd Pike-v7.2.239 <注:注意大小写> ./configure --prefix=$install directory your want make make install 安装的过程比较慢,耐心等待就是了:)。 你可以阅读一下pike的readme文件,那里面有一些更详细的解释。 4.解开gnugoclient-2.0.tar.gz压缩包: tar xvzf gnugoclient-2.0.tar.gz 解完后进入gnugoclient-2.0目录,打开Config.h文件,该文件里记录了 要挂载的围棋服务器的信息,内容如下: mapping(string:mapping(string:string|int)) servers = ([ "pgs" : ([ "address" : "stanly.lysator.liu.se", "port" : 9697, "protocol" : "pgs", "name" : "PGS" ]), "nngs" : ([ "address" : "nngs.cosmic.org", "port" : 9696, "protocol" : "nngs", "name" : "NNGS" ]) ]); string sgf_copyright_statement = ""; 现在需要把我们自己的围棋服务器信息加进去: mapping(string:mapping(string:string|int)) servers = ([ "sky" : ([ "address" : "10.1.0.131", "port" : 9696, "protocol" : "nngs", "name" : "skyserver" ]), "nngs" : ([ "address" : "nngs.cosmic.org", "port" : 9696, "protocol" : "nngs", "name" : "NNGS" ]) ]); string sgf_copyright_statement = ""; 我的围棋服务器的"address"是10.1.0.131,"port"是9696,"protocol" 当然填nngs了,"name"可以随便取:)。这一系列信息用前面的字符串 "sky"代表,"sky"以后还要用到。 再打开GnugoConfig.h文件,该文件里记录了默认以什么用户名挂载gnugo, 内容如下: // Default names to be used at different servers. mapping (string:string) default_names = ([ "pgs" : "testrobot", "nngs" : "GnuGo" ]); // Passwords for the names at different servsers. mapping(string:mapping(string:string)) passwords = ([ "pgs" : ([ "testrobot" : "" ]), "nngs" : ([ "GnuGo" : "xxxxxx" ]) ]); // Base path to the log directory. Game records will be saved in a // subdirectory to this directory named after the server. The log file // will go there as well. string savebasepath = "/tmp/gnugo/"; string logfilename = "log"; // People we don't want to play against. array(string) black_list = ({ }); // Set this to "automatic" if the program is trusted to remove dead // stones itself, "opponent" if it relies on the opponent to remove // all dead stones, or "manual" if the operator is supposed to take // active part in the scoring. string default_stone_removal_policy = "automatic"; 假设我们已经注册了一个用户名为myrobot、密码为myrobot的用户, 我们打算把它作为挂载gnugo的默认用户,现在把这个帐户的信息加进去: // Default names to be used at different servers. mapping (string:string) default_names = ([ "sky" : "myrobot", "nngs" : "GnuGo" ]); // Passwords for the names at different servsers. mapping(string:mapping(string:string)) passwords = ([ "sky" : ([ " myrobot " : "myrobot" ]), "nngs" : ([ "GnuGo" : "xxxxxx" ]) ]); // Base path to the log directory. Game records will be saved in a // subdirectory to this directory named after the server. The log file // will go there as well. string savebasepath = "/tmp/gnugo/"; string logfilename = "log"; // People we don't want to play against. array(string) black_list = ({ }); // Set this to "automatic" if the program is trusted to remove dead // stones itself, "opponent" if it relies on the opponent to remove // all dead stones, or "manual" if the operator is supposed to take // active part in the scoring. string default_stone_removal_policy = "automatic"; 注意两个mapping语句里的服务器名一定要和Config.h文件里定义的代表服务器 信息的字符串一样,在这个例子里就是"sky"。 GnugoConfig.h文件最后一行定义了终局时由谁拿掉盘上的死子,"automatic" 是由gnugo自己判断,"opponent"是由对手来拿,而"manual"就需要管理员干预了。 再打开Gnugo.pike文件,该文件的第一行记录了pike可执行文件的全路径,原文如下: #!/usr/bin/env pike 我们需要把它改成我们自己的路径信息(假设我的pike位于/sky/pike/bin目录下): #!/sky/pike/bin/pike 我们已经做好了所有的准备工作,现在进入Gnugo.pike文件所在的目录,执行 下面的命令(假设我的gnugo可执行文件位于/sky/go/bin目录下): ./Gnugo.pike sky /sky/go/bin/gnugo <注:注意大小写> 第一个参数一定要和Config.h和GnugoConfig.h文件里的代表服务器的字符串 一样(在这个例子里就是"sky"),第二个参数是你的gnugo可执行文件的 全路径。现在gnugo已经以你在GnugoConfig.h文件里定义的默认用户名挂载 到围棋服务器上了! 输入命令时你还可以加上用户名和密码,以取代GnugoConfig.h文件定义的 默认用户,例如: ./Gnugo.pike sky /sky/go/bin/gnugo newbie newb 此时gnugo就以用户名newbie挂载到了围棋服务器上(newb是用户newbie的密码)。 如果你想挂载多个gnugo机器人也是很容易的事。你可以多次执行./Gnugo.pike 命令来挂载多个gnugo机器人(这些机器人的用户名得不同哦);你还可以安装 多个level不同的gnugo,然后挂载它们,这样你就拥有了不同棋力的机器人:)。 最后说一句,你可以阅读一下gnugoclient的readme文件,那里面有一些更详细 的解释。 欢迎与我联系cccp401@sohu.com。