tic_tac_toes 0.0.4 → 0.0.5

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: d95fc15ec4e75672f05b36b32bd538a2cc2151ad
4
- data.tar.gz: 52c4c7899c4665ab00c11207aa40404ad2f9eb93
3
+ metadata.gz: 9b916612f87bbddbda20c8c47a5c0697dd0f3df9
4
+ data.tar.gz: e540d090a918ef060bdf219f1eb35c70389572ef
5
5
  SHA512:
6
- metadata.gz: 2c979a01b45ab43d4ec06b8c09ea443935cf49d8d315fba3b12489ac538d0d9504a28a2162301659b5eec5062fad56f2702925161bd5d6d188ada9526700dd32
7
- data.tar.gz: 21d2c928f2e06b78c6224642f56b097e122d9d2a46eb4b347d9393faa34b33adf31e7df9e8d46c595cae07ced0906110f51d17e4ea70e2f01c698fa12b558270
6
+ metadata.gz: bc76fb53614059ee235d7f4c22727c2171b05f982c11f6cbc098f3c05dc6559de85d1116bb5889f112f6802155dd5f75a06ec32524f121254b4ff23d5fcf70b5
7
+ data.tar.gz: 161f61d05e232f78e5a80c4582ece012dcb66ac1ac72cb4f61608e8207e6fab4888aaacef172ecfb4dae90c65a8a12c5ef511942ed1df02d7948323e1a08d230
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- tic_tac_toes (0.0.3)
4
+ tic_tac_toes (0.0.4)
5
5
  pg
6
6
 
7
7
  GEM
@@ -1,3 +1,3 @@
1
1
  module TicTacToes
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
data/lib/ui/adapter.rb CHANGED
@@ -1,36 +1,36 @@
1
1
  require 'tic_tac_toes/board'
2
2
  require 'tic_tac_toes/game_state'
3
3
  require 'tic_tac_toes/player_factory'
4
+ require 'tic_tac_toes/rules'
4
5
 
5
6
  module UI
6
- class NullHistory
7
- def record_board_size(size)
8
- nil
9
- end
10
-
11
- def record_move(move)
12
- nil
13
- end
14
- end
15
-
16
7
  module Adapter
17
8
  def self.new_board_structure
18
9
  board = TicTacToes::Board.new
19
10
  board.spaces
20
11
  end
21
12
 
22
- def self.move_made(board_structure, move)
13
+ def self.move_made(board_structure, move, listener)
23
14
  move = move.to_i
24
- game_state = UI::Adapter.game_state_from_board_structure(board_structure)
15
+ game_state = game_state_from_board_structure(board_structure)
25
16
 
26
17
  human_player = game_state.players.first
27
18
  game_state.board.place(human_player, move)
19
+
20
+ if TicTacToes::Rules.game_over?(game_state.board, game_state.players)
21
+ return listener.game_over(game_state_to_board_structure(game_state), "Game over")
22
+ end
23
+
28
24
  game_state.turn_over(move)
29
25
 
30
26
  computer_player = game_state.players.first
31
27
  computer_player.place_and_return_move(game_state.board, game_state.players)
32
28
 
33
- UI::Adapter.game_state_to_board_structure(game_state)
29
+ if TicTacToes::Rules.game_over?(game_state.board, game_state.players)
30
+ return listener.game_over(game_state_to_board_structure(game_state), "Game over")
31
+ end
32
+
33
+ listener.valid(game_state_to_board_structure(game_state))
34
34
  end
35
35
 
36
36
  def self.game_state_from_board_structure(board_structure)
@@ -81,4 +81,14 @@ module UI
81
81
  board
82
82
  end
83
83
  end
84
+
85
+ class NullHistory
86
+ def record_board_size(size)
87
+ nil
88
+ end
89
+
90
+ def record_move(move)
91
+ nil
92
+ end
93
+ end
84
94
  end
@@ -12,12 +12,31 @@ describe UI::Adapter do
12
12
  end
13
13
 
14
14
  describe '#move_made' do
15
- it 'takes a move (as string) and a board structure and returns an updated board structure' do
16
- board_structure = ["X", nil, nil, nil, "O", nil, nil, nil, nil]
17
- move = "2"
18
- updated_board_structure = ["X", "O", "X", nil, "O", nil, nil, nil, nil]
15
+ context 'when the game is still in progress' do
16
+ it 'sends its listener a `valid` message with an updated board structure' do
17
+ board_structure = ["X", nil, nil, nil, "O", nil, nil, nil, nil]
18
+ move = "2"
19
+ listener = double
19
20
 
20
- expect(UI::Adapter.move_made(board_structure, move)).to eq(updated_board_structure)
21
+ updated_board_structure = ["X", "O", "X", nil, "O", nil, nil, nil, nil]
22
+
23
+ expect(listener).to receive(:valid).with(updated_board_structure)
24
+ UI::Adapter.move_made(board_structure, move, listener)
25
+ end
26
+ end
27
+
28
+ context 'when the game has ended' do
29
+ it 'sends its listener a `game_over` message with an updated board structure and a game over message' do
30
+ board_structure = ["X", "X", nil, nil, nil, nil, nil, nil, nil]
31
+ move = "2"
32
+ listener = double
33
+
34
+ updated_board_structure = ["X", "X", "X", nil, nil, nil, nil, nil, nil]
35
+ game_over_message = "Game over"
36
+
37
+ expect(listener).to receive(:game_over).with(updated_board_structure, game_over_message)
38
+ UI::Adapter.move_made(board_structure, move, listener)
39
+ end
21
40
  end
22
41
  end
23
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tic_tac_toes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Spatafora
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-17 00:00:00.000000000 Z
11
+ date: 2014-07-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler