2012/08/04

Forsyth-Edwards Notation

Chessの局面の表現として、Forsyth-Edwards Notation(FEN)という記法がある。これは、19世紀にDavid Forsythによって新聞でチェスの棋譜をコンパクトに記事にするために開発されたもので、コンピュータチェスでは、チェスを含むボードゲームの棋譜を保存するためのPortable Game Notation (PGN)で用いられたり、コンピュータチェスにおいてコンピュータ同士が通信するためのインタフェースであるUniversal Chess Interface (UCI)でも用いられている。

実際のFENは、例えば次のようなものである。

r1bqkbnr/ppp2ppp/2np4/8/2P1P3/4Q3/PP3PPP/RNB1KBNR b KQkq c3 0 5

最初のブロックが駒の配置を表している。/で区切られた文字列が盤面の上(8行目)から順に各行を表している。各行は左(A列)からのコマの配置を表し、数字は連続する空マスの数である。つまり、上の文字列は次の盤面を表している。

r.bqkbnr
ppp..ppp
..np....
........
..P.P...
....Q...
PP...PPP
RNB.KBNR

次のブロックは、次の手が白(w)の番か、黒(b)の番かを表している。

3つ目のブロックは、キャスリングが可能かどうかを表している、KQkqはそれぞれ白のKingサイド、白のQueenサイド、黒のKingサイド、黒のQueenサイドを表す。いずれのキャスリングも不可能なときは、- となる。

4つ目のブロックは少し面白くて、アンパッサンのターゲットとなるマスを表している。つまり、このマスに駒があるとしたらとれるポーンがあるならばアンパッサンできるということを意味している。

5つ目のブロックは50手ルールに関するカウントで、最後にポーンが動くか、駒が取られるかしたあとで経過した手数を表す。

最後の6つ目のブロックは最初からの手数を表している。

このFENを実装したことで盤面の状態を文字列で表せるようになった。これを利用して、すべての駒のすべての配置からの可能な移動と、あるゲームの経過の中での可能な手とある手を打った後での盤面を確認するテストコードを生成した。ユニットテストというよりもレグレッションテストに近いですが、早速、キャスリングの実装にバグを発見した。テスト重要。

テストフレームワークはgoogletest http://code.google.com/p/googletest/ を使い、一部を抜粋すると次のようなコードになっている。これはレグレッションテストの方で5000行程度、駒の動きの方が18000行程度あり、コード本体の10倍以上のコードでテストしていることになっている。

あれ、コードのフォーマットが壊れているな。後で直しておきます。

1 件のコメント:

  1. Jacks or Better video poker games are recognized to offer variety of the} best progressive jackpots out there, but you solely stand a chance of profitable should you use the best technique. There are a number of} web sites have the ability to|you probably can} visit to play video poker on-line to apply. Fortunately, video poker can be performed near-optimally with a a lot less complicated technique, and it won’t cost you a lot in RTP. Newer gamers are beneficial begin out|to begin} with these simplified strategies and construct from there. You can find these strategies 소울카지노 round the} web, but here are are|listed beneath are} a number of} example hands from the main games available at Ignition, showing the kind of technique selections you’ll be making. To full this hand, want to|you must} have the Ten, Jack, Queen, King and Ace of the identical suit with|swimsuit}, in exactly that order from left to proper.

    返信削除