jankenpon 1.0.0
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 +10 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +25 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/jankenpon.gemspec +28 -0
- data/lib/jankenpon.rb +23 -0
- data/lib/jankenpon/ai.rb +9 -0
- data/lib/jankenpon/player.rb +23 -0
- data/lib/jankenpon/rock_paper_scissors.rb +98 -0
- data/lib/jankenpon/version.rb +3 -0
- metadata +90 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: db5ebf60f726de6b6b3cdcd3866954581b2d11e1
|
4
|
+
data.tar.gz: f59b81e5ee0fc212f098ced910ba90b18cc2e0ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 383b81ab2ca42b4e2d5a074a3fb64ed54281ae323a01134984cb689db2cf26a168d1ec7c1ca54fb2616d0dab0e5e37941a6c71acee0ae742874a35263ff37ba0
|
7
|
+
data.tar.gz: ae90578b48355335949ad714903f77c3b1a028b1c69eb4d1a7eee2fbd2bccea3662e77776eeee8f9301bccb7a5d9bb7cf42b48b4c803e7de67603fb40100d8e1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 niconan
|
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,25 @@
|
|
1
|
+
# Jankenpon
|
2
|
+
|
3
|
+
This gem allows for a game of rock, paper, scissors to be played with one player vs. AI, or two players against each other.
|
4
|
+
|
5
|
+
## Installation & usage
|
6
|
+
|
7
|
+
Install the gem:
|
8
|
+
|
9
|
+
`$ gem install jankenpon`
|
10
|
+
|
11
|
+
Require it in your file or in IRB/Pry:
|
12
|
+
|
13
|
+
`require "jankenpon"`
|
14
|
+
|
15
|
+
Call the play method and watch the magic:
|
16
|
+
|
17
|
+
`Jankenpon.play`
|
18
|
+
|
19
|
+
## Contributing
|
20
|
+
|
21
|
+
1. Fork it ( https://github.com/nicoNaN/assignment_gems_sprint/fork )
|
22
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
23
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
24
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
25
|
+
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 "jankenpon"
|
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/setup
ADDED
data/jankenpon.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'jankenpon/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jankenpon"
|
8
|
+
spec.version = Jankenpon::VERSION
|
9
|
+
spec.authors = ["niconan"]
|
10
|
+
spec.email = ["nick.hax@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Play rock, paper, scissors against an AI or another player.}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/nicoNaN/assignment_gems_sprint"
|
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 = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
if spec.respond_to?(:metadata)
|
23
|
+
spec.metadata['allowed_push_host'] = "https://rubygems.org"
|
24
|
+
end
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
end
|
data/lib/jankenpon.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require "jankenpon/version"
|
2
|
+
require "jankenpon/player"
|
3
|
+
require "jankenpon/ai"
|
4
|
+
require "jankenpon/rock_paper_scissors"
|
5
|
+
|
6
|
+
module Jankenpon
|
7
|
+
|
8
|
+
def self.play
|
9
|
+
puts "How many players, 1 or 2?"
|
10
|
+
|
11
|
+
|
12
|
+
input = gets.chomp.to_i
|
13
|
+
if input == 1
|
14
|
+
game = RPS.new(1)
|
15
|
+
game.play
|
16
|
+
elsif input == 2
|
17
|
+
game = RPS.new(2)
|
18
|
+
game.play
|
19
|
+
else
|
20
|
+
puts "Invalid number of players! Try again."
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/lib/jankenpon/ai.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
class Player
|
2
|
+
|
3
|
+
attr_accessor :choice, :pid
|
4
|
+
|
5
|
+
def initialize( pid )
|
6
|
+
@pid = pid
|
7
|
+
end
|
8
|
+
|
9
|
+
def beats?( opponent )
|
10
|
+
if self.choice == 'R' && opponent.choice == 'S' || self.choice == 'P' && opponent.choice == 'R' || self.choice == 'S' && opponent.choice == 'P'
|
11
|
+
true
|
12
|
+
elsif self.choice == 'R' && opponent.choice == 'P' || self.choice == 'P' && opponent.choice == 'S' || self.choice == 'S' && opponent.choice == 'R'
|
13
|
+
false
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def draw?( opponent )
|
18
|
+
if self.choice == opponent.choice
|
19
|
+
true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class RPS
|
2
|
+
|
3
|
+
def initialize( players )
|
4
|
+
@players = players
|
5
|
+
@p1 = Player.new(1)
|
6
|
+
@p2 = Player.new(2)
|
7
|
+
@current_player = @p1
|
8
|
+
@tachikoma = Tachikoma.new
|
9
|
+
@valid_input = false
|
10
|
+
end
|
11
|
+
|
12
|
+
def play
|
13
|
+
welcome_message
|
14
|
+
loop do
|
15
|
+
until @valid_input
|
16
|
+
prompt_user_input
|
17
|
+
end
|
18
|
+
@tachikoma.choose
|
19
|
+
determine_victor
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def welcome_message
|
24
|
+
puts ""
|
25
|
+
puts "Welcome to rock, paper, scissors!"
|
26
|
+
puts ""
|
27
|
+
end
|
28
|
+
|
29
|
+
def prompt_user_input
|
30
|
+
puts ""
|
31
|
+
puts "Choose your weapon, Player #{@current_player.pid}: Rock ('R'), Paper ('P') or Scissors ('S'). Type 'Q' to quit."
|
32
|
+
@current_player.choice = gets.chomp.upcase
|
33
|
+
validate_input
|
34
|
+
end
|
35
|
+
|
36
|
+
def validate_input
|
37
|
+
if @current_player.choice == "Q"
|
38
|
+
exit
|
39
|
+
elsif !["R","P","S"].include?( @current_player.choice )
|
40
|
+
puts ""
|
41
|
+
puts "Please enter a valid choice!"
|
42
|
+
@valid_input = false
|
43
|
+
else
|
44
|
+
if @players == 2
|
45
|
+
if @current_player.pid == 1
|
46
|
+
@valid_input = false
|
47
|
+
@current_player = @p2
|
48
|
+
else
|
49
|
+
@valid_input = true
|
50
|
+
end
|
51
|
+
else
|
52
|
+
@valid_input = true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def determine_victor
|
58
|
+
if @players == 2
|
59
|
+
if @p1.draw? ( @p2 )
|
60
|
+
puts ""
|
61
|
+
puts "Player 1 picks #{@p1.choice}, Player 2 picks #{@p2.choice}."
|
62
|
+
puts "It's a draw!"
|
63
|
+
puts ""
|
64
|
+
elsif @p1.beats? ( @p2 )
|
65
|
+
puts ""
|
66
|
+
puts "Player 1 picks #{@p1.choice}, Player 2 picks #{@p2.choice}."
|
67
|
+
puts "Player 1 wins!"
|
68
|
+
puts ""
|
69
|
+
else
|
70
|
+
puts ""
|
71
|
+
puts "Player 1 picks #{@p1.choice}, Player 2 picks #{@p2.choice}."
|
72
|
+
puts "Player 2 wins!"
|
73
|
+
puts ""
|
74
|
+
end
|
75
|
+
@current_player = @p1
|
76
|
+
@valid_input = false
|
77
|
+
else
|
78
|
+
if @p1.draw? ( @tachikoma )
|
79
|
+
puts ""
|
80
|
+
puts "You pick #{@p1.choice}, Tachikoma picks #{@tachikoma.choice}."
|
81
|
+
puts "It's a draw!"
|
82
|
+
puts ""
|
83
|
+
elsif @p1.beats?( @tachikoma )
|
84
|
+
puts ""
|
85
|
+
puts "You pick #{@p1.choice}, Tachikoma picks #{@tachikoma.choice}."
|
86
|
+
puts "You win!"
|
87
|
+
puts ""
|
88
|
+
else
|
89
|
+
puts ""
|
90
|
+
puts "You pick #{@p1.choice}, Tachikoma picks #{@tachikoma.choice}."
|
91
|
+
puts "Tachikoma wins!"
|
92
|
+
puts ""
|
93
|
+
end
|
94
|
+
@valid_input = false
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jankenpon
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- niconan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-07 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: ''
|
42
|
+
email:
|
43
|
+
- nick.hax@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".DS_Store"
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/.DS_Store
|
55
|
+
- bin/console
|
56
|
+
- bin/setup
|
57
|
+
- jankenpon.gemspec
|
58
|
+
- lib/.DS_Store
|
59
|
+
- lib/jankenpon.rb
|
60
|
+
- lib/jankenpon/.DS_Store
|
61
|
+
- lib/jankenpon/ai.rb
|
62
|
+
- lib/jankenpon/player.rb
|
63
|
+
- lib/jankenpon/rock_paper_scissors.rb
|
64
|
+
- lib/jankenpon/version.rb
|
65
|
+
homepage: https://github.com/nicoNaN/assignment_gems_sprint
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
allowed_push_host: https://rubygems.org
|
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 rock, paper, scissors against an AI or another player.
|
90
|
+
test_files: []
|