eighty_sixed 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ OGNkMGQwZjEzYTFmZDE2ZTEwYTgzMDJjMTY3YTJjMzU0OGJiYzEzMw==
5
+ data.tar.gz: !binary |-
6
+ ZjI3ZmVmMzg2ZjUxOGVmYWQ3ZDEzNjllNjY3NmRlNjIzNjFmYTgyMg==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YmI0NDZkZWMzNGJhYzBlNjhjOTJmNDRkN2VjZmQxNGI2MzJhNThiOTRiMjE0
10
+ NWVlZWFhMjM2Mzk4MjUxODA5NWYwMTI2ZTNkMTI4Y2I3MjdiYTc0NDhhZTdh
11
+ YjdlNTc3MmFkMzZhYmRlNGRkMTUxZjMyNmViMWI2MmYzYTVmZWM=
12
+ data.tar.gz: !binary |-
13
+ YzA1NWI3N2IxYTZhNTk1NWI4N2UyYjM3MGIxMjMyYjM3MmVkOTE5NTllMmJj
14
+ Njc0YzhiNWJhOGNhYjA4MzIxOGRkZjQ5MzgwYjBmMjc5YjEzNjY4YzA0YzQ0
15
+ MGZiM2E0NTIyMWRmNTU2MTBhZTMxMGQ5YjYzZTg5NDY1ZDZmYzY=
data/.gitignore ADDED
@@ -0,0 +1,52 @@
1
+ *.gem
2
+ *.rbc
3
+ <<<<<<< HEAD
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ =======
20
+ /.config
21
+ /coverage/
22
+ /InstalledFiles
23
+ /pkg/
24
+ /spec/reports/
25
+ /test/tmp/
26
+ /test/version_tmp/
27
+ /tmp/
28
+
29
+ ## Specific to RubyMotion:
30
+ .dat*
31
+ .repl_history
32
+ build/
33
+
34
+ ## Documentation cache and generated files:
35
+ /.yardoc/
36
+ /_yardoc/
37
+ /doc/
38
+ /rdoc/
39
+
40
+ ## Environment normalisation:
41
+ /.bundle/
42
+ /lib/bundler/man/
43
+
44
+ # for a library or gem, you might want to ignore these files since the code is
45
+ # intended to run in multiple environments; otherwise, check them in:
46
+ # Gemfile.lock
47
+ # .ruby-version
48
+ # .ruby-gemset
49
+
50
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
51
+ .rvmrc
52
+ >>>>>>> dbab889904dd0faba74b77a325fc661073940682
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in eighty_sixed.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Cristian Tountzis
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Cristian Tountzis
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,34 @@
1
+ <<<<<<< HEAD
2
+ # EightySixed
3
+
4
+ TODO: Write a gem description
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem 'eighty_sixed'
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install eighty_sixed
19
+
20
+ ## Usage
21
+
22
+ TODO: Write usage instructions here
23
+
24
+ ## Contributing
25
+
26
+ 1. Fork it ( http://github.com/<my-github-username>/eighty_sixed/fork )
27
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
28
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
29
+ 4. Push to the branch (`git push origin my-new-feature`)
30
+ 5. Create new Pull Request
31
+ =======
32
+ eighty_sixed
33
+ ============
34
+ >>>>>>> dbab889904dd0faba74b77a325fc661073940682
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'eighty_sixed'
4
+
5
+ if ARGV.length == 0
6
+ puts "Please pass an array of card values"
7
+ else
8
+ hand = EightySixed::Hand.new(argv_to_array)
9
+ puts hand.best_total
10
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'eighty_sixed/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "eighty_sixed"
8
+ spec.version = EightySixed::VERSION
9
+ spec.authors = ["Cristian Tountzis"]
10
+ spec.email = ["cristian@intriguos.com"]
11
+ spec.summary = %q{Calculates the best possible blackjack hand}
12
+ spec.description = %q{Calculates the best possible hand, don't use in the casino you may get 86'd}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,76 @@
1
+ require "eighty_sixed/version"
2
+
3
+ module EightySixed
4
+
5
+ class Hand
6
+
7
+ NON_NUMERICS = %w{ J K Q }
8
+
9
+ def initialize(cards)
10
+ @cards = cards
11
+ @total = nil
12
+ @aces = 0
13
+ end
14
+
15
+ def best_total
16
+ @total ||= calculate_total
17
+ end
18
+
19
+ private
20
+
21
+ def cards
22
+ @cards
23
+ end
24
+
25
+ def initialise_total
26
+ @total = 0
27
+ end
28
+
29
+ def total
30
+ @total
31
+ end
32
+
33
+ def aces
34
+ @aces
35
+ end
36
+
37
+ def add(value)
38
+ @total += value
39
+ end
40
+
41
+ def minus(value)
42
+ @total -= value
43
+ end
44
+
45
+ def increment_ace_count
46
+ @aces += 1
47
+ end
48
+
49
+ def calculate_total
50
+ initialise_total
51
+ add_values_for(@cards)
52
+ adjust_aces
53
+ total
54
+ end
55
+
56
+ def add_values_for(cards)
57
+ cards.each do |card|
58
+ if NON_NUMERICS.include? card
59
+ add(10)
60
+ elsif card == "A"
61
+ increment_ace_count
62
+ add(11)
63
+ else
64
+ add(card.to_i)
65
+ end
66
+ end
67
+ end
68
+
69
+ def adjust_aces
70
+ (1..aces).each do |ace|
71
+ break if total <= 21
72
+ minus(10)
73
+ end
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,3 @@
1
+ module EightySixed
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: eighty_sixed
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Cristian Tountzis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-05-29 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.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Calculates the best possible hand, don't use in the casino you may get
42
+ 86'd
43
+ email:
44
+ - cristian@intriguos.com
45
+ executables:
46
+ - eighty_sixed.rb
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - .gitignore
51
+ - Gemfile
52
+ - LICENSE
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/eighty_sixed.rb
57
+ - eighty_sixed.gemspec
58
+ - lib/eighty_sixed.rb
59
+ - lib/eighty_sixed/version.rb
60
+ homepage: ''
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.2.2
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Calculates the best possible blackjack hand
84
+ test_files: []