The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

TITLE

game-life - Interactive wrapper for Game::Life::Faster

SYNOPSIS

 game-life -help
 game-life -version
 game-life
 life> place_points 0 0 .x ..x xxx
 life> process
 life> grid
 ..........
 X.X.......
 .XX.......
 .X........
 ..........
 ..........
 ..........
 ..........
 ..........
 ..........
 life> exit

OPTIONS

-autoclear

If this Boolean option is asserted, the screen is cleared before the grid is printed.

The default is -noautoclear.

-autoprint

If this Boolean option is asserted, the grid is printed after it is processed.

The default is -noautoprint.

-dead

 -dead +

This option specifies the character to be used for "dead" cells. If a letter is specified, uses of this letter on input will be case-blind.

The default is -dead ..

-faster

If this Boolean option is asserted, Game::Life::Faster is used; if not, Game::Life is used.

The default is -faster, but it can be negated using -nofaster.

-help

This option displays the documentation for this script. The script then exits.

-living

 -living *

This option specifies the character to be used for "living" cells. If a letter is specified, uses of this letter on input will be case-blind.

The default is -living X.

-profile

 -profile game-life.ini

This option specifies a profile file to read before prompting the user. The default depends on the operating system:

  • VMS: 'sys$login:game_life.ini'

  • Windows: "$ENV{USERPROFILE}/game_life.ini"

  • anything else: "$ENV{HOME}/.game-life.ini"

Note that any explicitly-specified file must exist, but the defaut file need not exist.

-size

 -size 20
 -size 10,12

This option specifies the size of the grid. It takes as its value either a single positive integer specifying a square grid of that size, or two comma-separated positive integers specifying a rectangular grid of that width and height.

The default is -size 10.

-version

This option displays the version of this script. The script then exits.

DETAILS

This Perl script provides an interactive interface to Game::Life::Faster, or optionally to Game::Life.

COMMANDS

The following commands are implemented:

autoclear

This command displays the -autoclear setting. If an argument is provided, the setting is changed to that value, which is interpreted as a Perl Boolean value, except for special-case values false, no, or off (case-insensitive), which are treated as false.

autoprint

This command displays the -autoprint setting. If an argument is provided, the setting is changed to that value, which is interpreted as a Perl Boolean value, except for special-case values false, no, or off (case-insensitive), which are treated as false.

clear_grid

This command clears the grid.

clear_point

 life> clear_point 1 1

This command clears the point at the given row and column. It is a synonym for unset_point.

clear_screen

This command clears the screen. It does nothing if standard out is not a terminal.

dead

This command displays the -dead setting. If an argument is provided, the setting is changed to the first character of that value.

dump

This command is unsupported, in the sense that the author reserves the right to change or revoke it without notice.

If arguments are specified, the first argument is the name of a Game::Life::Faster method, and the value dumped is the result of calling that method with the subsequent arguments.

If no arguments are specified, the internal representation of the grid is dumped.

The output is serialized using Data::Dump::dump() if that can be loaded, otherwise with Data::Dumper::Dumper().

exit

This command is the equivalent of end-of-file. If issued in a source file it terminates processing of that file. If issued from standard input or in response to a command prompt, this script exits.

grid

This command displays the grid. "Living" cells are represented by 'X', "dead" cells by '.'.

help

This command displays the same help provided by the -help option, but the script does not exit.

living

This command displays the -living setting. If an argument is provided, the setting is changed to the first character of that value.

load

 life> load game.life

This command clears the grid and then loads the given file into it. The file is expected to specify "living" points by 'X' or 'x'; any other character represents a "dead" cell. Line breaks delimit rows.

An optional second character can specify PerlIO layers, eg:

 life> load game.life :crlf:encoding(cp1252)

place_points

 life> place_points 0 0 .x ..x xxx

This command places points into the grid. The first two arguments are the row and column coordinates of the first point. Subsequent arguments are string representations of the points to be placed, with each argument representing consecutive cells in consecutive rows. "Living" cells are represented by 'X' or 'x'; any other character represents a "dead" cell.

The example places a glider in the top-left corner of the grid.

process

This command causes the game to be processed. An optional parameter specifies the number of iterations, the default being 1.

set_point

 life> set_point 1 2

This command causes the cell in the specified row and columns to be set "living."

source

 life> source life.source

This command opens the given file and reads commands from it.

unset_point

 life> unset_point 1 1

This command clears the point at the given row and column. It is a synonym for clear_point.

AUTHOR

Thomas R. Wyant, III wyant at cpan dot org

COPYRIGHT AND LICENSE

Copyright (C) 2019 by Thomas R. Wyant, III

This program is free software; you can redistribute it and/or modify it under the same terms as Perl 5.10.0. For more details, see the full text of the licenses in the directory LICENSES.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.