ro_sham_bo 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 +7 -0
- data/.gitignore +2 -0
- data/LICENSE +21 -0
- data/README.md +46 -0
- data/Rakefile +23 -0
- data/bin/ro_sham_bo +42 -0
- data/lib/ro_sham_bo.rb +47 -0
- data/lib/ro_sham_bo/version.rb +27 -0
- data/ro_sham_bo.gemspec +32 -0
- metadata +74 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a6ebceb13a58c7ff84e66be32d08b422a57f41b37d361d591c69d88fbfbc9898
|
4
|
+
data.tar.gz: b574f3923921bce52e828b177b950277c8983ec3eb12b2d83f2948e8010963c4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '084251e4644082549a1526be1a9d827b0aca60f7fa739b1db62258f5d31a4f4c259f4baea97f421ef1313ebbc6e8a1ca309764dbac3231c2e7ca86f1708d30e8'
|
7
|
+
data.tar.gz: 264a793620438584bbe4ef70f7641a6aa287d43cd571baaaade783175a17f31ec35bcd07f654497289afeb1236184c9b2a330d5586c8c10870b7be90f8ffbf16
|
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2018 Evan Gray
|
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/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# RoShamBo
|
2
|
+
Simple Rock, Paper, Scissors game for the command-line, implemented in ruby.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
Just install the gem!
|
6
|
+
```
|
7
|
+
gem install ro_sham_bo
|
8
|
+
```
|
9
|
+
Alternatively, build from source.
|
10
|
+
```
|
11
|
+
git clone https://github.com/evanthegrayt/ro_sham_bo.git
|
12
|
+
cd ro_sham_bo
|
13
|
+
rake install
|
14
|
+
```
|
15
|
+
|
16
|
+
## Usage
|
17
|
+
Just call the `ro_sham_bo` executable, which should now be in your `$PATH`.
|
18
|
+
The default number of rounds is best-of `3`. This can be altered with the
|
19
|
+
`-r [NUMBER OF ROUNDS]` option. The number passed must be an odd number. To see
|
20
|
+
a list of all available options, run with `-h`.
|
21
|
+
```
|
22
|
+
ro_sham_bo [OPTIONS]
|
23
|
+
```
|
24
|
+
After calling the executable, you'll be asked to enter 'rock', 'paper', or
|
25
|
+
'scissors' (entering the first letters of the options is also accepted for
|
26
|
+
brevity's sake). The program will also randomly choose one of these options.
|
27
|
+
Once you hit `[return]`, your choice will be compared to the computer's choice,
|
28
|
+
and a winner for that round will be chosen based off the classic rules of the
|
29
|
+
game.
|
30
|
+
|
31
|
+
### Rules
|
32
|
+
The rules are standard rock, paper, scissors rules.
|
33
|
+
- Rock beats Scissors
|
34
|
+
- Scissors beats Paper
|
35
|
+
- Paper beats Rock
|
36
|
+
|
37
|
+
## Reporting Bugs
|
38
|
+
This was just a fun project for me to work on, but if you find problems, please
|
39
|
+
[create an
|
40
|
+
issue](https://github.com/evanthegrayt/ro_sham_bo/issues/new).
|
41
|
+
|
42
|
+
## Self-Promotion
|
43
|
+
I do these projects for fun, and I enjoy knowing that they're helpful to people.
|
44
|
+
Consider starring [the
|
45
|
+
repository](https://github.com/evanthegrayt/ro_sham_bo) if you like it!
|
46
|
+
If you love it, follow me [on github](https://github.com/evanthegrayt)!
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/ro_sham_bo'
|
4
|
+
require 'bundler/gem_tasks'
|
5
|
+
# require 'rdoc/task'
|
6
|
+
# require 'rake/testtask'
|
7
|
+
|
8
|
+
# TODO: Add tests.
|
9
|
+
# Rake::TestTask.new do |t|
|
10
|
+
# t.libs = ['lib']
|
11
|
+
# t.warning = true
|
12
|
+
# t.verbose = true
|
13
|
+
# t.test_files = FileList['test/**/*_test.rb']
|
14
|
+
# end
|
15
|
+
|
16
|
+
# TODO: Add documentation.
|
17
|
+
# RDoc::Task.new do |rdoc|
|
18
|
+
# rdoc.main = 'README.md'
|
19
|
+
# rdoc.rdoc_dir = 'doc'
|
20
|
+
# rdoc.rdoc_files.include('README.md', 'lib/**/*.rb')
|
21
|
+
# end
|
22
|
+
|
23
|
+
# task default: :test
|
data/bin/ro_sham_bo
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'optparse'
|
3
|
+
require_relative '../lib/ro_sham_bo.rb'
|
4
|
+
|
5
|
+
options = {rounds: 3}
|
6
|
+
OptionParser.new do |o|
|
7
|
+
o.on('-c', '--[no-]clear', "Clear screen after every turn") do |f|
|
8
|
+
options[:clear] = f
|
9
|
+
end
|
10
|
+
o.on('-r', '--rounds=N', Integer, "Best of N rounds", "Default is 3") do |f|
|
11
|
+
abort("Please use an odd number") if f.even?
|
12
|
+
options[:rounds] = f
|
13
|
+
end
|
14
|
+
end.parse!(ARGV)
|
15
|
+
|
16
|
+
game = RoShamBo.new(options)
|
17
|
+
|
18
|
+
system('clear') if options[:clear]
|
19
|
+
|
20
|
+
puts ">> FIRST TO #{game.points_to_win} WINS! <<"
|
21
|
+
|
22
|
+
until game.game_winner?
|
23
|
+
puts "\nCurrent score: #{game.score.inspect}"
|
24
|
+
print "What is your choice? (r)ock, (p)aper, or (s)cissors?: "
|
25
|
+
u_choice = game.user_choice($stdin.gets.chomp.downcase)
|
26
|
+
c_choice = game.computer_choice
|
27
|
+
|
28
|
+
if u_choice == :exit
|
29
|
+
break
|
30
|
+
elsif !u_choice
|
31
|
+
puts "Please enter a valid choice!"
|
32
|
+
next
|
33
|
+
end
|
34
|
+
|
35
|
+
{user: u_choice, computer: c_choice}.each { |k,v| puts "> #{k} chose #{v}" }
|
36
|
+
system('clear') if options[:clear]
|
37
|
+
|
38
|
+
puts "Round winner: #{game.round_winner(u_choice, c_choice)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
puts game.game_winner ? "\nGame over! #{game.game_winner} won!" :
|
42
|
+
"\nGame was quit. Score was #{game.score.inspect}"
|
data/lib/ro_sham_bo.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
class RoShamBo
|
2
|
+
RULES = {
|
3
|
+
rock: {rock: :draw, paper: :lose, scissors: :win}.freeze,
|
4
|
+
paper: {rock: :win, paper: :draw, scissors: :lose}.freeze,
|
5
|
+
scissors: {rock: :lose, paper: :win, scissors: :draw}.freeze,
|
6
|
+
}.freeze
|
7
|
+
|
8
|
+
attr_reader :score, :points_to_win
|
9
|
+
|
10
|
+
def initialize(options = {rounds: 3})
|
11
|
+
@options = options
|
12
|
+
@score = {user: 0, computer: 0}
|
13
|
+
@points_to_win = (options[:rounds].to_f / 2).ceil
|
14
|
+
end
|
15
|
+
|
16
|
+
def user_choice(user_input)
|
17
|
+
case user_input
|
18
|
+
when 'r', 'rock' then :rock
|
19
|
+
when 'p', 'paper' then :paper
|
20
|
+
when 's', 'scissors' then :scissors
|
21
|
+
when 'x', 'exit', 'q', 'quit' then :exit
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def computer_choice
|
26
|
+
RULES.keys.sample
|
27
|
+
end
|
28
|
+
|
29
|
+
def round_winner(u_choice, c_choice)
|
30
|
+
winner =
|
31
|
+
case RULES[u_choice][c_choice]
|
32
|
+
when :win then :user
|
33
|
+
when :lose then :computer
|
34
|
+
else :draw
|
35
|
+
end
|
36
|
+
score[winner] += 1 unless winner == :draw
|
37
|
+
winner
|
38
|
+
end
|
39
|
+
|
40
|
+
def game_winner
|
41
|
+
score.key(points_to_win).capitalize if score.value?(points_to_win)
|
42
|
+
end
|
43
|
+
|
44
|
+
def game_winner?
|
45
|
+
!game_winner.nil?
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class RoShamBo
|
4
|
+
##
|
5
|
+
# Module that contains all gem version information. Follows semantic
|
6
|
+
# versioning. Read: https://semver.org/
|
7
|
+
module Version
|
8
|
+
|
9
|
+
##
|
10
|
+
# Major version.
|
11
|
+
MAJOR = 0
|
12
|
+
|
13
|
+
##
|
14
|
+
# Minor version.
|
15
|
+
MINOR = 0
|
16
|
+
|
17
|
+
##
|
18
|
+
# Patch version.
|
19
|
+
PATCH = 1
|
20
|
+
|
21
|
+
##
|
22
|
+
# Version as +MAJOR.MINOR.PATCH+
|
23
|
+
def self.to_s
|
24
|
+
"#{MAJOR}.#{MINOR}.#{PATCH}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/ro_sham_bo.gemspec
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require_relative 'lib/ro_sham_bo/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'ro_sham_bo'
|
5
|
+
spec.version = RoShamBo::Version.to_s
|
6
|
+
spec.authors = ['Evan Gray']
|
7
|
+
spec.email = 'evanthegrayt@vivaldi.net'
|
8
|
+
spec.license = 'MIT'
|
9
|
+
spec.date = Time.now.strftime('%Y-%m-%d')
|
10
|
+
|
11
|
+
spec.summary = %q{Rock Paper Scissors in Ruby}
|
12
|
+
spec.description = %q{Play rock paper scissors from the command line}
|
13
|
+
spec.homepage = 'https://evanthegrayt.github.io/ro_sham_bo/'
|
14
|
+
|
15
|
+
unless spec.respond_to?(:metadata)
|
16
|
+
raise 'RubyGems 2.0 or newer is required to protect against ' \
|
17
|
+
'public gem pushes.'
|
18
|
+
end
|
19
|
+
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
22
|
+
spec.metadata['source_code_uri'] =
|
23
|
+
'https://github.com/evanthegrayt/ro_sham_bo'
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
26
|
+
f.match(%r{^(test|spec|features)/})
|
27
|
+
end
|
28
|
+
spec.bindir = 'bin'
|
29
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ['lib']
|
31
|
+
spec.add_development_dependency 'rake', '~> 13.0', '>= 13.0.1'
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ro_sham_bo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Evan Gray
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '13.0'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 13.0.1
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '13.0'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 13.0.1
|
33
|
+
description: Play rock paper scissors from the command line
|
34
|
+
email: evanthegrayt@vivaldi.net
|
35
|
+
executables:
|
36
|
+
- ro_sham_bo
|
37
|
+
extensions: []
|
38
|
+
extra_rdoc_files: []
|
39
|
+
files:
|
40
|
+
- ".gitignore"
|
41
|
+
- LICENSE
|
42
|
+
- README.md
|
43
|
+
- Rakefile
|
44
|
+
- bin/ro_sham_bo
|
45
|
+
- lib/ro_sham_bo.rb
|
46
|
+
- lib/ro_sham_bo/version.rb
|
47
|
+
- ro_sham_bo.gemspec
|
48
|
+
homepage: https://evanthegrayt.github.io/ro_sham_bo/
|
49
|
+
licenses:
|
50
|
+
- MIT
|
51
|
+
metadata:
|
52
|
+
allowed_push_host: https://rubygems.org
|
53
|
+
homepage_uri: https://evanthegrayt.github.io/ro_sham_bo/
|
54
|
+
source_code_uri: https://github.com/evanthegrayt/ro_sham_bo
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubygems_version: 3.2.3
|
71
|
+
signing_key:
|
72
|
+
specification_version: 4
|
73
|
+
summary: Rock Paper Scissors in Ruby
|
74
|
+
test_files: []
|