The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Games::Go::Cinderblock::NodeSet

SYNOPSIS

 my $rulemap = Games::Go::Cinderblock::Rulemap::Rect->new
   ( h => 19, w => 19 );
 #initialize two empty nodesets
 my $ns1 = $rulemap->nodeset;
 my $ns2 = $ns1->copy;
 #add two opposite corners.
 $ns1->add([0,0], [18,18]);
 # add 4 nodes to $ns2, each adjacent to the 2 nodes in $ns1
 $ns2->add($ns1->adjacent);
 # let ns2 have the original 2 corners.
 $ns2->add($ns1);
 # split ns2 into its 2 connected subsets 
 my @foo = $ns2->disjoint_split;
 # compare equality
 my $false = $ns1 == $ns2;

DESCRIPTION

A set of nodes :|

NodeSets are typically initiated with $rulemap->nodeset(@nodes). NodeSets may be empty. Nodesets are independant of State, but heavily dependant on Rulemap.

insertion, lookup, removal of a single node is O(1). Nodesets are mutable, but union & intersect do not affect the invocant. Nodes are topology-implementation-dependent. In ::Rect instances, nodes are defined as a [$row,$col] array ref. In future instances, a node may be defined as a number, with an entry in an adjacency matrix.

Set operations unclude union, intersect, ==, count, add, remove, copy, has_node, disjoint_split

METHODS

count

Returns the number of nodes in the nodeset.

add

add & remove each may take either a nodeset or a list of nodes

remove

has_node

 $set->add([3,3])
 my $true = $set->has_node([3,3])
 $set->remove([3,3])
 my $false = $set->has_node([3,3])

copy

union

 my $result = $set1->union($set2)

Return the set of nodes in either the invocant or operand.

intersect

 my $result = $set1->intersect($set2)

Return the set of nodes in both invocant and operand.

==, !=

Compare two sets. Returns true or false.

adjacent

Returns a nodeset of nodes adjacent to the nodes of the invocant. The result excludes any nodes of the invocant.

disjoint_split

Return an arrayref of disconnected regions. Use this with Games::Go::Cinderblock::State's grep functionality to uncover distinct, disconnected regions of a particular attribute (color, etc.)