Location : Home > Languages > Perl > Package Title : Algorithm::Metric::Chessboard |
![]() |
Algorithm::Metric::Chessboard - 正方格子上での距離(チェス盤距離)をオプションでワームホールの存在を認めて計算
チェス盤上の2点間を、縦・横・対角線に1つずつしか移動できないという条件下での最短距離を計算する。 何も条件を課さない場合には点 (x1, y1) から点 (x2, y2) までの距離は
d( (x1, y1), (x2, y2) ) = max( abs( x1 - x2 ), abs( y1 - y2) )
となる。
しかし空間にワームホール(wormholes)を認めると実際の距離は短くなる。ただしワームホールを使った移動には固定のペナルティを課すものとする。
my @wormholes = ( Algorithm::Metric::Chessboard::Wormhole->new( x => 5, y => 30 ), Algorithm::Metric::Chessboard::Wormhole->new( x => 98, y => 99 ), ); my $grid = Algorithm::Metric::Chessboard->new( x_range => [ 0, 99 ], y_range => [ 0, 99 ], wormholes => \@wormholes, wormhole_cost => 3, ); my $wormhole = $grid->nearest_wormhole( x => 26, y => 53 ); my $journey = $grid->shortest_journey(start => [1, 6], end => [80, 1]);
new
wormholes はオプションである。wormhole_cost のデフォルト値は 0 である。
nearest_wormhole
Algorithm::Metric::Chessboard::Wormhole オブジェクトを返す。
shortest_journey
Algorithm::Metric::Chessboard::Journey オブジェクトを返す。
Kake Pugh, <kake@earth.li>
Copyright (C) 2004 Kake Pugh. All Rights Reserved.
本モジュールはフリーソフトウェアであり、Perl 本体と同等の条件で修正/再配布してよい。
Jon Chin は名前を見つけ出すのを助けてくれたし、Andy Armstrong と Mike Stevens は問題の記述を明確にしてくれた。
なぜこのモジュールを書いたかについては:
【訳注と解説】
![]() |
Updated : 2006/09/25 |