NAME
Game::Mahjong::Terminal - a game against three bots at the keyboard
VERSION
Version 0.01
SYNOPSIS
my $t = Game::Mahjong::Terminal->new(seed => 'evening', level => 2, seat => 0,
in => \*STDIN, out => \*STDOUT, colour => -t STDOUT);
$t->run;
mahjong --level 3 --glyphs # from the shell
DESCRIPTION
The table drawn every time it is your move: the hand and round, your wind, the wall, the totals, each seat's melds, flowers and discard pool in rows of six, and your hand numbered so a discard is a number. A window says who discarded what and lists what you may do; a win names every fan with its points and the settlement; the end of the game is the standings. The bots play in between and are narrated a line at a time.
Commands
<n> discard the tile numbered n
d 5m discard by name (E S W N R G B for the honours)
kong [5m] declare a kong
win declare your hand complete
pass, pung, kong, chow [n] answer a discard
hint what the strongest bot would do now
table, fans, help, quit
The tiles
A tile is drawn as a tile: a box three lines tall with a face two cells wide. Two cells is what makes a rack of fourteen lay out without measuring anything, because all three ways of writing a face are two cells: the notation's codes (5m, F1), an honour as its letter and a space, and a character from the Unicode Mahjong Tiles block, which is double width. A rack of fourteen with a space between the tiles is sixty-nine columns and fits an eighty column terminal.
Your own rack, your own sets and the tile somebody has just thrown are drawn as tiles, because those are what a decision is about. The pools and the other seats' sets are drawn as chips, [5m], because a pool of twenty as boxes is nine lines a seat and thirty-six for the table, and it is the record rather than the thing anybody is about to touch.
Glyphs, colour and the frame
glyphs puts the Unicode Mahjong Tiles block on the faces for a terminal that has the font. colour paints the face ivory with the suit's own ink, the character suit red, dots blue, bamboo green, and the three dragons their own names. ascii draws the frame with +, - and | for a terminal that cannot manage box drawing. clear clears the screen before each table, so the table is in one place and is read rather than scrolled to; it is on when standard output is a terminal.
ATTRIBUTES
seed
The game's seed; the same seed deals the same tiles.
level
The bots' level, 1 to 3.
seat
The person's seat, 0 to 3; seat 0 deals the first hand.
in
The filehandle commands are read from.
out
The filehandle the table is written to.
colour
ANSI colour when true.
glyphs
The Unicode Mahjong Tiles block instead of the notation when true.
ascii
Draw the tile frames with +, - and | rather than box drawing, for a terminal that cannot manage them.
clear
Clear the screen before each table. On when standard output is a terminal.
auto
Every seat played by a bot, no prompt: a game to watch. The table is drawn once a round rather than once a move, so a watched game reads as a game rather than as a log.
names
The four seats' names, the person's first.
rules
The game.
bots
The four bots.
hinter
The level-three bot the hint asks.
quit
Whether the person left.
METHODS
run
Plays until the game ends or the person quits; returns the rules object.
show_table, show_hand_end, show_game_end, narrate, help, show_fans
The pieces of the display, each writing to out.
read_move
Reads commands from in until one is a legal move.
face
One tile's face as exactly two cells: its notation code, an honour's letter and a space, or one double width character from the Unicode Mahjong Tiles block when glyphs is on.
tile_art
The three lines of one tile, framed. back draws it face down, which is what another seat's concealed kong is; mark emphasises it.
tile_row
A run of tiles side by side, as three lines. gaps names the positions that take an extra space before them, which is how the tile just drawn is set apart from the sorted hand.
tile_chip, tile_chips
The compact form, [5m], for the pools and for another seat's sets.
tile, tiles, name_of, say
Small helpers: a kind as text, kinds as text, a seat's name, a line out.
SEE ALSO
Game::Mahjong::Rules, Game::Mahjong::Bot
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.