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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 76f4600254a71f4f37fe5efa7f74a8000b5d7b35
4
- data.tar.gz: 81f2f459fa5e1a867e053d42f5dfdfe2ae4dc27f
3
+ metadata.gz: 26958ec38dc0a7146011dd9fcf8d64e44c53dd11
4
+ data.tar.gz: c9f624e26c265343a44f9704a023a09ceefb1242
5
5
  SHA512:
6
- metadata.gz: 5eae5eeee50f815eaac5fb338c1aba07e9d54ad669cd179f6a333ef4b693aa333145b12825f61696eab943103b1934f4ca101e10f7bff4c10f9e702bc54a3912
7
- data.tar.gz: b9e661172ad637011bd6b36e7a0ce4cb5a56bf17f114277b9e1da7ad57bc4d03f29269e6c7328d8fd8d147b44fc39b3b7feae7d9bd8cbe7004ee8f8a4665ca98
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.2)
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.3)
9
+ multi_json (~> 1.7.5)
10
+ multi_test (>= 0.0.2)
10
11
  diff-lcs (1.2.4)
11
- gherkin (2.12.0)
12
+ gherkin (2.12.1)
12
13
  multi_json (~> 1.3)
13
14
  json (1.7.7)
14
- multi_json (1.7.7)
15
+ multi_json (1.7.9)
16
+ multi_test (0.0.2)
15
17
  rake (10.1.0)
16
- rspec (2.13.0)
17
- rspec-core (~> 2.13.0)
18
- rspec-expectations (~> 2.13.0)
19
- rspec-mocks (~> 2.13.0)
20
- rspec-core (2.13.1)
21
- rspec-expectations (2.13.0)
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.13.1)
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)
@@ -11,7 +11,7 @@ module TicTacToe
11
11
  @current_player = players[0]
12
12
  end
13
13
 
14
- def game_over?
14
+ def over?
15
15
  rules.game_over?
16
16
  end
17
17
 
@@ -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, game_state_factory = TicTacToe::GameFactory.new)
8
+ def initialize(ui = TicTacToe::Console.new, game_factory = TicTacToe::GameFactory.new)
9
9
  @ui = ui
10
- @game_state_factory = game_state_factory
10
+ @game_factory = game_factory
11
11
  end
12
12
 
13
13
  def start
14
14
  ui.display_welcome_message
15
- @game_state = create_game_state
16
- play until game_state.game_over?
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, :game_state, :game_state_factory
22
+ attr_reader :ui, :game, :game_factory
23
23
 
24
- def create_game_state
24
+ def create_game
25
25
  game_type = ui.game_type
26
26
  begin
27
- game_state_factory.create(game_type)
27
+ game_factory.create(game_type)
28
28
  rescue ArgumentError
29
- create_game_state
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(game_state.current_player)
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
- game_state.make_player_move
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 = game_state.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
- game_state.board
57
+ game.board
58
58
  end
59
59
  end
60
60
  end
data/spec/mocks/game.rb CHANGED
@@ -6,7 +6,7 @@ class MockGame
6
6
  define_reader :current_player
7
7
 
8
8
  define :winner
9
- define(:game_over?){true}
9
+ define(:over?){true}
10
10
  define(:make_player_move){|*move|}
11
11
  end
12
12
 
@@ -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 :game_state, :player1, :player2, :board
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
- @game_state = TicTacToe::Game.new([@player1, @player2], @board)
16
+ @game = TicTacToe::Game.new([@player1, @player2], @board)
17
17
  end
18
18
 
19
19
 
20
20
  it "can read board" do
21
- game_state.board.should == board
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
- game_state.should_not be_game_over
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
- game_state.should be_game_over
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
- game_state.winner.should be_nil
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
- game_state.winner.should == player1
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
- game_state.winner.should == player2
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
- @game_state.make_player_move
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
- @game_state.make_player_move
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
- @game_state.make_player_move(move)
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
- @game_state.make_player_move(nil)
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
- @game_state.make_player_move(move)
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
- @game_state.current_player.should == @player1
87
- @game_state.make_player_move
88
- @game_state.current_player.should == @player1
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
- @game_state.current_player.should == @player1
93
- @game_state.make_player_move(1)
94
- @game_state.current_player.should == @player2
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
- game_state.board.mark(move, value)
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 :game, :ui, :game_state, :game_state_factory
10
+ attr_reader :runner, :game, :ui, :game_factory
11
11
 
12
12
  before(:each) do
13
- @game_state = MockGame.factory
14
- @game_state_factory = MockGameFactory.factory create: game_state
13
+ @game = MockGame.factory
14
+ @game_factory = MockGameFactory.factory create: game
15
15
  @ui = MockConsole.factory
16
- @game = TicTacToe::Runner.new(@ui, @game_state_factory)
16
+ @runner = TicTacToe::Runner.new(@ui, @game_factory)
17
17
  end
18
18
 
19
19
  it "displays a welcome message" do
20
- game.start
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
- game.start
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
- game.start
34
- @game_state_factory.was told_to(:create).with(game_type)
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
- game_state_factory.will_create ArgumentError.new, game_state
39
- game.start
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
- game_state.will_game_over? false, true
50
- game_state.will_have_current_player @player
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
- game.start
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
- game.start
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
- game_state.will_make_player_move TicTacToe::MoveNotAvailableError.new, nil
65
- game.start
66
- game_state.was told_to(:make_player_move).times(2)
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
- game.start
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
- game_state.will_have_winner winner
79
- game.start
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
- game.start
84
+ runner.start
85
85
  ui.was told_to(:display_tied_game)
86
86
  end
87
87
  end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'tic_tac_toe_nhu'
3
- s.version = '0.1.0'
3
+ s.version = '0.1.1'
4
4
  s.date = '2013-06-11'
5
5
  s.summary = "Tic Tac Toe"
6
6
  s.description = "A simple tic tac toe game with AI"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tic_tac_toe_nhu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nhu Nguyen