NAME
Game::Backgammon::Terminal - the game at a prompt
SYNOPSIS
use Game::Backgammon::Terminal;
Game::Backgammon::Terminal->new(mode => 'bot', level => 3)->run;
DESCRIPTION
All of this distribution's input and output lives here and in bin/backgammon. Nothing below this file reads or writes anything, which is what makes the engine reusable; t/09-no-io.t proves it by playing a whole game with STDOUT tied to something that dies on write.
in and out are attributes rather than bare handles, so a test can play a game through this class without a terminal. A UI that only a human can drive is a UI that rots without anybody noticing.
The board
+13-14-15-16-17-18-+---+19-20-21-22-23-24-+---+
| O X | | X O | | Black 167 pips
| O X | | X O | |
| O X | | X | |
| O | | X | |
| O | | X | |
| |BAR| |OFF|
| X | | O | |
| X | | O | |
| X O | | O | |
| X O | | O X | |
| X O | | O X | | White 167 pips
+12-11-10--9--8--7-+---+-6--5--4--3--2--1-+---+
A real board: the twelve points of each half between their borders, the bar down the middle and the tray on the right. Checkers hang down from the top border and stand up from the bottom one; a point taller than five shows its count in the last place. Round checkers unless "ascii" is set, and colour only when the session is interactive and NO_COLOR is unset.
It is drawn from the numbering of whoever is on roll, so the board in front of a player is the one their own moves are written in: their home board is the bottom right quarter and they run anticlockwise into it. That is why the numbers change sides between turns, and "view" pins them to one side for anybody who would rather they did not. Your own checkers on the bar are drawn in the top of the middle column, where you re-enter, and your tray at the bottom right beside your home board.
The pip counts are beside the side they belong to: the one number in the game nobody can read off the board itself.
ATTRIBUTES
game, in, out, mode, level, seat
mode is bot, hotseat or watch.
view
white, black, or empty for whoever is on roll.
ascii
O and X instead of the round checkers.
colour, interactive
Both default from in: colour when it is a terminal and NO_COLOR is unset, and the screen is only cleared between turns for a person, so a captured transcript stays readable.
METHODS
render($view)
The board as one string.
board_lines($view)
The board as an arrayref of lines, without their newlines.
offer_lines($turns)
The legal turns, numbered, laid out across the width of the board. Doubles from the bar can offer thirty of them, and a list that long pushes the board it belongs to off the top of the screen.
clear
Clears the screen, but only for a person.
step
Play one turn. Returns true while the game is still on.
run
Play until the game ends or the player stops. Returns the Game::Backgammon::Result, or undef if it was stopped.
say_to(@what)
Write a line to out.