tic_tac_toe_nhu 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/Gemfile.lock +13 -11
- data/lib/tic_tac_toe/game.rb +1 -1
- data/lib/tic_tac_toe/runner.rb +12 -12
- data/spec/mocks/game.rb +1 -1
- data/spec/tic_tac_toe/game_spec.rb +20 -20
- data/spec/tic_tac_toe/runner_spec.rb +21 -21
- data/tic_tac_toe_nhu.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26958ec38dc0a7146011dd9fcf8d64e44c53dd11
|
4
|
+
data.tar.gz: c9f624e26c265343a44f9704a023a09ceefb1242
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f85c1739cef67a1deba90eed624f3e897b9c8eebdde2054ec2243c5fcce3b4b48906e86962291dc5dcdd68b49020b3f8774481e337554f14d5f1767b67fa4ed
|
7
|
+
data.tar.gz: a6251f4b4f381ae5fda53eb1ee046c8425e5be125e486e5ce06fabdc63fd9d22ab351674cdffc99bad3fac633dddf39b6b7ecb7861ecb5c7d70b4dc444c1f171
|
data/Gemfile.lock
CHANGED
@@ -2,25 +2,27 @@ GEM
|
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
builder (3.2.2)
|
5
|
-
cucumber (1.3.
|
5
|
+
cucumber (1.3.6)
|
6
6
|
builder (>= 2.1.2)
|
7
7
|
diff-lcs (>= 1.1.3)
|
8
8
|
gherkin (~> 2.12.0)
|
9
|
-
multi_json (~> 1.
|
9
|
+
multi_json (~> 1.7.5)
|
10
|
+
multi_test (>= 0.0.2)
|
10
11
|
diff-lcs (1.2.4)
|
11
|
-
gherkin (2.12.
|
12
|
+
gherkin (2.12.1)
|
12
13
|
multi_json (~> 1.3)
|
13
14
|
json (1.7.7)
|
14
|
-
multi_json (1.7.
|
15
|
+
multi_json (1.7.9)
|
16
|
+
multi_test (0.0.2)
|
15
17
|
rake (10.1.0)
|
16
|
-
rspec (2.
|
17
|
-
rspec-core (~> 2.
|
18
|
-
rspec-expectations (~> 2.
|
19
|
-
rspec-mocks (~> 2.
|
20
|
-
rspec-core (2.
|
21
|
-
rspec-expectations (2.
|
18
|
+
rspec (2.14.1)
|
19
|
+
rspec-core (~> 2.14.0)
|
20
|
+
rspec-expectations (~> 2.14.0)
|
21
|
+
rspec-mocks (~> 2.14.0)
|
22
|
+
rspec-core (2.14.4)
|
23
|
+
rspec-expectations (2.14.1)
|
22
24
|
diff-lcs (>= 1.1.3, < 2.0)
|
23
|
-
rspec-mocks (2.
|
25
|
+
rspec-mocks (2.14.3)
|
24
26
|
simplecov (0.7.1)
|
25
27
|
multi_json (~> 1.0)
|
26
28
|
simplecov-html (~> 0.7.1)
|
data/lib/tic_tac_toe/game.rb
CHANGED
data/lib/tic_tac_toe/runner.rb
CHANGED
@@ -5,47 +5,47 @@ require 'tic_tac_toe/board'
|
|
5
5
|
module TicTacToe
|
6
6
|
class Runner
|
7
7
|
|
8
|
-
def initialize(ui = TicTacToe::Console.new,
|
8
|
+
def initialize(ui = TicTacToe::Console.new, game_factory = TicTacToe::GameFactory.new)
|
9
9
|
@ui = ui
|
10
|
-
@
|
10
|
+
@game_factory = game_factory
|
11
11
|
end
|
12
12
|
|
13
13
|
def start
|
14
14
|
ui.display_welcome_message
|
15
|
-
@
|
16
|
-
play until
|
15
|
+
@game = create_game
|
16
|
+
play until game.over?
|
17
17
|
ui.display_board(board)
|
18
18
|
display_result
|
19
19
|
end
|
20
20
|
|
21
21
|
private
|
22
|
-
attr_reader :ui, :
|
22
|
+
attr_reader :ui, :game, :game_factory
|
23
23
|
|
24
|
-
def
|
24
|
+
def create_game
|
25
25
|
game_type = ui.game_type
|
26
26
|
begin
|
27
|
-
|
27
|
+
game_factory.create(game_type)
|
28
28
|
rescue ArgumentError
|
29
|
-
|
29
|
+
create_game
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
33
|
def play
|
34
34
|
ui.display_board(board)
|
35
|
-
ui.display_player_turn(
|
35
|
+
ui.display_player_turn(game.current_player)
|
36
36
|
make_player_move
|
37
37
|
end
|
38
38
|
|
39
39
|
def make_player_move
|
40
40
|
begin
|
41
|
-
|
41
|
+
game.make_player_move
|
42
42
|
rescue MoveNotAvailableError
|
43
43
|
make_player_move
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
def display_result
|
48
|
-
winner =
|
48
|
+
winner = game.winner
|
49
49
|
if winner
|
50
50
|
ui.display_winner(winner)
|
51
51
|
else
|
@@ -54,7 +54,7 @@ module TicTacToe
|
|
54
54
|
end
|
55
55
|
|
56
56
|
def board
|
57
|
-
|
57
|
+
game.board
|
58
58
|
end
|
59
59
|
end
|
60
60
|
end
|
data/spec/mocks/game.rb
CHANGED
@@ -6,99 +6,99 @@ require 'tic_tac_toe/values'
|
|
6
6
|
require 'mocks/strategy/dynamic'
|
7
7
|
|
8
8
|
describe TicTacToe::Game do
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :game, :player1, :player2, :board
|
10
10
|
|
11
11
|
before(:each) do
|
12
12
|
@board = TicTacToe::Board.new
|
13
13
|
@player1_strategy = MockDynamicStrategy.new
|
14
14
|
@player1 = TicTacToe::Player.new("player1", TicTacToe::VALUES[0], @player1_strategy)
|
15
15
|
@player2 = TicTacToe::Player.new("player1", TicTacToe::VALUES[1], nil)
|
16
|
-
@
|
16
|
+
@game = TicTacToe::Game.new([@player1, @player2], @board)
|
17
17
|
end
|
18
18
|
|
19
19
|
|
20
20
|
it "can read board" do
|
21
|
-
|
21
|
+
game.board.should == board
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "game over" do
|
25
25
|
it "is false when there is no mark" do
|
26
|
-
|
26
|
+
game.should_not be_over
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should be over when there is a winner" do
|
30
30
|
mark_winning_board(player1.value)
|
31
|
-
|
31
|
+
game.should be_over
|
32
32
|
end
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "winner" do
|
36
36
|
it "has no winner when there is no mark" do
|
37
|
-
|
37
|
+
game.winner.should be_nil
|
38
38
|
end
|
39
39
|
|
40
40
|
it "is player 1" do
|
41
41
|
mark_winning_board(player1.value)
|
42
|
-
|
42
|
+
game.winner.should == player1
|
43
43
|
end
|
44
44
|
|
45
45
|
it "is player 2" do
|
46
46
|
mark_winning_board(player2.value)
|
47
|
-
|
47
|
+
game.winner.should == player2
|
48
48
|
end
|
49
49
|
end
|
50
50
|
|
51
51
|
context "make player move" do
|
52
52
|
it "mark the board with player move when caller doesn't pass in a move" do
|
53
53
|
@player1_strategy.add_move(1)
|
54
|
-
@
|
54
|
+
@game.make_player_move
|
55
55
|
@board.unique_marked_values.should include(@player1.value)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "does not mark the board if user doesn't return an input and caller didn't pass in a move" do
|
59
59
|
@player1_strategy.add_move(nil)
|
60
|
-
@
|
60
|
+
@game.make_player_move
|
61
61
|
@board.unique_marked_values.should_not include(@player1.value)
|
62
62
|
end
|
63
63
|
|
64
64
|
it "marks the board with the move passed in" do
|
65
65
|
@player1_strategy.add_move(1)
|
66
66
|
move = 2
|
67
|
-
@
|
67
|
+
@game.make_player_move(move)
|
68
68
|
@board.available_moves.should_not include(move)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "marks the board with player move when move passed in is nil" do
|
72
72
|
@player1_strategy.add_move(1)
|
73
|
-
@
|
73
|
+
@game.make_player_move(nil)
|
74
74
|
@board.available_moves.should_not include(1)
|
75
75
|
end
|
76
76
|
|
77
77
|
it "marks the board with current player value when the move passed in" do
|
78
78
|
move = 2
|
79
|
-
@
|
79
|
+
@game.make_player_move(move)
|
80
80
|
@board.unique_marked_values.should include(@player1.value)
|
81
81
|
end
|
82
82
|
end
|
83
83
|
|
84
84
|
describe "changes player" do
|
85
85
|
it "doesn't change player if player 1 doesn't return a move" do
|
86
|
-
@
|
87
|
-
@
|
88
|
-
@
|
86
|
+
@game.current_player.should == @player1
|
87
|
+
@game.make_player_move
|
88
|
+
@game.current_player.should == @player1
|
89
89
|
end
|
90
90
|
|
91
91
|
it "changes to player 2 after player 1 moves" do
|
92
|
-
@
|
93
|
-
@
|
94
|
-
@
|
92
|
+
@game.current_player.should == @player1
|
93
|
+
@game.make_player_move(1)
|
94
|
+
@game.current_player.should == @player2
|
95
95
|
end
|
96
96
|
end
|
97
97
|
|
98
98
|
|
99
99
|
def mark_winning_board(value)
|
100
100
|
[0, 4, 8].each do |move|
|
101
|
-
|
101
|
+
game.board.mark(move, value)
|
102
102
|
end
|
103
103
|
end
|
104
104
|
end
|
@@ -7,36 +7,36 @@ require 'mocks/ui/console'
|
|
7
7
|
require 'mocks/player'
|
8
8
|
|
9
9
|
describe TicTacToe::Runner do
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :runner, :game, :ui, :game_factory
|
11
11
|
|
12
12
|
before(:each) do
|
13
|
-
@
|
14
|
-
@
|
13
|
+
@game = MockGame.factory
|
14
|
+
@game_factory = MockGameFactory.factory create: game
|
15
15
|
@ui = MockConsole.factory
|
16
|
-
@
|
16
|
+
@runner = TicTacToe::Runner.new(@ui, @game_factory)
|
17
17
|
end
|
18
18
|
|
19
19
|
it "displays a welcome message" do
|
20
|
-
|
20
|
+
runner.start
|
21
21
|
ui.was told_to(:display_welcome_message)
|
22
22
|
end
|
23
23
|
|
24
24
|
describe "create game state" do
|
25
25
|
it "asks user for a game type" do
|
26
|
-
|
26
|
+
runner.start
|
27
27
|
@ui.was asked_for(:game_type)
|
28
28
|
end
|
29
29
|
|
30
30
|
it "asks game state factory to create a game with input game type" do
|
31
31
|
game_type = 4
|
32
32
|
ui.will_have_game_type 4
|
33
|
-
|
34
|
-
@
|
33
|
+
runner.start
|
34
|
+
@game_factory.was told_to(:create).with(game_type)
|
35
35
|
end
|
36
36
|
|
37
37
|
it "asks ui for game type again if the input is incorrect" do
|
38
|
-
|
39
|
-
|
38
|
+
game_factory.will_create ArgumentError.new, game
|
39
|
+
runner.start
|
40
40
|
ui.was asked_for(:game_type).times(2)
|
41
41
|
end
|
42
42
|
end
|
@@ -46,42 +46,42 @@ describe TicTacToe::Runner do
|
|
46
46
|
|
47
47
|
before(:each) do
|
48
48
|
@player = MockPlayer.new
|
49
|
-
|
50
|
-
|
49
|
+
game.will_over? false, true
|
50
|
+
game.will_have_current_player @player
|
51
51
|
end
|
52
52
|
|
53
53
|
it "displays the board" do
|
54
|
-
|
54
|
+
runner.start
|
55
55
|
ui.was told_to(:display_board)
|
56
56
|
end
|
57
57
|
|
58
58
|
it "tells ui to display player turn" do
|
59
|
-
|
59
|
+
runner.start
|
60
60
|
ui.was told_to(:display_player_turn).with(player)
|
61
61
|
end
|
62
62
|
|
63
63
|
it "tells player to move again if there is an error" do
|
64
|
-
|
65
|
-
|
66
|
-
|
64
|
+
game.will_make_player_move TicTacToe::MoveNotAvailableError.new, nil
|
65
|
+
runner.start
|
66
|
+
game.was told_to(:make_player_move).times(2)
|
67
67
|
end
|
68
68
|
end
|
69
69
|
|
70
70
|
describe "end game" do
|
71
71
|
it "display a board at the end of the game" do
|
72
|
-
|
72
|
+
runner.start
|
73
73
|
ui.was told_to(:display_board)
|
74
74
|
end
|
75
75
|
|
76
76
|
it "asks ui to display a winner if there is a winner" do
|
77
77
|
winner = "Winner"
|
78
|
-
|
79
|
-
|
78
|
+
game.will_have_winner winner
|
79
|
+
runner.start
|
80
80
|
ui.was told_to(:display_winner).with(winner)
|
81
81
|
end
|
82
82
|
|
83
83
|
it "asks ui to display a draw" do
|
84
|
-
|
84
|
+
runner.start
|
85
85
|
ui.was told_to(:display_tied_game)
|
86
86
|
end
|
87
87
|
end
|
data/tic_tac_toe_nhu.gemspec
CHANGED