bare_gato 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,13 +1,15 @@
1
- class Move
2
- attr_reader :x, :y, :player
1
+ module BareGato
2
+ class Move
3
+ attr_reader :x, :y, :player
3
4
 
4
- def initialize player, space
5
- @player = player
6
- @x = space[:x]
7
- @y = space[:y]
8
- end
5
+ def initialize player, space
6
+ @player = player
7
+ @x = space[:x]
8
+ @y = space[:y]
9
+ end
9
10
 
10
- def valid?
11
- x > -1 && y > -1
11
+ def valid?
12
+ x > -1 && y > -1
13
+ end
12
14
  end
13
15
  end
@@ -1,12 +1,14 @@
1
- class Player
1
+ module BareGato
2
+ class Player
2
3
 
3
- attr_reader :display
4
+ attr_reader :display
4
5
 
5
- def initialize display
6
- @display = display
7
- end
6
+ def initialize display
7
+ @display = display
8
+ end
8
9
 
9
- def == other
10
- other.display == display
10
+ def == other
11
+ other.display == display
12
+ end
11
13
  end
12
14
  end
@@ -1,3 +1,3 @@
1
1
  module BareGato
2
- VERSION = '0.0.2'
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,198 +1,200 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe BareGato::Game do
4
-
5
- let(:x_player) { Player.new 'x' }
6
-
7
- let(:o_player) { Player.new 'o' }
8
-
9
- describe 'a 3x3 game' do
10
- subject do
11
- bare_gato_game = BareGato::Game.new players: [
12
- x_player, o_player
13
- ]
14
- bare_gato_game.strategies = [
15
- BareGato::WinningStrategies::Row,
16
- BareGato::WinningStrategies::Column,
17
- BareGato::WinningStrategies::Diagonal,
18
- BareGato::WinningStrategies::InverseDiagonal
19
- ]
20
- bare_gato_game
21
- end
22
-
23
- it 'should tell if a player belongs to a game' do
24
- expect(subject.includes_player? x_player).to be_true
25
- expect(subject.includes_player? o_player).to be_true
26
- expect(subject.includes_player? Player.new 'pepino').to be_false
27
- end
3
+ module BareGato
4
+ describe Game do
5
+
6
+ let(:x_player) { Player.new 'x' }
7
+
8
+ let(:o_player) { Player.new 'o' }
9
+
10
+ describe 'a 3x3 game' do
11
+ subject do
12
+ bare_gato_game = BareGato::Game.new players: [
13
+ x_player, o_player
14
+ ]
15
+ bare_gato_game.strategies = [
16
+ BareGato::WinningStrategies::Row,
17
+ BareGato::WinningStrategies::Column,
18
+ BareGato::WinningStrategies::Diagonal,
19
+ BareGato::WinningStrategies::InverseDiagonal
20
+ ]
21
+ bare_gato_game
22
+ end
28
23
 
29
- it 'should start with the last added player' do
30
- expect(subject.next? o_player).to be_true
31
- move = Move.new o_player, x: 0, y: 0
32
- subject.play move
33
- end
24
+ it 'should tell if a player belongs to a game' do
25
+ expect(subject.includes_player? x_player).to be_true
26
+ expect(subject.includes_player? o_player).to be_true
27
+ expect(subject.includes_player? Player.new 'pepino').to be_false
28
+ end
34
29
 
35
- it 'should return the next move type' do
36
- subject.next.should eq(o_player)
37
- end
30
+ it 'should start with the last added player' do
31
+ expect(subject.next? o_player).to be_true
32
+ move = Move.new o_player, x: 0, y: 0
33
+ subject.play move
34
+ end
38
35
 
39
- it 'should keep movements sequence' do
40
- subject.play Move.new(o_player, x: 0, y: 0)
41
- expect(subject.next? o_player).to be_false
42
- expect(subject.next? x_player).to be_true
36
+ it 'should return the next move type' do
37
+ subject.next.should eq(o_player)
38
+ end
43
39
 
44
- subject.play Move.new(x_player, x: 1, y: 0)
45
- expect(subject.next? x_player).to be_false
46
- expect(subject.next? o_player).to be_true
47
- end
40
+ it 'should keep movements sequence' do
41
+ subject.play Move.new(o_player, x: 0, y: 0)
42
+ expect(subject.next? o_player).to be_false
43
+ expect(subject.next? x_player).to be_true
48
44
 
49
- it 'should return the current game status' do
50
- subject.status.should eq({
51
- game: [[nil, nil, nil],
52
- [nil, nil, nil],
53
- [nil, nil, nil]],
54
- next: o_player
55
- })
56
- end
45
+ subject.play Move.new(x_player, x: 1, y: 0)
46
+ expect(subject.next? x_player).to be_false
47
+ expect(subject.next? o_player).to be_true
48
+ end
57
49
 
58
- describe 'playing a few moves' do
50
+ it 'should return the current game status' do
51
+ subject.status.should eq({
52
+ game: [[nil, nil, nil],
53
+ [nil, nil, nil],
54
+ [nil, nil, nil]],
55
+ next: o_player
56
+ })
57
+ end
59
58
 
60
- context 'providing correct moves order' do
61
- before do
62
- subject.play Move.new(o_player, x: 0, y: 0)
63
- subject.play Move.new(x_player, x: 1, y: 0)
64
- subject.play Move.new(o_player, x: 0, y: 2)
59
+ describe 'playing a few moves' do
60
+
61
+ context 'providing correct moves order' do
62
+ before do
63
+ subject.play Move.new(o_player, x: 0, y: 0)
64
+ subject.play Move.new(x_player, x: 1, y: 0)
65
+ subject.play Move.new(o_player, x: 0, y: 2)
66
+ end
67
+
68
+ it 'should return the current game status' do
69
+ subject.status.should eq({
70
+ game: [[o_player, x_player, nil],
71
+ [nil, nil, nil],
72
+ [o_player, nil, nil]],
73
+ next: x_player
74
+ })
75
+ end
65
76
  end
66
77
 
67
- it 'should return the current game status' do
68
- subject.status.should eq({
69
- game: [[o_player, x_player, nil],
70
- [nil, nil, nil],
71
- [o_player, nil, nil]],
72
- next: x_player
73
- })
78
+ context 'providing incorrect moves order' do
79
+ it 'should raise error' do
80
+ expect { subject.play Move.new(x_player, x: 0, y: 0) }.to raise_error
81
+ subject.play Move.new(o_player, x: 0, y: 0)
82
+ subject.status.should eq({
83
+ game: [[o_player, nil, nil],
84
+ [nil, nil, nil],
85
+ [nil, nil, nil]],
86
+ next: x_player
87
+ })
88
+ end
74
89
  end
75
90
  end
76
91
 
77
- context 'providing incorrect moves order' do
78
- it 'should raise error' do
79
- expect { subject.play Move.new(x_player, x: 0, y: 0) }.to raise_error
80
- subject.play Move.new(o_player, x: 0, y: 0)
81
- subject.status.should eq({
82
- game: [[o_player, nil, nil],
83
- [nil, nil, nil],
84
- [nil, nil, nil]],
85
- next: x_player
86
- })
92
+ context 'a full game' do
93
+ context 'when winning by column' do
94
+ it 'should determine a winner' do
95
+ subject.play Move.new(o_player, x: 0, y: 0)
96
+ subject.got_a_winner?.should be_false
97
+
98
+ subject.play Move.new(x_player, x: 1, y: 0)
99
+ subject.got_a_winner?.should be_false
100
+
101
+ subject.play Move.new(o_player, x: 2, y: 0)
102
+ subject.got_a_winner?.should be_false
103
+
104
+ subject.play Move.new(x_player, x: 1, y: 1)
105
+ subject.got_a_winner?.should be_false
106
+
107
+ subject.play Move.new(o_player, x: 2, y: 1)
108
+ subject.got_a_winner?.should be_false
109
+
110
+ subject.play Move.new(x_player, x: 1, y: 2)
111
+ subject.status.should eq({
112
+ game: [[o_player, x_player, o_player],
113
+ [nil, x_player, o_player],
114
+ [nil, x_player, nil]],
115
+ next: o_player
116
+ })
117
+ subject.got_a_winner?.should be_true
118
+ end
87
119
  end
88
- end
89
- end
90
-
91
- context 'a full game' do
92
- context 'when winning by column' do
93
- it 'should determine a winner' do
94
- subject.play Move.new(o_player, x: 0, y: 0)
95
- subject.got_a_winner?.should be_false
96
-
97
- subject.play Move.new(x_player, x: 1, y: 0)
98
- subject.got_a_winner?.should be_false
99
-
100
- subject.play Move.new(o_player, x: 2, y: 0)
101
- subject.got_a_winner?.should be_false
102
-
103
- subject.play Move.new(x_player, x: 1, y: 1)
104
- subject.got_a_winner?.should be_false
105
120
 
106
- subject.play Move.new(o_player, x: 2, y: 1)
107
- subject.got_a_winner?.should be_false
108
-
109
- subject.play Move.new(x_player, x: 1, y: 2)
110
- subject.status.should eq({
111
- game: [[o_player, x_player, o_player],
112
- [nil, x_player, o_player],
113
- [nil, x_player, nil]],
114
- next: o_player
115
- })
116
- subject.got_a_winner?.should be_true
121
+ context 'when winning by row' do
122
+ it 'should determine a winner' do
123
+ subject.play Move.new(o_player, x: 0, y: 0)
124
+ subject.got_a_winner?.should be_false
125
+
126
+ subject.play Move.new(x_player, x: 0, y: 1)
127
+ subject.got_a_winner?.should be_false
128
+
129
+ subject.play Move.new(o_player, x: 1, y: 0)
130
+ subject.got_a_winner?.should be_false
131
+
132
+ subject.play Move.new(x_player, x: 1, y: 1)
133
+ subject.got_a_winner?.should be_false
134
+
135
+ subject.play Move.new(o_player, x: 2, y: 0)
136
+ subject.status.should eq({
137
+ game: [[o_player, o_player, o_player],
138
+ [x_player, x_player, nil],
139
+ [nil, nil, nil]],
140
+ next: x_player
141
+ })
142
+ subject.got_a_winner?.should be_true
143
+ end
117
144
  end
118
- end
119
-
120
- context 'when winning by row' do
121
- it 'should determine a winner' do
122
- subject.play Move.new(o_player, x: 0, y: 0)
123
- subject.got_a_winner?.should be_false
124
-
125
- subject.play Move.new(x_player, x: 0, y: 1)
126
- subject.got_a_winner?.should be_false
127
-
128
- subject.play Move.new(o_player, x: 1, y: 0)
129
- subject.got_a_winner?.should be_false
130
145
 
131
- subject.play Move.new(x_player, x: 1, y: 1)
132
- subject.got_a_winner?.should be_false
133
-
134
- subject.play Move.new(o_player, x: 2, y: 0)
135
- subject.status.should eq({
136
- game: [[o_player, o_player, o_player],
137
- [x_player, x_player, nil],
138
- [nil, nil, nil]],
139
- next: x_player
140
- })
141
- subject.got_a_winner?.should be_true
146
+ context 'when winning by diagonal' do
147
+ it 'should determine a winner' do
148
+ subject.play Move.new(o_player, x: 0, y: 0)
149
+ subject.got_a_winner?.should be_false
150
+
151
+ subject.play Move.new(x_player, x: 0, y: 1)
152
+ subject.got_a_winner?.should be_false
153
+
154
+ subject.play Move.new(o_player, x: 1, y: 1)
155
+ subject.got_a_winner?.should be_false
156
+
157
+ subject.play Move.new(x_player, x: 1, y: 0)
158
+ subject.got_a_winner?.should be_false
159
+
160
+ subject.play Move.new(o_player, x: 2, y: 2)
161
+ subject.status.should eq({
162
+ game: [[o_player, x_player, nil],
163
+ [x_player, o_player, nil],
164
+ [nil, nil, o_player]],
165
+ next: x_player
166
+ })
167
+ subject.got_a_winner?.should be_true
168
+ end
142
169
  end
143
- end
144
-
145
- context 'when winning by diagonal' do
146
- it 'should determine a winner' do
147
- subject.play Move.new(o_player, x: 0, y: 0)
148
- subject.got_a_winner?.should be_false
149
-
150
- subject.play Move.new(x_player, x: 0, y: 1)
151
- subject.got_a_winner?.should be_false
152
170
 
153
- subject.play Move.new(o_player, x: 1, y: 1)
154
- subject.got_a_winner?.should be_false
155
-
156
- subject.play Move.new(x_player, x: 1, y: 0)
157
- subject.got_a_winner?.should be_false
158
-
159
- subject.play Move.new(o_player, x: 2, y: 2)
160
- subject.status.should eq({
161
- game: [[o_player, x_player, nil],
162
- [x_player, o_player, nil],
163
- [nil, nil, o_player]],
164
- next: x_player
165
- })
166
- subject.got_a_winner?.should be_true
171
+ context 'when winning by inverse diagonal' do
172
+ it 'should determine a winner' do
173
+ subject.play Move.new(o_player, x: 2, y: 0)
174
+ subject.got_a_winner?.should be_false
175
+
176
+ subject.play Move.new(x_player, x: 0, y: 1)
177
+ subject.got_a_winner?.should be_false
178
+
179
+ subject.play Move.new(o_player, x: 1, y: 1)
180
+ subject.got_a_winner?.should be_false
181
+
182
+ subject.play Move.new(x_player, x: 1, y: 0)
183
+ subject.got_a_winner?.should be_false
184
+
185
+ subject.play Move.new(o_player, x: 0, y: 2)
186
+ subject.status.should eq({
187
+ game: [[nil, x_player, o_player],
188
+ [x_player, o_player, nil],
189
+ [o_player, nil, nil]],
190
+ next: x_player
191
+ })
192
+ subject.got_a_winner?.should be_true
193
+ end
167
194
  end
168
- end
169
-
170
- context 'when winning by inverse diagonal' do
171
- it 'should determine a winner' do
172
- subject.play Move.new(o_player, x: 2, y: 0)
173
- subject.got_a_winner?.should be_false
174
-
175
- subject.play Move.new(x_player, x: 0, y: 1)
176
- subject.got_a_winner?.should be_false
177
195
 
178
- subject.play Move.new(o_player, x: 1, y: 1)
179
- subject.got_a_winner?.should be_false
180
-
181
- subject.play Move.new(x_player, x: 1, y: 0)
182
- subject.got_a_winner?.should be_false
183
-
184
- subject.play Move.new(o_player, x: 0, y: 2)
185
- subject.status.should eq({
186
- game: [[nil, x_player, o_player],
187
- [x_player, o_player, nil],
188
- [o_player, nil, nil]],
189
- next: x_player
190
- })
191
- subject.got_a_winner?.should be_true
192
- end
193
196
  end
194
197
 
195
198
  end
196
-
197
199
  end
198
200
  end
@@ -1,20 +1,22 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Move do
4
- it "should accept valid movements" do
5
- player = Player.new 'x'
3
+ module BareGato
4
+ describe Move do
5
+ it "should accept valid movements" do
6
+ player = Player.new 'x'
6
7
 
7
- move = Move.new player, x: 0, y: 0
8
- move.valid?.should be_true
9
- end
8
+ move = Move.new player, x: 0, y: 0
9
+ move.valid?.should be_true
10
+ end
10
11
 
11
- it "should not accept invalid indexes" do
12
- player = Player.new 'x'
12
+ it "should not accept invalid indexes" do
13
+ player = Player.new 'x'
13
14
 
14
- move = Move.new player, x: -1, y: 0
15
- move.valid?.should_not be_true
15
+ move = Move.new player, x: -1, y: 0
16
+ move.valid?.should_not be_true
16
17
 
17
- move = Move.new player, x: 0, y: -1
18
- move.valid?.should_not be_true
18
+ move = Move.new player, x: 0, y: -1
19
+ move.valid?.should_not be_true
20
+ end
19
21
  end
20
22
  end
@@ -1,17 +1,19 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Player do
4
- subject do
5
- Player.new('X')
6
- end
3
+ module BareGato
4
+ describe Player do
5
+ subject do
6
+ Player.new('X')
7
+ end
7
8
 
8
- it "should be string friendly" do
9
- subject.display.should == "X"
10
- end
9
+ it "should be string friendly" do
10
+ subject.display.should == "X"
11
+ end
11
12
 
12
- it 'should identify players' do
13
- expect(Player.new 'X' ).to eq Player.new('X')
14
- expect(Player.new 'X' ).to_not eq Player.new('R')
15
- end
13
+ it 'should identify players' do
14
+ expect(Player.new 'X' ).to eq Player.new('X')
15
+ expect(Player.new 'X' ).to_not eq Player.new('R')
16
+ end
16
17
 
18
+ end
17
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bare_gato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -106,7 +106,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
106
106
  version: '0'
107
107
  segments:
108
108
  - 0
109
- hash: 85962428890766304
109
+ hash: -162106955877737498
110
110
  required_rubygems_version: !ruby/object:Gem::Requirement
111
111
  none: false
112
112
  requirements:
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
115
  version: '0'
116
116
  segments:
117
117
  - 0
118
- hash: 85962428890766304
118
+ hash: -162106955877737498
119
119
  requirements: []
120
120
  rubyforge_project:
121
121
  rubygems_version: 1.8.23