Bonanza Version 4.0.4 bonanza_v4.0.3\src\bonanza\bonanza.txt 翻訳

少しずつ訳していきます。
正確ではないです。

                                                                                                                                          • -

Bonanza Version 4.0.4 Source Code
Kunihito Hoki, 2 Feb 2009

                                                                                                                                          • -


1. Introduction

                              • -

Bonanza is a state-of-the art computer shogi engine which runs on
Windows and Linux machines, and this directory contains a
platform-independent source code.

ボナンザは最先端のコンピューター将棋エンジンでWindowsLinuxそれぞれのプラットフォームで動きます。しかもソースコード付き!
このソースコードはコンピュータ将棋エンジンのパーツとして役に立つという望みを持って配布されます。

This source code is distributed with a hope that it will be useful in
addition to the main part of the shogi engine. This program includes
many useful functions such as manipulating a shogi board, reading and
writing a CSA record file, speaking of a CSA protocol with a socket
communication, and controlling time, and etc.. I believe this program
can be a good starting point if you are interested in making shogi
programs.

このプログラムは多くの有用な関数、将棋盤を操作したり、CSAファイルを読んだり書いたり、CSAのプロトコルで操作、時間制御・・・などなど含みます。私はこのプログラムがコンピューター将棋を作るよいスタート地点になることを信じています。

One main feature of this program is that it employs a brute-force
search method together with bitboard techniques as many chess programs
do. Another notable feature is a machine learning of shogi evaluation
functions. The details of the learning algorithm (aka Bonanza method)
were already presented [1], and this source code provides an example
of implementation of the learning method.

このプログラムのひとつの大きな特徴としてチェスのそれに用いられるビットボード技術を用いた総当たり探索があります。そのほかの特徴として機械学習関数があります。その学習アルゴリズムはすでに公開されており、さらにこのソースコードでも学習メソッドの実装の例を提供しています。

I admit that some parts of the source code are cryptic, e.g. codes in
"mate1ply.c". I hope that I will have some time to make a quality
documentation and comments on the program code, or someone else could
decrypt my program and provide a documentation.

私は、ソースコードのいくつかの部分が不可解であることを認めます。たとえば”mate1ply.c”。私にはプログラム・コードの品質文書とコメントをするいくらかの時間があるこ
とを願っているか、他の誰かが、私のプログラムを解読して、ドキュメンテーションを提供するかもしれません。

Any comments or suggestions are welcome [2].

どんなコメントや提案も歓迎します。

[1] K. Hoki, "Optimal control of minimax search results to learn
positional evaluation", Game Programing Workshop, Hakone, Japan
2008.

[2] Contact to "bonanza_query [at] hotmail.com".


2. Legal Notices

                                • -

This program is protected by copyright. Without a specific
permission, any means of commercial applications are prohibited.
Furthermore, this program is distributed without a warrantee.
Within these limits, you can use, redistribute, and/or modify it.

法律云々について

このプログラムは著作権によって保護されます。 特別に許可がなければ、アプリケーションとして売ることはできません。
また、このプログラムは被保証人なしで配布されます。
これらの制約の中でなら使用し、再配付、そして変更することができます。


3. Change Logs

                    • -

Version 4.0.4 (2 Feb 2009)

  • An error of GCC inline assembly for spinlock in "thread.c" is fixed.
  • In Windows OS, Bonanza now opens all streams with file sharing by

using "_SH_DENYNO" constant in "io.c".

  • GCC built-in functions are substituted for GCC inline assemblies for

bit-scan operations in "bitop.h". Furthermore, "bitop.h" is removed,
and some of macros in the header are integrated into "shogi.h".

GCCでスピンロックするエラーがあったのでthread.cを修正しました。
Windows OSでは、Bonanzaはファイル共有でSH_DENYNOを使用することによって、すべてのストリームを開きます。"io.c"では一定です。
・"bitop.h"でのビット・スキャン操作のためのGCCインラインアセンブリGCC
込み関数を代入します。 その上、"bitop.h"は移されます。そしてヘッダーのマクロのいくつかが"shogi.h"と統合されます。

Version 4.0.3 (Jan 2008)


4. Files

                • -

Here is a list of files you can find in this directory.

ここにあなたがこのディレクトリで見つけることができるファイルのリストがあります。

C headers

  • param.h piece values
  • shogi.h main header

C ヘッダーファイル

  • param.h 駒の価値
  • shogi.h メインヘッダー

basic C functions

  • main.c main function of C program
  • data.c definition of global variables
  • ini.c initializations
  • rand.c pseudo random number generator
  • time.c time functions
  • bitop.c bit operation
  • utility.c misc. functions

basic C functions

  • main.c C言語のメイン・・・mainです
  • data.c グローバル変数が定義されている
  • ini.c 初期設定
  • rand.c 疑似乱数ジェネレータ
  • time.c 時間関数
  • bitop.c ビット操作
  • utility.c ユーティリティ関数群

I/O

  • proce.c input procedure
  • csa.c csa file format I/O
  • io.c basic I/O
  • dek.c dekunobou
  • sckt.c TCP/IP client of CSA SHOGI protocol

I/O

  • proce.c インプット
  • csa.c csaのファイルフォーマットI/O
  • io.c ベーシック I/O
  • dek.c デクノボウ?
  • sckt.c CSAプロトコルTCP/IPクライアント

bitboard manipulations

  • attack.c piece attacks
  • genchk.c move generation (checks)
  • genevasn.c move generation (evasions)
  • gendrop.c move generation (drops)
  • gennocap.c move generation (non-captures)
  • gencap.c move generation (captures)
  • movgenex.c move generation (inferior moves)
  • makemove.c make moves
  • unmake.c unmake move
  • mate1ply.c 1-ply mate detection
  • debug.c examine bitboard validity

ビットボード 操作

  • attack.c 駒の利き
  • genchk.c 王手の生成
  • genevasn.c 王手回避の生成
  • gendrop.c 駒を打つ手生成
  • gennocap.c 駒を取らない手生成
  • gencap.c 駒を取る手生成
  • movgenex.c 下向きの動き生成
  • makemove.c 成り
  • unmake.c 成らず
  • mate1ply.c 1手詰め発見
  • debug.c ビットボードが正しいか調べる

brute-force search

  • iterate.c iterative deepning search at root node
  • searchr.c alpha-beta search at root node
  • search.c alpha-beta search
  • next.c obtains next move
  • quiesrch.c quiescence search
  • evaluate.c static eveluation function
  • evaldiff.c easy and fast evaluation function
  • swap.c static exchange evaluation
  • hash.c transposition table
  • thread.c thread-level parallelization
  • root.c root move genelation and shallow min-max search
  • mate3.c 3-ply mate detection
  • ponder.c pondering
  • book.c creates and probes opening book
  • problem.c auto problem solver
  • valid.c examine move validity

総当たり探索

  • iterate.c 反復探索(ルートノード)
  • searchr.c αβ探索(ルートノード)
  • search.c αβ探索
  • next.c 次に移るところをゲット
  • quiesrch.c 静的探索
  • evaluate.c 静的評価関数
  • evaldiff.c 簡単かつ高速な評価関数
  • swap.c SEE
  • hash.c ハッシュ化テーブル
  • thread.c スレッド並列化
  • root.c 根移動生成、浅い min-max探索
  • mate3.c 3手詰め発見
  • ponder.c 熟考
  • book.c 定石ファイルの使用
  • problem.c 自動問題解決
  • valid.c 合法手調査

optimal control of min-max search

  • learn1.c main functions
  • learn2.c feture vector manipuration

min-max 探索の最適化

  • learn1.c メイン関数
  • learn2.c ベクトル操作

misc.

その他

4. How to build Bonanza

                                            • -

You can build Bonanza by means of GNU Make on Linux or Microsoft NMAKE
on Windows. Here is some examples:

ボナンザはLinuxGNU Make でも WindowsのNMAKEでもビルドできます。下記が例です。

補足)bonanza_v4.0.3\src\bonanza\をカレントディレクトリとして下記を実行する必要がある。

> make -f Makefile gcc

> make -f Makefile icc

> nmake -f Makefile.vs cl

> nmake -f Makefile.vs icl

The C source codes are written by using ANSI C plus a small number of
new features in ISO C99. Therefore, I think this can be easily built
in many platforms without much effort.

これらC言語ソースコードANSI C ISO C99で書かれています。
従って多くのプラットフォームで苦労することなく容易にビルドできるでしょう。

It may be necessary to define some macros in Makefile or
Makefile.vs. The macros are:

いくつかのマクロをMakefileMakefile.vsで定義する必要があると思います。
そのマクロは・・・

  • NDEBUG (DEBUG) builds release (debug) version of Bonanza

ボナンザのリリースバージョン

  • MINIMUM disables some auxiliary functions that are not

necessary to play a game, e.g., book composition
and optimization of evaluation functions

  • TLP enables thread-level parallel search
  • MPV enables multi-PV search

protcol

  • DEKUNOBOU enables dekunobou interface (available only for

Windows)

  • CSASHOGI builds an engine for CSA Shogi (available only for

Windows)

  • NO_LOGGING suppresses dumping log files

Bonanza is an application that does not provide graphical user
interface. If you could build "bonanza.exe" properly without CSASHOGI
macro, it shows a prompt "Black 1>" when you execute it at a computer
console.

Bonanza uses three binary files: a feature vector of static evaluation
function "fv.bin", an opening book "book.bin", and a
position-learning database "hash.bin". You can find these in "winbin/"
directory. Without the NO_LOGGING option, Bonanza must find "log/"
directory to dump log files.


5. Command List

                            • -

These commands enable (on) or disable (off) a beep when Bonanza
makes a move. The default is on.

  • book on
  • book off

These commands enable (on) or disable (off) to probe the opening
book, "./book.bin". The default is on.

  • book narrow
  • book wide

When the command with "narrow" is used, Bonanza selects a book
move from a small set of opening moves. The default is "wide". The
narrowing of the opening moves is useful if you want Bonanza
choose a common opening line.

  • book create

This command creates the opening book file, "./book.bin", by using
numerous experts' games in a single CSA record file, "./book.csa".
It also uses another CSA record file, "book_anti.csa", where you
can register bad moves that may appear in the experts' games at
the last moves in the record file. Here is the example:

                                                                              • -

PI, +, +6978KI, %TORYO
/
PI, +, +6978KI, -8384FU, %TORYO
/
PI, +, +7776FU, -4132KI, %TORYO
/
PI, +, +7776FU, -4132KI, +2726FU, %TORYO

                                                                              • -

This command becomes effective when MINIMUM macro is not defined
in the Makefile.

  • connect 'addr' 'port' 'id' 'passwd' ['ngame']

This command connects Bonanza to a shogi server by using the CSA
protocol. The first four arguments specify the network address,
port number, user ID, and password, respectively. The last
argument limits a number of games that will be played by Bonanza.
This command becomes effective when CSA_LAN macro is defined in
the Makefile.

  • dekunobou 'addr' 'port-dekunobou' 'port-bonanza'

This command connects Bonanza to Dekunobou.

  • display ['num']

This command prints the shogi board. If you want to flip the
board, set 'num' to 2. If not, set it to 1.

  • s

Bonanza makes a prompt reply while thinking as soon as this
command is used.

  • hash 'num'

This command is used to initialize the transposition table and
set the size of the table to 2^'num'.

  • hash learn create

This command is used to make a zero-filled position-lerning
database, "hash.bin". This command becomes effective when MINIMUM
macro is not defined in the Makefile.

  • hash learn on
  • hash learn off

These commands enable (on) or disable (off) the position learning.
The default is on.

  • learn 'str' 'steps' ['games' ['iterations' ['num1' ['num2']]]]

This command optimizes a feature vector of the static evaluation
function by using numorous experts' games in a single CSA record
file, "./records.csa". If you want to use a zero-filled vector as
an initial guess of the optimization procedure, set 'str' to
"ini". If not, set it to "no-ini". The third argument 'games' is a
number of games to be read from the record file. If the third
argument is negative or omitted, all games are read from the file.

The learning method iterates a set of procedures, and the number
of iteration can be limited by the fourth argument. It continues
as long as the argument is negative. The procedures consist of two
parts. The first part reads the record file and creates principal
variations by using 'num1' threads. The default value of 'num1' is
1. The second part renews the feature vector 'steps' times by using
'num2' threads in accord with the principal variations. The default
value of 'steps' and 'num2' is 1. Note that each thread in the
second procedure uses about 500MByte of the main memory. The two
arguments 'num1' and 'num2' become effective when TLP macro is
defined in the Makefile. After the procedures, the optimized
vector is saved in "./fv.bin". This command become effective when
MINIMUM macro is not defined in the Makefile.

  • limit depth 'num'

This command is used to specify a depth, 'num', at which Bonanza
ends the iterative deepening search.

  • limit nodes 'num'

When this command is used, Bonanza stops thinking after searched
nodes reach to 'num'.

  • limit time 'minute' 'second' ['depth']

This command limits thinking time of Bonanza. It tries to make
each move by consuming the time 'minute'. When the time is spent
all, it makes each move in 'second'. The last argument 'depth' can
be used if you want Bonanza to stop thinking after the iterative
deepening searches reach sufficient depth.

  • limit time extendable
  • limit time strict

The command, "limit time extendable", allows Bonanza to think
longer than the time limited by the previous command if it wishes
to. The default is "strict".

  • move ['str']

Bonanza makes a move of 'str'. If the argument is omitted, Bonanza
thinks of its next move by itself.

  • mpv num 'nroot'
  • mpv width 'threshold'

These commands control the number of root moves, 'nroot', to
constitute principal variations. The default number is 1. A root
move that yields a smaller value than the best value by 'threshold'
is neglected. The default threshold is about 200. These commands
become effective when MPV macro is defined in the Makefile.

  • new ['str']

This command initializes the shogi board. The argument 'str'
controls an initial configuration of the board. If you want to
play a no-handicapped game, set 'str' to "PI" and this is the
default value. In a handicapped game, specify squares and pieces
to drop, e.g. "new PI82HI22KA" or "new PI19KY".

  • peek on
  • peek off

The command "peek on (off)" enables (disables) peeks at a buffer
of the standard input file while Bonanza is thinking. The default
is on. This command is useful when you want to process a set of
commands as "> ./bonanza.exe < infile".

Prompt Bonanza to print "pong".

  • ponder on
  • ponder off

The command "ponder on (off)" enables (disables) thinks on the
opponent's time. The default is on.

  • problem ['num']

This command is used to solve problems in "./problem.csa". Here
is an example of the problem file.

                                                        • -

$ANSWER:+0024FU
P1-KY-KE-OU-KI * * * * -KY
P2 * * * * * -KI * * *
P3 * * -FU-GI-FU * -KE * -KA
P4-FU * * -FU-GI-FU-HI * -FU
P5 * * * * * * * -FU+KY
P6+FU+KA+FU+FU+GI+FU+KI * *
P7 * +FU * * +FU * * * *
P8 * +OU+KI+GI * * +HI * *
P9+KY+KE * * * * * +KE *
P+00FU00FU
P-00FU00FU00FU
+
/
$ANSWER:+0087KY:+0088KY
P1-OU-KE * * * * * +GI *
P2-KY-KI * * * * * * *
P3-FU-HI * -KI * * -GI * *
P4 * * -KE * * * * * -FU
P5 * +GI * -FU-FU-FU-FU-FU *
P6+FU+HI-FU * * * * * *
P7 * * * +FU * * * * +FU
P8 * * +OU+KI+KI * * * *
P9+KY+KE * * * * * +KE+KY
P+00KA00GI00KY00FU00FU
P-00KA00FU00FU00FU00FU00FU
+

                                                        • -

The argument 'num' specifies the number of problems to solve.

  • quit

The quit command and EOF character will exit Bonanza.

  • read 'filename' [(t|nil) ['num']]

This command is used to read a CSA record 'filename' up to 'num'
moves. Set the second argument to "nil" when you want to ignore
time information in the record. The default value is "t". Bonanza
reads all move sequence if the last argument is neglected. If
'filename' is ".", the command reads an ongoing game from the
initial position.

  • resign

Use this command when you resign a game.

  • resign 'num'

This command specifies the threshold to resign. 'num' is a value
of the threshold. The default is around 1000.

  • stress on
  • stress off

When the command "stress on" is used, last-move shown in shogi
board is stressed. The default is on.

  • time remain 'num1' 'num2'

This command tells Bonanza the remaining time. 'num1' ('num2') is
the remaining time of black (white) in seconds.

  • time response 'num'

This command specifies a margin to control time. The time margin
saves Bonanza from time up due to TCP/IP communication to a server
program, sudden disc access, or imperfection of time control of
Bonanza. 'num' is the time margin in milli-second. The default
value is 200.

  • tlp 'num'

This command controls the number of threads to be created when
Bonana considers a move to make. The command becomes effective
when TLP macro is defined in the Makefile. 'num' is the number of
threads. The default value is 1.

  • #

A line beginning with # causes all characters on that line
to be ignored.

  • [move command]

A move command consists of four digits followed by two
capital alphabets, e.g. 7776FU. The first two digits
are a starting square and the last two are a target square. The
starting square is "OO" if the move is a dorp, e.g. 0087FU. The
following two alphabets specify a piece type as the following,

FU - pawn (Fuhyo) TO - promoted pawn (Tokin)
KY - lance (Kyousha) NY - promoted lance (Narikyo)
KE - knight (Keima) NK - promoted knight (Narikei)
GI - silver general (Ginsho) NG - promoted silver (Narigin)
KI - gold general (Kinsyo)
KA - Bishop (Kakugyo) UM - Dragon horse (Ryuma)
HI - Rook (Hisha) RY - Dragon king (Ryuo)
OU - King (Osho)

Here, words in parentheses are romanization of Japanese words.