Coder Social home page Coder Social logo

dice_box's Introduction

DiceBox

Dice Box

Gem Version Dependency Status Build Status Test Coverage Code Climate Inline docs

A gem of dices, to get rolling with Ruby.

Supported Ruby versions:

  • MRI 2.2.0
  • MRI 2.1.5
  • MRI 2.1.0
  • MRI 2.0.0
  • MRI 1.9.3

Installation

Via RubyGems:

$ gem install dice_box

Or in a Gemfile:

gem 'dice_box'

Usage

Complete documentation available here.

  • DiceBox::Dice (rolling dices)

    # Roll a dice with 7 sides
    DiceBox::Dice.roll(7) # => 4
    
    # Roll 3 dices with 12 sides
    DiceBox::Dice.roll(12, 3) # => 27
    
    # Using an instance
    dice = DiceBox::Dice.new(12)
    dice.result # => nil
    dice.roll # => 24
    dice.result # => 24
  • DiceBox::Dice::Sides (cheating with sides weights)

    dice = DiceBox::Dice.new(3)
    dice.sides[0].weight = 0.0
    dice.sides[1].weight = 2.0
    
    dice.roll # => 2
    dice.roll # => 3
    dice.roll # => 2
    dice.roll # => 2
    dice.roll # => 2
  • DiceBox::Cup (rolling multiple dice instances)

    dices = [DiceBox::Dice.new(6), DiceBox::Dice.new(20), DiceBox::Dice.new(100)]
    cup = DiceBox::Cup.new(dices)
    
    cup.result # => nil
    cup.roll # => 103
    cup.result # => 103
    
    cup.dices[0].result # => 2
    cup.dices[1].result # => 19
    cup.dices[2].result # => 88

Versioning

DiceBox follows the principles of semantic versioning 2.0.0.

Given a version number MAJOR.MINOR.PATCH:

  • MAJOR is incremented when incompatible API changes are made
  • MINOR is incremented when functionalities are added in a backwards-compatible manner
  • PATCH is incremented when backwards-compatible bug fixes are made

Similar Libraries

License

Copyright ©️ 2014 Rafaël Gonzalez

Released under the terms of the MIT licence. See the LICENSE file for more details.

dice_box's People

Contributors

rafaelgonzalez avatar

Watchers

 avatar  avatar

dice_box's Issues

Implement probabilities for Dice

Add probability methods to DiceBox::Cup and DiceBox::Dice.

  • Dice#probabilities
  • Dice#probability(value)
  • Dice#probability_greater_than(value) (aka #probability_gt)
  • Dice#probability_greater_than_or_equal(value) (aka #probability_gte)
  • Dice#probability_lower_than(value) (aka #probability_lt)
  • Dice#probability_lower_than_or_equal(value) (aka #probability_lte)

Rewrite specs

Make more use of is_expected with let() to alter specs within contexts.

Rename Dice @rolled instance variable

Wrong variable name used in initialization. This does not cause a bug but should be addressed nonetheless.

class Dice
  def initialize(sides_number)
    @sides = build_sides(sides_number)
    @rolled_side = nil
    @rolled = nil # Rename to result
  end
end

Initialize Dice with given Side values

Allow to pass an Array of values to Dice#new. In the future this would allow to specify any type of Side#value (characters and strings)

For example:

class Dice
  def initialize(fixnum_or_array)
    if fixnum_or_array.is_a? Array
      # create as many Sides as fixnum_or_array.size and populate with the values
    elsif fixnum_or_array.is_a? Fixnum
      # do what's already being done
    else
      # throw an ArgumentError
    end
  end
end

Implement probabilities for Cup

  • Cup#probabilities
  • Cup#probability_equal_to(value)
  • Cup#probability_greater_than(value)
  • Cup#probability_greater_than_or_equal_to(value)
  • Cup#probability_lower_than(value)
  • Cup#probability_lower_than_or_equal_to(value)
  • Cup#probability_at_least(number, side_value)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.