src/GameOfLife/Rules/BaseRule.php
/**
     * Calculate the new cell state of $_field.
     *
     * @param Field $_field Field for which the new cell state will be calculated
     *
     * @return bool New cell state
     */
Calculate the new cell state of $_field.
@param Field $_field Field for which the new cell state will be calculated

@return bool New cell state
Calculate the new cell state of $_field . @param Field $_field Field for which the new cell state will be calculated @return bool New cell state
public function calculateNewState(Field $_field): bool
    {
        $amountLivingNeighbors = $_field->numberOfLivingNeighbors();
        if ($this->isAntiRule) $amountLivingNeighbors += $_field->numberOfNeighborBorderFields();
        if ($_field->isAlive())
        {
            foreach ($this->rulesStayAlive as $amountStayAlive)
            {
                if ($amountLivingNeighbors == $amountStayAlive) return true;
            }
            return false;
        }
        else
        {
            foreach ($this->rulesBirth as $amountBirth)
            {
                if ($amountLivingNeighbors == $amountBirth) return true;
            }
        }
        return $_field->value();
    }
public function calculateNewState ( Field $ _field ) : bool { $ amountLivingNeighbors = $ _field -> numberOfLivingNeighbors ( ) ; if ( $ this -> isAntiRule ) $ amountLivingNeighbors += $ _field -> numberOfNeighborBorderFields ( ) ; if ( $ _field -> isAlive ( ) ) { foreach ( $ this -> rulesStayAlive as $ amountStayAlive ) { if ( $ amountLivingNeighbors == $ amountStayAlive ) return true ; } return false ; } else { foreach ( $ this -> rulesBirth as $ amountBirth ) { if ( $ amountLivingNeighbors == $ amountBirth ) return true ; } } return $ _field -> value ( ) ; }
Calculate the new cell state of $_field.
Calculate the new cell state of $_field .
// Return same field value if the cell neither dies nor rebirths