sub is_alive { my \$self = shift; return 0 + exists \$self->{Cells}->{ join ':', @_ }; } # Return the list of dead cells surrounding a cell sub get_dead_cells { my ( \$self, \$x, \$y ) = @_; ( (join ':', \$x - 1, \$y - 1) x !\$self->is_alive(\$x - 1, \$y - 1), (join ':', \$x - 1, \$y ) x !\$self->is_alive(\$x - 1, \$y ), (join ':', \$x - 1, \$y + 1) x !\$self->is_alive(\$x - 1, \$y + 1), (join ':', \$x , \$y - 1) x !\$self->is_alive(\$x , \$y - 1), (join ':', \$x , \$y + 1) x !\$self->is_alive(\$x , \$y + 1), (join ':', \$x + 1, \$y - 1) x !\$self->is_alive(\$x + 1, \$y - 1), (join ':', \$x + 1, \$y ) x !\$self->is_alive(\$x + 1, \$y ), (join ':', \$x + 1, \$y + 1) x !\$self->is_alive(\$x + 1, \$y + 1) ); } sub get_num_live { my ( \$self, \$x, \$y ) = @_; \$self->is_alive( \$x - 1, \$y - 1 ) + \$self->is_alive( \$x - 1, \$y ) + \$self->is_alive( \$x - 1, \$y + 1 ) + \$self->is_alive( \$x , \$y - 1 ) + \$self->is_alive( \$x , \$y + 1 ) + \$self->is_alive( \$x + 1, \$y - 1 ) + \$self->is_alive( \$x + 1, \$y ) + \$self->is_alive( \$x + 1, \$y + 1 ); }