simple_craps 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 477780779912390b4745b8c4aa37aecc356bf454
4
+ data.tar.gz: 27e4996a3a3d92a9c8d18e0066ebf5c87c8a79fc
5
+ SHA512:
6
+ metadata.gz: 5e7de20fd2c3e7e12945931a88d28783b53a4cb0c9dfa8fe4890217dac49ffe79f8ec0a2b3d763811f5982bd0cffa572cade5cbfaa6ad690f3d15d76f41d0b24
7
+ data.tar.gz: 16657adbe34269542030cd0d2bf94892fd7f9a2f3550942b7a309101c17599cb28fc9ee0713cbe53d56811eaa46e49cb838a979a9ef9a5527d1871e6aecb3d39
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.2
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in simple_craps.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Chris Vannoy
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,39 @@
1
+ # SimpleCraps
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/simple_craps`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'simple_craps'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install simple_craps
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ 1. Fork it ( https://github.com/[my-github-username]/simple_craps/fork )
36
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
37
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
38
+ 4. Push to the branch (`git push origin my-new-feature`)
39
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "simple_craps"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/craps ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'simple_craps'
4
+
5
+ SimpleCraps::GamePlay.play
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,12 @@
1
+ require "simple_craps/version"
2
+ require "simple_craps/dice"
3
+ require "simple_craps/loaded_dice"
4
+ require "simple_craps/simple_craps"
5
+
6
+ module SimpleCraps
7
+ class GamePlay
8
+ def self.play
9
+ SimpleCrapsGame.play
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,16 @@
1
+ class Dice
2
+ attr_accessor :sides
3
+
4
+ def initialize(sides=6)
5
+ @sides = sides
6
+ end
7
+
8
+ def roll
9
+ (1..sides).to_a.sample
10
+ end
11
+
12
+ def is_loaded?
13
+ false
14
+ end
15
+
16
+ end
@@ -0,0 +1,12 @@
1
+ class LoadedDice < Dice
2
+
3
+ def roll
4
+ original = (1..sides).to_a
5
+ loaded = original + original.each_slice((sides/2).to_i).to_a[1]
6
+ loaded.sample
7
+ end
8
+
9
+ def is_it_really_loaded?
10
+ true
11
+ end
12
+ end
@@ -0,0 +1,97 @@
1
+ class SimpleCrapsGame
2
+
3
+ def self.get_dice(num=2)
4
+ # num.times.collect{|_num| [Dice, LoadedDice].sample.new}
5
+ num.times.collect{|_num| Dice.new}
6
+ end
7
+
8
+ def self.statistics
9
+ unless defined?(@@statistics)
10
+ @@statistics = {wins: [], losses: []}
11
+ end
12
+ @@statistics
13
+ end
14
+
15
+ def self.run_stats
16
+ bulk_play
17
+ puts "You won #{statistics[:wins].length} times."
18
+ puts "The house won #{statistics[:losses].length} times."
19
+ end
20
+
21
+ def self.play
22
+ die = Dice.new
23
+ puts "Welcome to our table. Take your first roll (any key)."
24
+ $stdin.gets
25
+ value1 = 0
26
+ value2 = 0
27
+ first_total = 0
28
+ first_time = true
29
+ until winning_time?(first_total, value1, value2, first_time) || losing_time?(first_total, value1, value2, first_time)
30
+ value1, value2 = die.roll, die.roll
31
+ if first_time
32
+ first_total = value1 + value2
33
+ end
34
+ if losing_time?(first_total, value1, value2, first_time)
35
+ puts "You lost. (You rolled a #{to_emoji(value1)} #{to_emoji(value2)})"
36
+ puts "Where's my money?!?!?!"
37
+ exit
38
+ end
39
+ if winning_time?(first_total, value1, value2, first_time)
40
+ puts "You rolled a #{to_emoji(value1)} #{to_emoji(value2)}!"
41
+ puts "🎉 🎉, 🐔 🍲"
42
+ exit
43
+ end
44
+ puts "You rolled a #{to_emoji(value1)} #{to_emoji(value2)}. Roll again."
45
+ if first_time
46
+ value1 = 0
47
+ value2 = 0
48
+ first_time = false
49
+ end
50
+ $stdin.gets
51
+ end
52
+
53
+ end
54
+
55
+ # Wikipedia: A come-out roll of 7 or 11 is a "natural", and the Pass line wins.
56
+ # Wikipedia: If the shooter "hits" the point value again (any value of the
57
+ # dice that sum to the point will do; the shooter doesn't have to exactly
58
+ # repeat the value combination of the come-out roll) before rolling a seven,
59
+ # the Pass line wins
60
+ def self.winning_time?(first_total, value1, value2, first_run=false)
61
+ if first_run
62
+ [7, 11].include?([value1, value2].inject(0){|sum, x| sum + x})
63
+ else
64
+ first_total == value1 + value2
65
+ end
66
+ end
67
+
68
+ # Wikipedia: A come-out roll of 2, 3 or 12 is called "craps" or
69
+ # "crapping out", and anyone betting the Pass line loses.
70
+ # Wikipedia: If the shooter rolls any seven before repeating the point
71
+ # number (a "seven-out"), the Pass line loses.
72
+ def self.losing_time?(first_total, value1, value2, first_run=false)
73
+ if first_run
74
+ value1 + value2 == 2 || value1 + value2 == 12 || value1 + value2 == 3
75
+ else
76
+ value1 + value2 == 7
77
+ end
78
+ end
79
+
80
+ def self.to_emoji(value)
81
+ case value
82
+ when 1
83
+ "⚀"
84
+ when 2
85
+ "⚁"
86
+ when 3
87
+ "⚂"
88
+ when 4
89
+ "⚃"
90
+ when 5
91
+ "⚄"
92
+ when 6
93
+ "⚅"
94
+ end
95
+ end
96
+
97
+ end
@@ -0,0 +1,3 @@
1
+ module SimpleCraps
2
+ VERSION = "0.1.3"
3
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'simple_craps/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "simple_craps"
8
+ spec.version = SimpleCraps::VERSION
9
+ spec.authors = ["Chris Vannoy"]
10
+ spec.email = ["chris.vannoy@theironyard.com"]
11
+
12
+ spec.summary = %q{Play craps on your command line.}
13
+ spec.description = %q{Brought to you by the Indianapolis June 2015 Ruby Cohort of The Iron Yard.}
14
+ spec.homepage = ""
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = ["craps"]
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_craps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.3
5
+ platform: ruby
6
+ authors:
7
+ - Chris Vannoy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Brought to you by the Indianapolis June 2015 Ruby Cohort of The Iron
42
+ Yard.
43
+ email:
44
+ - chris.vannoy@theironyard.com
45
+ executables:
46
+ - craps
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - ".travis.yml"
52
+ - CODE_OF_CONDUCT.md
53
+ - Gemfile
54
+ - LICENSE.txt
55
+ - README.md
56
+ - Rakefile
57
+ - bin/console
58
+ - bin/craps
59
+ - bin/setup
60
+ - lib/simple_craps.rb
61
+ - lib/simple_craps/dice.rb
62
+ - lib/simple_craps/loaded_dice.rb
63
+ - lib/simple_craps/simple_craps.rb
64
+ - lib/simple_craps/version.rb
65
+ - simple_craps.gemspec
66
+ homepage: ''
67
+ licenses:
68
+ - MIT
69
+ metadata: {}
70
+ post_install_message:
71
+ rdoc_options: []
72
+ require_paths:
73
+ - lib
74
+ required_ruby_version: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ requirements: []
85
+ rubyforge_project:
86
+ rubygems_version: 2.4.5
87
+ signing_key:
88
+ specification_version: 4
89
+ summary: Play craps on your command line.
90
+ test_files: []