erics_tic_tac_toe 0.5.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -18,5 +18,3 @@ end
18
18
  require 'tic_tac_toe/board'
19
19
  require 'tic_tac_toe/game'
20
20
  require 'tic_tac_toe/player'
21
- require 'tic_tac_toe/presenters/game_presenter'
22
- require 'tic_tac_toe/presenters/player_presenter'
@@ -41,6 +41,14 @@ module TicTacToe
41
41
  @board.grid
42
42
  end
43
43
 
44
+ def decorated_grid
45
+ grid.each_with_index.map do |row, i|
46
+ row.each_with_index.map do |cell, j|
47
+ cell || ((i*3)+(j+1)).to_s
48
+ end
49
+ end
50
+ end
51
+
44
52
  def solved?
45
53
  @board.solved?
46
54
  end
@@ -9,5 +9,11 @@ module TicTacToe
9
9
  Player::Computer.new(params)
10
10
  end
11
11
 
12
+ module MoveJson
13
+ require 'json'
14
+ def move_json(move=nil)
15
+ {:letter => letter, :type => type, :move => move}.to_json
16
+ end
17
+ end
12
18
  end
13
19
  end
@@ -1,8 +1,10 @@
1
- module TicTacToe
1
+ require 'tic_tac_toe/player'
2
2
 
3
+ module TicTacToe
3
4
  module Player
4
-
5
5
  class Computer
6
+ include MoveJson
7
+
6
8
  attr_reader :letter
7
9
 
8
10
  def initialize(params, solver=Strategy::MinimaxStrategy)
@@ -23,8 +25,5 @@ module TicTacToe
23
25
  end
24
26
 
25
27
  end
26
-
27
28
  end
28
-
29
-
30
29
  end
@@ -1,7 +1,10 @@
1
- module TicTacToe
1
+ require 'tic_tac_toe/player'
2
2
 
3
+ module TicTacToe
3
4
  module Player
4
5
  class Human
6
+ include Player::MoveJson
7
+
5
8
  attr_reader :letter
6
9
  attr_writer :move
7
10
 
@@ -1,3 +1,3 @@
1
1
  module TicTacToe
2
- VERSION = '0.5.2'
2
+ VERSION = '1.0.0'
3
3
  end
@@ -29,6 +29,16 @@ class GameTest < MiniTest::Unit::TestCase
29
29
  assert_equal game.grid, empty_grid
30
30
  end
31
31
 
32
+ def test_empty_decorated_grid
33
+ assert_equal [%w(1 2 3), %w(4 5 6), %w(7 8 9)], TicTacToe::Game.new.decorated_grid
34
+ end
35
+
36
+ def test_decorated_grid_with_moves
37
+ game = TicTacToe::Game.new([['x', nil, nil], [nil, nil, nil], [nil, nil, nil]])
38
+
39
+ assert_equal [%w(x 2 3), %w(4 5 6), %w(7 8 9)], game.decorated_grid
40
+ end
41
+
32
42
  def test_an_empty_game_is_not_solved
33
43
  game = TicTacToe::Game.new
34
44
 
@@ -32,6 +32,11 @@ module SharedPlayerTests
32
32
  refute @player.type.nil?
33
33
  end
34
34
 
35
+ def test_has_move_json
36
+ assert_equal({:letter => 'x', :type => @player.type, :move => '1'}.to_json,
37
+ @player.move_json('1'))
38
+ end
39
+
35
40
  end
36
41
 
37
42
  class HumanPlayerTest < MiniTest::Unit::TestCase
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: erics_tic_tac_toe
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.5.2
5
+ version: 1.0.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - Eric Koslow
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-08-27 00:00:00 -05:00
13
+ date: 2012-11-18 00:00:00 -06:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -57,15 +57,11 @@ files:
57
57
  - lib/tic_tac_toe/player.rb
58
58
  - lib/tic_tac_toe/players/computer_player.rb
59
59
  - lib/tic_tac_toe/players/human_player.rb
60
- - lib/tic_tac_toe/presenters/game_presenter.rb
61
- - lib/tic_tac_toe/presenters/player_presenter.rb
62
60
  - lib/tic_tac_toe/strategies/minimax_strategy.rb
63
61
  - lib/tic_tac_toe/strategies/three_by_three_strategy.rb
64
62
  - lib/tic_tac_toe/version.rb
65
63
  - test/board_test.rb
66
- - test/game_presentor_test.rb
67
64
  - test/game_test.rb
68
- - test/player_presenter_test.rb
69
65
  - test/player_test.rb
70
66
  - test/potential_state_test.rb
71
67
  - test/solver_test.rb
@@ -102,9 +98,7 @@ specification_version: 3
102
98
  summary: A game of Tic Tac Toe
103
99
  test_files:
104
100
  - test/board_test.rb
105
- - test/game_presentor_test.rb
106
101
  - test/game_test.rb
107
- - test/player_presenter_test.rb
108
102
  - test/player_test.rb
109
103
  - test/potential_state_test.rb
110
104
  - test/solver_test.rb
@@ -1,21 +0,0 @@
1
- module TicTacToe
2
-
3
- module Presenter
4
-
5
- class Game
6
- def initialize(game)
7
- @game = game
8
- end
9
-
10
- def grid
11
- @game.grid.each_with_index.map do |row, i|
12
- row.each_with_index.map do |cell, j|
13
- cell || ((i*3)+(j+1)).to_s
14
- end
15
- end
16
- end
17
- end
18
-
19
- end
20
-
21
- end
@@ -1,19 +0,0 @@
1
- require 'json'
2
-
3
- module TicTacToe
4
-
5
- module Presenter
6
-
7
- class Player
8
- def initialize(player)
9
- @player = player
10
- end
11
-
12
- def move_json(move=nil)
13
- {:letter => @player.letter, :type => @player.type, :move => move}.to_json
14
- end
15
- end
16
-
17
- end
18
-
19
- end
@@ -1,19 +0,0 @@
1
- require 'test_helper'
2
-
3
- class GamePresentorTest < MiniTest::Unit::TestCase
4
- def setup
5
- @game = TicTacToe::Game.new
6
- @presentor = TicTacToe::Presenter::Game.new(@game)
7
- end
8
-
9
- def test_grid
10
- assert_equal [%w(1 2 3), %w(4 5 6), %w(7 8 9)], @presentor.grid
11
- end
12
-
13
- def test_grid_with_moves
14
- @game = TicTacToe::Game.new([['x', nil, nil], [nil, nil, nil], [nil, nil, nil]])
15
- @presentor = TicTacToe::Presenter::Game.new(@game)
16
-
17
- assert_equal [%w(x 2 3), %w(4 5 6), %w(7 8 9)], @presentor.grid
18
- end
19
- end
@@ -1,15 +0,0 @@
1
- require 'test_helper'
2
-
3
- class PlayerPresenterTest < MiniTest::Unit::TestCase
4
- def setup
5
- @player_mock = OpenStruct.new(:letter => 'x')
6
- @player_mock.instance_eval do
7
- def type; "mock" end
8
- end
9
- end
10
-
11
- def test_move_json
12
- assert_equal({:letter => 'x', :type => 'mock', :move => '1'}.to_json,
13
- TicTacToe::Presenter::Player.new(@player_mock).move_json('1'))
14
- end
15
- end