Games-Goban-0.01 > Games::Goban
Games-Goban-0.01

名前

Games::Goban - Board for playing go, renju, othello, etc.

Games::Goban - 碁、連珠、オセロ、その他で遊ぶための盤面

概要

  use Games::Goban;
  my $board = new Games::Goban (
                size => 19,
                game => "go",
                white => "Seigen, Go",
                black => "Minoru, Kitani",
                referee => \&Games::Goban::Rules::Go,
  );                       # 訳注:上記の関数はこのパッケージに含まれていない

  $board->play("pd"); $board->play("dd"); # 訳注:play というメソッドはない
  print $board->as_sgf;                   #       move の間違い

説明

This is a generic module for handling goban-based board games. Theoretically, it can be used to handle many of the other games which can use Smart Game Format (SGF) but I want to keep it reasonably restricted in order to keep it simple.

これは碁盤を使うボードゲームを操作する汎用モジュールである。 理論的にはSmart Game Format(SGF)以外のゲームも数多く操作できるのだが、 シンプルにしておくために、合理的な制限をかけておきたいと思う。

メソッド

new(%options);

Creates and initializes a new goban. The options and their legal values (* marks defaults):

新しい碁盤を作成し初期化する。オプションとその適切な値(*がデフォルト):

    size       9, 11, 13, 15, 17, *19           # 盤面のサイズ
    game       *go, othello, renju, gomoku      # 競技の種類
    white      任意のテキスト,  *: "Miss White" # 白
    black      任意のテキスト,  *: "Mr Black"   # 黒
    referee    任意のサブルーチン, *: sub {1}   # 審判(どんな手も正当)

The referee subroutine takes a board object and a piece object, and determines whether or not the move is legal. It also reports if the game is won.

審判(referee)サブルーチンは盤面オブジェクトと駒オブジェクト[訳注:実際は 盤面の位置を表す2文字]を引数に取り、その手が合法か違法かを判定する。 また、勝敗の報告を行う。

move

    $ok = $board->move($position)

Takes a move, creates a Games::Goban::Piece object, and attempts to place it on the board, subject to the constraints of the referee. If this is not successful, it returns 0 and sets $@ to be an error message explaining why the move could not be made. If successful, updates the board, updates the move number and the turn, and returns true.

一手すすめてGames::Goban::Pieceオブジェクトを生成し、refereeサブルーチンの 制約に従って盤面に駒を置こうと試みる。その手が成功しなかったらメソッドは0を 返し、$@になぜ移動できなかったを説明するエラーメッセージをセットする。 手が成功したら盤面を更新し、手数と手番を更新して真値を返す。

[訳注:このメソッドが返すのは白駒か黒駒かを表す文字('w'か'b')。]

get

    $move = $board->get($position)

Gets the Games::Goban::Piece object at the given location, if there is one. Locations are specified as per SGF - a 19x19 board starts from aa in the top left corner, with tt in the bottom right. i does not exist.

指定した位置に駒があればGames::Goban::Pieceオブジェクトを得る。 位置はSGF(Smart Game Format)に基づいて指定する。例えば19x19盤は 左上隅がaaで右下がttiは存在しない。

[訳注:iは存在していて、19x19の場合、aa〜ssまでのようです…]

size

    $size = $board->size

Returns the size of the goban.

碁盤のサイズを返す。

as_sgf

    $sgf = $board->as_sgf;

Returns a representation of the board as an SGF (Smart Game Format) file.

盤面をSGF(Smart Game Format)ファイル形式で返す。

as_text

    print $board->as_text(coords => 1)

Returns a printable text picture of the board, similar to that printed by gnugo. Black pieces are represented by X, white pieces by O, and the latest move is bracketed. hoshi points are in their normal position for Go, and printed as an +. Coordinates are not printed by default, but can be enabled as suggested in the synopsis.

プリント可能なように、盤面をテキスト絵にして返す。これはgnugoが印刷する ものに似ている。黒駒はX、白駒はOで表され、最新の手は括弧が付く。 は碁に対応した通常の位置にあり、+で表される。デフォルトでは座標は 出力されないが、上の使用方法で示したようにやれば可能だ。

register

    my $key = $board->register(\&callback);

Register a calllback to be called after every move is made. This is useful for analysis programs which wish to maintain statistics on the board state. The key returned from this can be fed to...

全手終了の後に呼び出されるコールバックルーチンを登録する。これは盤面状態の 統計を管理する分析用プログラムを使う際に便利だ。このメソッドが返すkeyは 次のように利用される…

notes

    $board->notes($key)->{score} += 5;

notes returns a hash reference which can be used by a callback to store local state about the board.

notesは盤面の局所的状態を保持するためにコールバックルーチンが利用できる ハッシュリファレンスを返す。

hash

    $hash = $board->hash

Provides a unique hash of the board position. If the phrase "positional superko" means anything to you, you want to use this method. If not, move along, nothing to see here.

盤面の配置を表す一意なハッシュを返す。"positional superko"というフレーズが あなたにとって意味があるなら、このメソッドを使いたいだろう。そうでないなら、 ここにみるべきものはない、先に進んで欲しい。

[訳注:super ko については http://home.snafu.de/jasiek/superko.html を参照]

Games::Goban::Piece メソッド

Here are the methods which can be called on a Games::Goban::Piece object, representing a piece on the board.

ここでは、盤上の駒を表すGames::Goban::Pieceオブジェクトから呼び出す メソッドについて触れる。

color

Returns "b" for a black piece and "w" for a white. colour is also provided for Anglophones.

黒駒なら"b"を、白駒なら"w"を返す。英式発音用にcolourも用意されている。

notes

Similar to the notes method on the board class, this provides a private area for callbacks to scribble on.

盤面クラスメソッドのnotesと同じで、殴り書きするためのコールバックルーチン用 にプライベートなエリアを提供する[訳注:スクラッチパッドの提供]。

position

Returns the position of this piece, as a two-character string. Incidentally, try to avoid taking references to Piece objects, since this stops them being destroyed in a timely fashion. Use a position and get if you can get away with it, or take a weak reference if you're worried about the piece going away or being replaced by another one in that position.

この駒の位置を2文字で返す。ちなみに、Pieceオブジェクトへのリファレンスを とるのは避けたほうがいい。なぜなら、適切なときにオブジェクトが破壊されるのを 妨げるからだ。オブジェクトが欲しいなら、positiongetを使うこと。 あるいは駒が去ったり、別の駒に置き換えられるのが心配であるなら、 弱いリファレンス(weak reference)を使うこと。

move

Returns the move number on which this piece was played.

この駒の手数を返す。

board

Returns the board object whence this piece came.

この駒がいる盤面オブジェクトを返す。

参考

Smart Game Format: http://www.red-bean.com/sgf/

Games::Go::SGF

The US Go Association: http://www.usgo.org/

作者

Simon Cozens, simon@cpan.org