NAME

Game::Mahjong::Search - the three rungs of the bot, reading a view and nothing else

VERSION

Version 0.01

SYNOPSIS

my $view = Game::Mahjong::Search::view_of($rules, $seat);
my $move = Game::Mahjong::Search::best($view, 2);   # a member of $view->{legal}

DESCRIPTION

The view is all a rung may read

Its own hand, every pool, every exposed meld (another seat's concealed kong shows as a kong with no tiles), what is visible and how many of each kind remain, the wall count, the winds, the window, the legal moves. No field for another hand and none for the wall's order, so a rung cannot cheat by construction, and the tests hand the rungs written views.

The three rungs, each the one below plus one idea

1  THE MOST ISOLATED TILE. Discard the tile with the fewest neighbours in
   hand, honours first, then terminals; pass every window; win when legal.

2  SHANTEN AND ACCEPTANCE. For every candidate discard the distance to
   ready after it; keep the minimum; among those, the most accepting tiles
   still to be had. Declare a kong that does not lengthen the road. Claim a
   pung or kong that shortens it when the pung scores by itself (a dragon,
   the prevalent or seat wind, a terminal), when the melds already floor
   eight, or when it makes the hand ready to win eight; claim a chow only
   when it makes the hand ready to win eight.

3  DEFENCE AND A TARGET. Against a seat with three melds exposed, while
   two or more from ready, discard a kind every copy of which is out or
   which that seat has discarded. Among equal discards prefer the one that
   keeps a flush, a pungs hand or scoring pairs in the making, and claim
   toward such a hand one step earlier.

%OFF switches an idea off by name (shanten, claims, defence, planning) so the ladder script can price it.

FUNCTIONS

view_of

The view of a Game::Mahjong::Rules for a seat.

best

my $move = best($view, $level, $word);

A member of the view's legal moves, or undef when there are none. $word breaks ties from the seed; the default hashes the view's seed, hand and move count.

SEE ALSO

Game::Mahjong::Bot, Game::Mahjong::Shanten

AUTHOR

LNATION <email@lnation.org>

LICENSE AND COPYRIGHT

This software is Copyright (c) 2026 by LNATION <email@lnation.org>.

This is free software, licensed under the Artistic License 2.0.