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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 651da5542ce090d2e04c3155ebf6234c46783a03
4
- data.tar.gz: 94de98d13d2ab16b04bb788fbe004e77d09567d6
3
+ metadata.gz: e619834818cb5beb69ef5e5fe999842e5ee3a7d0
4
+ data.tar.gz: db9183e75ac76101c2ee1cd2664923d60d7c5084
5
5
  SHA512:
6
- metadata.gz: b6ae8ec94576ec9bfaee57900aadef62a67e664ca56d30bc86408fe7934749b38c6ffa05de8c34e4227091c83bf25dd5d0b66864b1aeb256211faacf31681b33
7
- data.tar.gz: d9c0ac812a9933a375bef24ccc6921cf10afe1f97f70a3f239f59892902e1e090c069e31c736344bfad884cd7af847b57401b5619ebf5800cdff43f8b730bf7d
6
+ metadata.gz: 18bcb84577326abdf20a0b569d1d031ae920b1fea230d46fbc4ab5488c0422c294ffae4575465ea1a6f6459b7087511cfa1d49a6e3d5c665d1ce09771bc19c8b
7
+ data.tar.gz: f0b3dc27e735b88ac4ed511ff908973308532162c883a12ebd070c70ca81f73e6bcba1ff1ef44743035d3f4721f43f9d1c02fa69c9c8e3499db4f53911d96d91
@@ -71,18 +71,27 @@ module Boy2Man
71
71
 
72
72
  private
73
73
  def predict
74
- if @history.length < 2
75
- %w(グー チョキ パー).sample
76
- else
77
- possible_hands = Array.new
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
@@ -1,3 +1,3 @@
1
1
  module Boy2Man
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -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.1
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-10-26 00:00:00.000000000 Z
11
+ date: 2013-11-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler