<commit_before><?php
/**
 * Rolls dices, according to standard AD&D format:
 *
 * nDd([+/-]m)
 *
 * where
 * n - is the number of dices to roll
 * d - is the number of dots on each dice
 * m - modifier
 * and optional modifier as a signed integer
 *
 * Example:
 * 2D6+2 (roll 2 six sided dices and add 2 to the result)
 */

namespace cd;

require_once('RandomNumber.php');

class WrongFormatException extends \Exception { }

class DiceDnD
{
    var $numberOfDices = 0;
    var $numberOfDots  = 0;
    var $adjustment    = 0;

    function __construct($cmd)
    {
        $pos = stripos($cmd, 'D');
        if ($pos === false)
            throw new WrongFormatException();

        $this->numberOfDices = intval(substr($cmd, 0, $pos));

        $s = substr($cmd, $pos+1);

        $pos = strpos($s, '+');
        if ($pos === false)
            $pos = strpos($s, '-');

        if ($pos === false) {
            $this->numberOfDots = $s;
            return;
        }

        $this->numberOfDots = intval(substr($s, 0, $pos));
        $this->adjustment   = intval(substr($s, $pos));
    }

    function roll()
    {
        $result = 0;

        for ($i = 0; $i < $this->numberOfDices; $i++)
            $result += (RandomNumber::get() % $this->numberOfDots) + 1;

        return $result + $this->adjustment;
    }

    function min()
    {
        return $this->numberOfDices + $this->adjustment;
    }

    function max()
    {
        return ($this->numberOfDices * $this->numberOfDots) + $this->adjustment;
    }

}
<commit_msg>simplify logic by dropping "return"<commit_after><?php
/**
 * Rolls dices, according to standard AD&D format:
 *
 * nDd([+/-]m)
 *
 * where
 * n - is the number of dices to roll
 * d - is the number of dots on each dice
 * m - modifier
 * and optional modifier as a signed integer
 *
 * Example:
 * 2D6+2 (roll 2 six sided dices and add 2 to the result)
 */

namespace cd;

require_once('RandomNumber.php');

class WrongFormatException extends \Exception { }

class DiceDnD
{
    var $numberOfDices = 0;
    var $numberOfDots  = 0;
    var $adjustment    = 0;

    function __construct($cmd)
    {
        $pos = stripos($cmd, 'D');
        if ($pos === false)
            throw new WrongFormatException();

        $this->numberOfDices = intval(substr($cmd, 0, $pos));

        $s = substr($cmd, $pos+1);

        $pos = strpos($s, '+');
        if ($pos === false)
            $pos = strpos($s, '-');

        if ($pos === false) {
            $this->numberOfDots = intval($s);
        } else {
            $this->numberOfDots = intval(substr($s, 0, $pos));
            $this->adjustment   = intval(substr($s, $pos));
        }
    }

    function roll()
    {
        $result = 0;

        for ($i = 0; $i < $this->numberOfDices; $i++)
            $result += (RandomNumber::get() % $this->numberOfDots) + 1;

        return $result + $this->adjustment;
    }

    function min()
    {
        return $this->numberOfDices + $this->adjustment;
    }

    function max()
    {
        return ($this->numberOfDices * $this->numberOfDots) + $this->adjustment;
    }

}

{'fraction_non_alphanumeric': 0.15838709677419355, 'fraction_numerical': 0.00903225806451613, 'mean_word_length': 2.1514227642276422, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1055099', 'n_tokens_mistral': 1083, 'n_tokens_neox': 1024, 'n_words': 270}