bare_gato 0.0.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.
- data/.gitignore +17 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +34 -0
- data/LICENSE +22 -0
- data/README.md +32 -0
- data/Rakefile +2 -0
- data/bare_gato.gemspec +21 -0
- data/lib/bare_gato/game.rb +47 -0
- data/lib/bare_gato/move.rb +13 -0
- data/lib/bare_gato/player.rb +12 -0
- data/lib/bare_gato/version.rb +3 -0
- data/lib/bare_gato/winning_strategies/column.rb +15 -0
- data/lib/bare_gato/winning_strategies/diagonal.rb +20 -0
- data/lib/bare_gato/winning_strategies/inverse_diagonal.rb +20 -0
- data/lib/bare_gato/winning_strategies/row.rb +17 -0
- data/lib/bare_gato.rb +12 -0
- data/spec/bare_gato/game_spec.rb +192 -0
- data/spec/bare_gato/move_spec.rb +20 -0
- data/spec/bare_gato/player_spec.rb +17 -0
- data/spec/bare_gato/winning_strategies/column_spec.rb +40 -0
- data/spec/bare_gato/winning_strategies/diagonal_spec.rb +40 -0
- data/spec/bare_gato/winning_strategies/inverse_diagonal_spec.rb +40 -0
- data/spec/bare_gato/winning_strategies/row_spec.rb +40 -0
- data/spec/spec_helper.rb +2 -0
- data/tags +41 -0
- metadata +133 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
bare_gato (0.0.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
columnize (0.3.6)
|
10
|
+
debugger (1.6.2)
|
11
|
+
columnize (>= 0.3.1)
|
12
|
+
debugger-linecache (~> 1.2.0)
|
13
|
+
debugger-ruby_core_source (~> 1.2.3)
|
14
|
+
debugger-linecache (1.2.0)
|
15
|
+
debugger-ruby_core_source (1.2.3)
|
16
|
+
diff-lcs (1.1.3)
|
17
|
+
rake (10.1.0)
|
18
|
+
rspec (2.11.0)
|
19
|
+
rspec-core (~> 2.11.0)
|
20
|
+
rspec-expectations (~> 2.11.0)
|
21
|
+
rspec-mocks (~> 2.11.0)
|
22
|
+
rspec-core (2.11.0)
|
23
|
+
rspec-expectations (2.11.1)
|
24
|
+
diff-lcs (~> 1.1.3)
|
25
|
+
rspec-mocks (2.11.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bare_gato!
|
32
|
+
debugger
|
33
|
+
rake
|
34
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 emmanuel delgado
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
# BareGato
|
2
|
+
|
3
|
+
This is an engine to play the [**El Gato**](http://en.wikipedia.org/wiki/Tic-tac-toe) game
|
4
|
+
|
5
|
+
[](https://codeclimate.com/github/chischaschos/bare_gato)
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
gem 'bare_gato'
|
13
|
+
|
14
|
+
And then execute:
|
15
|
+
|
16
|
+
$ bundle
|
17
|
+
|
18
|
+
Or install it yourself as:
|
19
|
+
|
20
|
+
$ gem install bare_gato
|
21
|
+
|
22
|
+
## Usage
|
23
|
+
|
24
|
+
TODO: Write usage instructions here
|
25
|
+
|
26
|
+
## Contributing
|
27
|
+
|
28
|
+
1. Fork it
|
29
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
30
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
31
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
32
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/bare_gato.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/bare_gato/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ['emmanuel delgado']
|
6
|
+
gem.email = ['emmanuel.delgado@crowdint.com']
|
7
|
+
gem.description = %q{A tic tac toe game engine}
|
8
|
+
gem.summary = %q{A tic tac toe game engine}
|
9
|
+
gem.homepage = 'http://blog.crowdint.com/'
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = 'bare_gato'
|
15
|
+
gem.require_paths = ['lib']
|
16
|
+
gem.version = BareGato::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rake'
|
19
|
+
gem.add_development_dependency 'debugger'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module BareGato
|
2
|
+
class Game
|
3
|
+
attr_accessor :strategies
|
4
|
+
|
5
|
+
def initialize args
|
6
|
+
@grid = [
|
7
|
+
[nil, nil, nil],
|
8
|
+
[nil, nil, nil],
|
9
|
+
[nil, nil, nil],
|
10
|
+
]
|
11
|
+
@players = args[:players]
|
12
|
+
end
|
13
|
+
|
14
|
+
def add_player player
|
15
|
+
@players << player
|
16
|
+
end
|
17
|
+
|
18
|
+
def got_a_winner?
|
19
|
+
!!strategies.find do |strategy_class|
|
20
|
+
strategy = strategy_class.new @grid
|
21
|
+
strategy.winner?
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def next
|
26
|
+
@players.last
|
27
|
+
end
|
28
|
+
|
29
|
+
def next? player
|
30
|
+
@players.last == player
|
31
|
+
end
|
32
|
+
|
33
|
+
def play move
|
34
|
+
raise "Unexpected player moving" unless next? move.player
|
35
|
+
@grid[move.y][move.x] = move.player
|
36
|
+
@players.reverse!
|
37
|
+
end
|
38
|
+
|
39
|
+
def status
|
40
|
+
{
|
41
|
+
game: @grid,
|
42
|
+
next: self.next
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BareGato
|
2
|
+
module WinningStrategies
|
3
|
+
class Diagonal
|
4
|
+
def initialize grid
|
5
|
+
@grid = grid
|
6
|
+
end
|
7
|
+
|
8
|
+
def winner?
|
9
|
+
diagonal = []
|
10
|
+
@grid.size.times do |index|
|
11
|
+
diagonal << @grid[index][index]
|
12
|
+
end
|
13
|
+
|
14
|
+
diagonal.compact.size == @grid.size && diagonal.compact.uniq.size == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module BareGato
|
2
|
+
module WinningStrategies
|
3
|
+
class InverseDiagonal
|
4
|
+
def initialize grid
|
5
|
+
@grid = grid
|
6
|
+
end
|
7
|
+
|
8
|
+
def winner?
|
9
|
+
diagonal = []
|
10
|
+
@grid.size.times do |index|
|
11
|
+
diagonal << @grid[index][@grid.size - 1 - index]
|
12
|
+
end
|
13
|
+
|
14
|
+
diagonal.compact.size == @grid.size && diagonal.compact.uniq.size == 1
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
data/lib/bare_gato.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'bare_gato/winning_strategies/row'
|
2
|
+
require 'bare_gato/winning_strategies/column'
|
3
|
+
require 'bare_gato/winning_strategies/diagonal'
|
4
|
+
require 'bare_gato/winning_strategies/inverse_diagonal'
|
5
|
+
require 'bare_gato/player'
|
6
|
+
require 'bare_gato/move'
|
7
|
+
require 'bare_gato/game'
|
8
|
+
require "bare_gato/version"
|
9
|
+
|
10
|
+
module BareGato
|
11
|
+
# Your code goes here...
|
12
|
+
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
require 'spec_helper'
|
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 start with the last added player" do
|
24
|
+
expect(subject.next? o_player).to be_true
|
25
|
+
move = Move.new o_player, x: 0, y: 0
|
26
|
+
subject.play move
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should return the next move type" do
|
30
|
+
subject.next.should eq(o_player)
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should keep movements sequence" do
|
34
|
+
subject.play Move.new(o_player, x: 0, y: 0)
|
35
|
+
expect(subject.next? o_player).to be_false
|
36
|
+
expect(subject.next? x_player).to be_true
|
37
|
+
|
38
|
+
subject.play Move.new(x_player, x: 1, y: 0)
|
39
|
+
expect(subject.next? x_player).to be_false
|
40
|
+
expect(subject.next? o_player).to be_true
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should return the current game status" do
|
44
|
+
subject.status.should eq({
|
45
|
+
game: [[nil, nil, nil],
|
46
|
+
[nil, nil, nil],
|
47
|
+
[nil, nil, nil]],
|
48
|
+
next: o_player
|
49
|
+
})
|
50
|
+
end
|
51
|
+
|
52
|
+
describe "playing a few moves" do
|
53
|
+
|
54
|
+
context "providing correct moves order" do
|
55
|
+
before do
|
56
|
+
subject.play Move.new(o_player, x: 0, y: 0)
|
57
|
+
subject.play Move.new(x_player, x: 1, y: 0)
|
58
|
+
subject.play Move.new(o_player, x: 0, y: 2)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should return the current game status" do
|
62
|
+
subject.status.should eq({
|
63
|
+
game: [[o_player, x_player, nil],
|
64
|
+
[nil, nil, nil],
|
65
|
+
[o_player, nil, nil]],
|
66
|
+
next: x_player
|
67
|
+
})
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "providing incorrect moves order" do
|
72
|
+
it "should raise error" do
|
73
|
+
expect { subject.play Move.new(x_player, x: 0, y: 0) }.to raise_error
|
74
|
+
subject.play Move.new(o_player, x: 0, y: 0)
|
75
|
+
subject.status.should eq({
|
76
|
+
game: [[o_player, nil, nil],
|
77
|
+
[nil, nil, nil],
|
78
|
+
[nil, nil, nil]],
|
79
|
+
next: x_player
|
80
|
+
})
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "a full game" do
|
86
|
+
context "when winning by column" do
|
87
|
+
it "should determine a winner" do
|
88
|
+
subject.play Move.new(o_player, x: 0, y: 0)
|
89
|
+
subject.got_a_winner?.should be_false
|
90
|
+
|
91
|
+
subject.play Move.new(x_player, x: 1, y: 0)
|
92
|
+
subject.got_a_winner?.should be_false
|
93
|
+
|
94
|
+
subject.play Move.new(o_player, x: 2, y: 0)
|
95
|
+
subject.got_a_winner?.should be_false
|
96
|
+
|
97
|
+
subject.play Move.new(x_player, x: 1, y: 1)
|
98
|
+
subject.got_a_winner?.should be_false
|
99
|
+
|
100
|
+
subject.play Move.new(o_player, x: 2, y: 1)
|
101
|
+
subject.got_a_winner?.should be_false
|
102
|
+
|
103
|
+
subject.play Move.new(x_player, x: 1, y: 2)
|
104
|
+
subject.status.should eq({
|
105
|
+
game: [[o_player, x_player, o_player],
|
106
|
+
[nil, x_player, o_player],
|
107
|
+
[nil, x_player, nil]],
|
108
|
+
next: o_player
|
109
|
+
})
|
110
|
+
subject.got_a_winner?.should be_true
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
context "when winning by row" do
|
115
|
+
it "should determine a winner" do
|
116
|
+
subject.play Move.new(o_player, x: 0, y: 0)
|
117
|
+
subject.got_a_winner?.should be_false
|
118
|
+
|
119
|
+
subject.play Move.new(x_player, x: 0, y: 1)
|
120
|
+
subject.got_a_winner?.should be_false
|
121
|
+
|
122
|
+
subject.play Move.new(o_player, x: 1, y: 0)
|
123
|
+
subject.got_a_winner?.should be_false
|
124
|
+
|
125
|
+
subject.play Move.new(x_player, x: 1, y: 1)
|
126
|
+
subject.got_a_winner?.should be_false
|
127
|
+
|
128
|
+
subject.play Move.new(o_player, x: 2, y: 0)
|
129
|
+
subject.status.should eq({
|
130
|
+
game: [[o_player, o_player, o_player],
|
131
|
+
[x_player, x_player, nil],
|
132
|
+
[nil, nil, nil]],
|
133
|
+
next: x_player
|
134
|
+
})
|
135
|
+
subject.got_a_winner?.should be_true
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
context "when winning by diagonal" do
|
140
|
+
it "should determine a winner" do
|
141
|
+
subject.play Move.new(o_player, x: 0, y: 0)
|
142
|
+
subject.got_a_winner?.should be_false
|
143
|
+
|
144
|
+
subject.play Move.new(x_player, x: 0, y: 1)
|
145
|
+
subject.got_a_winner?.should be_false
|
146
|
+
|
147
|
+
subject.play Move.new(o_player, x: 1, y: 1)
|
148
|
+
subject.got_a_winner?.should be_false
|
149
|
+
|
150
|
+
subject.play Move.new(x_player, x: 1, y: 0)
|
151
|
+
subject.got_a_winner?.should be_false
|
152
|
+
|
153
|
+
subject.play Move.new(o_player, x: 2, y: 2)
|
154
|
+
subject.status.should eq({
|
155
|
+
game: [[o_player, x_player, nil],
|
156
|
+
[x_player, o_player, nil],
|
157
|
+
[nil, nil, o_player]],
|
158
|
+
next: x_player
|
159
|
+
})
|
160
|
+
subject.got_a_winner?.should be_true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when winning by inverse diagonal" do
|
165
|
+
it "should determine a winner" do
|
166
|
+
subject.play Move.new(o_player, x: 2, y: 0)
|
167
|
+
subject.got_a_winner?.should be_false
|
168
|
+
|
169
|
+
subject.play Move.new(x_player, x: 0, y: 1)
|
170
|
+
subject.got_a_winner?.should be_false
|
171
|
+
|
172
|
+
subject.play Move.new(o_player, x: 1, y: 1)
|
173
|
+
subject.got_a_winner?.should be_false
|
174
|
+
|
175
|
+
subject.play Move.new(x_player, x: 1, y: 0)
|
176
|
+
subject.got_a_winner?.should be_false
|
177
|
+
|
178
|
+
subject.play Move.new(o_player, x: 0, y: 2)
|
179
|
+
subject.status.should eq({
|
180
|
+
game: [[nil, x_player, o_player],
|
181
|
+
[x_player, o_player, nil],
|
182
|
+
[o_player, nil, nil]],
|
183
|
+
next: x_player
|
184
|
+
})
|
185
|
+
subject.got_a_winner?.should be_true
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Move do
|
4
|
+
it "should accept valid movements" do
|
5
|
+
player = Player.new 'x'
|
6
|
+
|
7
|
+
move = Move.new player, x: 0, y: 0
|
8
|
+
move.valid?.should be_true
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should not accept invalid indexes" do
|
12
|
+
player = Player.new 'x'
|
13
|
+
|
14
|
+
move = Move.new player, x: -1, y: 0
|
15
|
+
move.valid?.should_not be_true
|
16
|
+
|
17
|
+
move = Move.new player, x: 0, y: -1
|
18
|
+
move.valid?.should_not be_true
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Player do
|
4
|
+
subject do
|
5
|
+
Player.new('X')
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should be string friendly" do
|
9
|
+
subject.display.should == "X"
|
10
|
+
end
|
11
|
+
|
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
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BareGato::WinningStrategies::Column do
|
4
|
+
|
5
|
+
context "within a winner grid" do
|
6
|
+
let(:grid) do
|
7
|
+
[
|
8
|
+
[ nil, 'x', 'o' ],
|
9
|
+
[ nil, 'x', 'o' ],
|
10
|
+
[ nil, 'x', nil ]
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
BareGato::WinningStrategies::Column.new grid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a winner" do
|
19
|
+
subject.winner?.should be_true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "within a loser grid" do
|
24
|
+
let(:grid) do
|
25
|
+
[
|
26
|
+
[ nil, 'x', 'x' ],
|
27
|
+
[ 'o', 'x', 'o' ],
|
28
|
+
[ nil, nil, nil ]
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
BareGato::WinningStrategies::Column.new grid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a winner" do
|
37
|
+
subject.winner?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BareGato::WinningStrategies::Diagonal do
|
4
|
+
|
5
|
+
context "within a winner grid" do
|
6
|
+
let(:grid) do
|
7
|
+
[
|
8
|
+
[ 'x', nil, 'o' ] ,
|
9
|
+
[ nil, 'x', nil ] ,
|
10
|
+
[ nil, 'o', 'x' ]
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
BareGato::WinningStrategies::Diagonal.new grid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a winner" do
|
19
|
+
subject.winner?.should be_true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "within a loser grid" do
|
24
|
+
let(:grid) do
|
25
|
+
[
|
26
|
+
[ nil, 'x', 'x' ] ,
|
27
|
+
[ 'o', 'x', 'o' ] ,
|
28
|
+
[ nil, nil, nil ]
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
BareGato::WinningStrategies::Diagonal.new grid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a winner" do
|
37
|
+
subject.winner?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BareGato::WinningStrategies::InverseDiagonal do
|
4
|
+
|
5
|
+
context "within a winner grid" do
|
6
|
+
let(:grid) do
|
7
|
+
[
|
8
|
+
[ 'o', nil, 'x' ],
|
9
|
+
[ nil, 'x', nil ],
|
10
|
+
[ 'x', 'o', nil ]
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
BareGato::WinningStrategies::InverseDiagonal.new grid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a winner" do
|
19
|
+
subject.winner?.should be_true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "within a loser grid" do
|
24
|
+
let(:grid) do
|
25
|
+
[
|
26
|
+
[ nil, 'x', 'x' ],
|
27
|
+
[ 'o', 'x', 'o' ],
|
28
|
+
[ nil, nil, nil ]
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
BareGato::WinningStrategies::InverseDiagonal.new grid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a winner" do
|
37
|
+
subject.winner?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe BareGato::WinningStrategies::Row do
|
4
|
+
|
5
|
+
context "within a winner grid" do
|
6
|
+
let(:grid) do
|
7
|
+
[
|
8
|
+
[ nil, 'x', 'x' ],
|
9
|
+
[ 'o', 'o', 'o' ],
|
10
|
+
[ nil, nil, nil ]
|
11
|
+
]
|
12
|
+
end
|
13
|
+
|
14
|
+
subject do
|
15
|
+
BareGato::WinningStrategies::Row.new grid
|
16
|
+
end
|
17
|
+
|
18
|
+
it "returns a winner" do
|
19
|
+
subject.winner?.should be_true
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "within a loser grid" do
|
24
|
+
let(:grid) do
|
25
|
+
[
|
26
|
+
[ nil, 'x', 'x' ],
|
27
|
+
[ 'o', 'x', 'o' ],
|
28
|
+
[ nil, nil, nil ]
|
29
|
+
]
|
30
|
+
end
|
31
|
+
|
32
|
+
subject do
|
33
|
+
BareGato::WinningStrategies::Row.new grid
|
34
|
+
end
|
35
|
+
|
36
|
+
it "returns a winner" do
|
37
|
+
subject.winner?.should be_false
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/spec/spec_helper.rb
ADDED
data/tags
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;" to lines/
|
2
|
+
!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/
|
3
|
+
!_TAG_PROGRAM_AUTHOR Darren Hiebert /dhiebert@users.sourceforge.net/
|
4
|
+
!_TAG_PROGRAM_NAME Exuberant Ctags //
|
5
|
+
!_TAG_PROGRAM_URL http://ctags.sourceforge.net /official site/
|
6
|
+
!_TAG_PROGRAM_VERSION 5.8 //
|
7
|
+
BareGato lib/bare_gato.rb /^module BareGato$/;" m
|
8
|
+
BareGato lib/bare_gato/game.rb /^module BareGato$/;" m
|
9
|
+
BareGato lib/bare_gato/version.rb /^module BareGato$/;" m
|
10
|
+
BareGato lib/bare_gato/winning_strategies/column.rb /^module BareGato$/;" m
|
11
|
+
BareGato lib/bare_gato/winning_strategies/diagonal.rb /^module BareGato$/;" m
|
12
|
+
BareGato lib/bare_gato/winning_strategies/inverse_diagonal.rb /^module BareGato$/;" m
|
13
|
+
BareGato lib/bare_gato/winning_strategies/row.rb /^module BareGato$/;" m
|
14
|
+
Column lib/bare_gato/winning_strategies/column.rb /^ class Column$/;" c class:BareGato.WinningStrategies
|
15
|
+
Diagonal lib/bare_gato/winning_strategies/diagonal.rb /^ class Diagonal$/;" c class:BareGato.WinningStrategies
|
16
|
+
Game lib/bare_gato/game.rb /^ class Game$/;" c class:BareGato
|
17
|
+
InverseDiagonal lib/bare_gato/winning_strategies/inverse_diagonal.rb /^ class InverseDiagonal$/;" c class:BareGato.WinningStrategies
|
18
|
+
Move lib/bare_gato/move.rb /^class Move$/;" c
|
19
|
+
Player lib/bare_gato/player.rb /^class Player$/;" c
|
20
|
+
Row lib/bare_gato/winning_strategies/row.rb /^ class Row$/;" c class:BareGato.WinningStrategies
|
21
|
+
WinningStrategies lib/bare_gato/winning_strategies/column.rb /^ module WinningStrategies$/;" m class:BareGato
|
22
|
+
WinningStrategies lib/bare_gato/winning_strategies/diagonal.rb /^ module WinningStrategies$/;" m class:BareGato
|
23
|
+
WinningStrategies lib/bare_gato/winning_strategies/inverse_diagonal.rb /^ module WinningStrategies$/;" m class:BareGato
|
24
|
+
WinningStrategies lib/bare_gato/winning_strategies/row.rb /^ module WinningStrategies$/;" m class:BareGato
|
25
|
+
got_a_winner? lib/bare_gato/game.rb /^ def got_a_winner?$/;" f class:BareGato.Game
|
26
|
+
initialize lib/bare_gato/game.rb /^ def initialize$/;" f class:BareGato.Game
|
27
|
+
initialize lib/bare_gato/move.rb /^ def initialize player, space$/;" f class:Move
|
28
|
+
initialize lib/bare_gato/player.rb /^ def initialize display$/;" f class:Player
|
29
|
+
initialize lib/bare_gato/winning_strategies/column.rb /^ def initialize grid$/;" f class:BareGato.WinningStrategies.Column
|
30
|
+
initialize lib/bare_gato/winning_strategies/diagonal.rb /^ def initialize grid$/;" f class:BareGato.WinningStrategies.Diagonal
|
31
|
+
initialize lib/bare_gato/winning_strategies/inverse_diagonal.rb /^ def initialize grid$/;" f class:BareGato.WinningStrategies.InverseDiagonal
|
32
|
+
initialize lib/bare_gato/winning_strategies/row.rb /^ def initialize grid$/;" f class:BareGato.WinningStrategies.Row
|
33
|
+
next lib/bare_gato/game.rb /^ def next$/;" f class:BareGato.Game
|
34
|
+
next? lib/bare_gato/game.rb /^ def next? move_type$/;" f class:BareGato.Game
|
35
|
+
play lib/bare_gato/game.rb /^ def play move$/;" f class:BareGato.Game
|
36
|
+
status lib/bare_gato/game.rb /^ def status$/;" f class:BareGato.Game
|
37
|
+
valid? lib/bare_gato/move.rb /^ def valid?$/;" f class:Move
|
38
|
+
winner? lib/bare_gato/winning_strategies/column.rb /^ def winner?$/;" f class:BareGato.WinningStrategies.Column
|
39
|
+
winner? lib/bare_gato/winning_strategies/diagonal.rb /^ def winner?$/;" f class:BareGato.WinningStrategies.Diagonal
|
40
|
+
winner? lib/bare_gato/winning_strategies/inverse_diagonal.rb /^ def winner?$/;" f class:BareGato.WinningStrategies.InverseDiagonal
|
41
|
+
winner? lib/bare_gato/winning_strategies/row.rb /^ def winner?$/;" f class:BareGato.WinningStrategies.Row
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bare_gato
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- emmanuel delgado
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-10-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: debugger
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: A tic tac toe game engine
|
63
|
+
email:
|
64
|
+
- emmanuel.delgado@crowdint.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- .rspec
|
71
|
+
- Gemfile
|
72
|
+
- Gemfile.lock
|
73
|
+
- LICENSE
|
74
|
+
- README.md
|
75
|
+
- Rakefile
|
76
|
+
- bare_gato.gemspec
|
77
|
+
- lib/bare_gato.rb
|
78
|
+
- lib/bare_gato/game.rb
|
79
|
+
- lib/bare_gato/move.rb
|
80
|
+
- lib/bare_gato/player.rb
|
81
|
+
- lib/bare_gato/version.rb
|
82
|
+
- lib/bare_gato/winning_strategies/column.rb
|
83
|
+
- lib/bare_gato/winning_strategies/diagonal.rb
|
84
|
+
- lib/bare_gato/winning_strategies/inverse_diagonal.rb
|
85
|
+
- lib/bare_gato/winning_strategies/row.rb
|
86
|
+
- spec/bare_gato/game_spec.rb
|
87
|
+
- spec/bare_gato/move_spec.rb
|
88
|
+
- spec/bare_gato/player_spec.rb
|
89
|
+
- spec/bare_gato/winning_strategies/column_spec.rb
|
90
|
+
- spec/bare_gato/winning_strategies/diagonal_spec.rb
|
91
|
+
- spec/bare_gato/winning_strategies/inverse_diagonal_spec.rb
|
92
|
+
- spec/bare_gato/winning_strategies/row_spec.rb
|
93
|
+
- spec/spec_helper.rb
|
94
|
+
- tags
|
95
|
+
homepage: http://blog.crowdint.com/
|
96
|
+
licenses: []
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
segments:
|
108
|
+
- 0
|
109
|
+
hash: -2920284401328294361
|
110
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
111
|
+
none: false
|
112
|
+
requirements:
|
113
|
+
- - ! '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: -2920284401328294361
|
119
|
+
requirements: []
|
120
|
+
rubyforge_project:
|
121
|
+
rubygems_version: 1.8.23
|
122
|
+
signing_key:
|
123
|
+
specification_version: 3
|
124
|
+
summary: A tic tac toe game engine
|
125
|
+
test_files:
|
126
|
+
- spec/bare_gato/game_spec.rb
|
127
|
+
- spec/bare_gato/move_spec.rb
|
128
|
+
- spec/bare_gato/player_spec.rb
|
129
|
+
- spec/bare_gato/winning_strategies/column_spec.rb
|
130
|
+
- spec/bare_gato/winning_strategies/diagonal_spec.rb
|
131
|
+
- spec/bare_gato/winning_strategies/inverse_diagonal_spec.rb
|
132
|
+
- spec/bare_gato/winning_strategies/row_spec.rb
|
133
|
+
- spec/spec_helper.rb
|