Boy2Man 0.2.1 → 0.2.2
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/lib/Boy2Man/janken.rb +17 -8
- data/lib/Boy2Man/version.rb +1 -1
- data/test/test_janken.rb +13 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e619834818cb5beb69ef5e5fe999842e5ee3a7d0
|
4
|
+
data.tar.gz: db9183e75ac76101c2ee1cd2664923d60d7c5084
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 18bcb84577326abdf20a0b569d1d031ae920b1fea230d46fbc4ab5488c0422c294ffae4575465ea1a6f6459b7087511cfa1d49a6e3d5c665d1ce09771bc19c8b
|
7
|
+
data.tar.gz: f0b3dc27e735b88ac4ed511ff908973308532162c883a12ebd070c70ca81f73e6bcba1ff1ef44743035d3f4721f43f9d1c02fa69c9c8e3499db4f53911d96d91
|
data/lib/Boy2Man/janken.rb
CHANGED
@@ -71,18 +71,27 @@ module Boy2Man
|
|
71
71
|
|
72
72
|
private
|
73
73
|
def predict
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
74
|
+
possible_hands = Array.new
|
75
|
+
|
76
|
+
if @history.length >= 3
|
77
|
+
@history.each_with_index do |hand, i|
|
78
|
+
# 最後に出されたと、その前の手から、次の手を予想する
|
79
|
+
if hand == @history.last(2)[0] && @history[i+1] == @history.last
|
80
|
+
possible_hands.push @history[i+2] if @history[i+2] != nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
if possible_hands.empty? || (1 < @history.length && @history.length < 3)
|
78
86
|
@history.each_with_index do |hand, i|
|
87
|
+
# 最後に出された手から、次の手を予想する
|
79
88
|
if hand == @history.last
|
80
|
-
possible_hands.push @history[i+1]
|
89
|
+
possible_hands.push @history[i+1] if @history[i+1] != nil
|
81
90
|
end
|
82
|
-
end
|
83
|
-
possible_hands.compact!
|
84
|
-
possible_hands.empty? ? %w(グー チョキ パー).sample : possible_hands.sample
|
91
|
+
end
|
85
92
|
end
|
93
|
+
|
94
|
+
possible_hands.empty? ? %w(グー チョキ パー).sample : possible_hands.sample
|
86
95
|
end
|
87
96
|
|
88
97
|
end
|
data/lib/Boy2Man/version.rb
CHANGED
data/test/test_janken.rb
CHANGED
@@ -69,5 +69,18 @@ class TestBoy2Man < MiniTest::Unit::TestCase
|
|
69
69
|
100.times do
|
70
70
|
assert_includes ["グー", "チョキ", "パー"], @janken.send(:predict)
|
71
71
|
end
|
72
|
+
@janken.reset
|
73
|
+
@janken.pon("グー")
|
74
|
+
@janken.pon("グー")
|
75
|
+
assert_equal "パー", @janken.pon("グー")
|
76
|
+
|
77
|
+
@janken.reset
|
78
|
+
@janken.pon("グー")
|
79
|
+
@janken.pon("チョキ")
|
80
|
+
@janken.pon("パー")
|
81
|
+
@janken.pon("グー")
|
82
|
+
@janken.pon("チョキ")
|
83
|
+
assert_equal "チョキ", @janken.pon("パー")
|
84
|
+
|
72
85
|
end
|
73
86
|
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.2.
|
4
|
+
version: 0.2.2
|
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-11-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|