Boy2Man 0.1.0 → 0.1.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 +4 -4
- data/README.md +11 -0
- data/bin/Boy2Man +0 -0
- data/lib/Boy2Man.rb +55 -7
- data/lib/Boy2Man/version.rb +1 -1
- data/test/test_Boy2Man.rb +10 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf09c31b373b25cb9019efd9b20a4b1699713a1f
|
4
|
+
data.tar.gz: 9fa59a0c7cfb78b4fa28ce9dde125766aa48f1a8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4838e5d2da32e34c6540bd13993043af74f1b0dda751c5feb347f326dcd0b74e3fa6e0368e3f663605e325f4457be54469e0275b8d70a0f480fde9ea159acef2
|
7
|
+
data.tar.gz: 3c86dd5dce8505b9c1158d0b0f3a20d73da68aa7658e9ce5b892d3e24c8236048917f153354a4a38d367d24ce62f6850ba17c90fba189449a4f7da4ba2bc3073
|
data/README.md
CHANGED
data/bin/Boy2Man
CHANGED
File without changes
|
data/lib/Boy2Man.rb
CHANGED
@@ -8,20 +8,24 @@ module Boy2Man
|
|
8
8
|
stand = Boy2Man.new
|
9
9
|
loop do
|
10
10
|
print '> '
|
11
|
-
hand = gets
|
11
|
+
hand = gets.chomp
|
12
12
|
case hand
|
13
|
-
when "
|
13
|
+
when "", "bye", "exit"
|
14
14
|
exit
|
15
|
-
when "
|
16
|
-
puts stand.match(hand
|
17
|
-
when "history
|
15
|
+
when "グー", "チョキ", "パー"
|
16
|
+
puts stand.match(hand)
|
17
|
+
when "history"
|
18
18
|
puts stand.history
|
19
|
+
when "reset"
|
20
|
+
stand.reset
|
19
21
|
else
|
20
22
|
puts stand.select_hand
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
# @!attribute [r] history
|
28
|
+
# @return [Array] the history of player's hand
|
25
29
|
class Boy2Man
|
26
30
|
attr_reader :history
|
27
31
|
|
@@ -33,18 +37,32 @@ module Boy2Man
|
|
33
37
|
# retrun deep copy of history, to prevent history to be changed.
|
34
38
|
Marshal.load(Marshal.dump(@history))
|
35
39
|
end
|
36
|
-
|
40
|
+
|
41
|
+
# @return [Array] resets history
|
42
|
+
def reset
|
43
|
+
@history.clear
|
44
|
+
end
|
45
|
+
|
46
|
+
# @return [String]
|
37
47
|
def match(hand)
|
38
48
|
case hand
|
39
49
|
when "グー", "チョキ", "パー"
|
40
50
|
# 先に手を決めておかないと後出しになる
|
41
51
|
selected = select_hand
|
42
52
|
@history.push hand
|
43
|
-
selected
|
53
|
+
case judge(hand, selected)
|
54
|
+
when hand
|
55
|
+
selected + "\nYou Win!"
|
56
|
+
when selected
|
57
|
+
selected + "\nYou Lose!"
|
58
|
+
else
|
59
|
+
selected + "\nDraw!"
|
60
|
+
end
|
44
61
|
else
|
45
62
|
end
|
46
63
|
end
|
47
64
|
|
65
|
+
# @return [String]
|
48
66
|
def select_hand
|
49
67
|
case predict
|
50
68
|
when "グー" then "パー"
|
@@ -57,5 +75,35 @@ module Boy2Man
|
|
57
75
|
def predict
|
58
76
|
@history.empty? ? %w(グー チョキ パー).sample : @history.sample
|
59
77
|
end
|
78
|
+
|
79
|
+
def judge(a, b)
|
80
|
+
case a
|
81
|
+
when "グー"
|
82
|
+
if b == "チョキ"
|
83
|
+
return a
|
84
|
+
elsif b == "パー"
|
85
|
+
return b
|
86
|
+
else
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
when "チョキ"
|
90
|
+
if b == "パー"
|
91
|
+
return a
|
92
|
+
elsif b == "グー"
|
93
|
+
return b
|
94
|
+
else
|
95
|
+
return nil
|
96
|
+
end
|
97
|
+
when "パー"
|
98
|
+
if b == "グー"
|
99
|
+
return a
|
100
|
+
elsif b == "チョキ"
|
101
|
+
return b
|
102
|
+
else
|
103
|
+
return nil
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
60
108
|
end
|
61
109
|
end
|
data/lib/Boy2Man/version.rb
CHANGED
data/test/test_Boy2Man.rb
CHANGED
@@ -26,5 +26,15 @@ class TestBoy2Man < MiniTest::Unit::TestCase
|
|
26
26
|
assert_equal(["グー"], @stand.history)
|
27
27
|
@stand.match("チョキ")
|
28
28
|
assert_equal(["グー", "チョキ"], @stand.history)
|
29
|
+
|
30
|
+
@stand.history.push("something")
|
31
|
+
assert_equal(["グー", "チョキ"], @stand.history)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_reset
|
35
|
+
assert_respond_to @stand, :reset
|
36
|
+
@stand.match("チョキ")
|
37
|
+
@stand.reset
|
38
|
+
assert_equal([], @stand.history)
|
29
39
|
end
|
30
40
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Boy2Man
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zakuni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
136
|
rubyforge_project:
|
137
|
-
rubygems_version: 2.0.
|
137
|
+
rubygems_version: 2.0.3
|
138
138
|
signing_key:
|
139
139
|
specification_version: 4
|
140
140
|
summary: Rock Paper Scissors
|