Regexp-N_Queens
view release on metacpan or search on metacpan
lib/Regexp/N_Queens.pm view on Meta::CPAN
package Regexp::N_Queens;
use 5.028;
use strict;
use warnings;
no warnings 'syntax';
use experimental 'signatures';
use experimental 'lexical_subs';
use Hash::Util::FieldHash qw [fieldhash];
use lib qw [lib];
our $VERSION = '2023021701';
fieldhash my %size;
fieldhash my %pattern;
fieldhash my %subject;
my $queen = "Q";
my $prefix = "Q";
my $sep = ";";
my sub init_size;
my sub init_subject_and_pattern;
my sub name;
my sub all_groups;
my sub attacks;
################################################################################
#
# sub new ($class)
#
# Create a new, uninitialized object.
#
# IN: $class: Package name
#
# OUT: Blessed object, uninitialized object
#
################################################################################
sub new ($class) {bless \do {my $v => $class}}
################################################################################
#
# sub init ($self, @args)
#
# Initialize the object.
#
# IN: $self: Uninitialized object.
# @args: Set of named parameters used to initialized the object.
# We accept the following options:
# - size => N: The size of the chess board (number of rows/columns)
# If no size parameter is given, the board will
# be assumed to have size 8, like a standard
# chess board.
#
# As a special feature, the set of named parameter may also
# be passed in as a hashref.
#
# OUT: Initialized object.
#
################################################################################
sub init ($self, @args) {
my $args = @args == 1 && ref $args [0] eq "HASH" ? $args [0] : {@args};
init_size ($self, $args);
if (keys %$args) {
die "Unknown parameter(s) to init: " . join (", " => keys %$args)
. "\n";
}
$self;
}
################################################################################
#
# my sub init_size ($self, $args)
#
# Initialize the size of the board. This subroutine is called from init ().
# This is subroutine is lexical, and cannot be called from the outside.
#
# IN: $self: Current object
# $args: Hashref with parameters. Used (and then deleted) parameters:
# - size => N: The size of the chess board (number of rows/columns)
#
# OUT: Current object
#
################################################################################
sub init_size ($self, $args) {
$size {$self} = delete $$args {size} || 8;
$self;
}
################################################################################
#
( run in 1.647 second using v1.01-cache-2.11-cpan-ceb78f64989 )