erics_tic_tac_toe 0.5.1 → 0.5.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/tic_tac_toe.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  # Third Party Requies
2
+ require 'rubygems'
2
3
 
3
4
  # Module wide methods / constants
4
5
  module TicTacToe
@@ -1,11 +1,14 @@
1
1
  #This is a computer that will play a perfect game of tic-tac-toe
2
2
  #Author: Eric Koslow
3
3
 
4
- require_relative 'game_types/terminal_game'
5
- require_relative 'strategies/three_by_three_strategy'
6
- require_relative 'strategies/minimax_strategy'
7
- require_relative 'players/human_player'
8
- require_relative 'players/computer_player'
4
+ $: << File.expand_path(File.dirname(__FILE__) + "/game_types")
5
+ $: << File.expand_path(File.dirname(__FILE__) + "/strategies")
6
+ $: << File.expand_path(File.dirname(__FILE__) + "/players")
7
+ require 'terminal_game'
8
+ require 'three_by_three_strategy'
9
+ require 'minimax_strategy'
10
+ require 'human_player'
11
+ require 'computer_player'
9
12
 
10
13
  module TicTacToe
11
14
  # The main director of the program
@@ -27,7 +30,7 @@ module TicTacToe
27
30
  while @current_player && (move = @current_player.get_move(@board))
28
31
  move = TicTacToe::number_to_cords(move, @board.size) unless move.is_a?(Array)
29
32
 
30
- @board.play_at(*move, @current_player.letter)
33
+ @board.play_at(move[0], move[1], @current_player.letter)
31
34
  break if over?
32
35
 
33
36
  switch_player
@@ -10,7 +10,7 @@ module TicTacToe
10
10
  end
11
11
 
12
12
  def move_json(move=nil)
13
- {letter: @player.letter, type: @player.type, move: move}.to_json
13
+ {:letter => @player.letter, :type => @player.type, :move => move}.to_json
14
14
  end
15
15
  end
16
16
 
@@ -188,7 +188,8 @@ module TicTacToe
188
188
  # Simulate forcing them to block
189
189
  temp_board = @board.clone
190
190
  temp_board.play_at(row, column, @letter)
191
- temp_board.play_at(*block(temp_board, @other_player), @other_player)
191
+ x, y = block(temp_board, @other_player)
192
+ temp_board.play_at(x, y, @other_player)
192
193
 
193
194
  # Did I just create another fork with that block?
194
195
  next if PotentialState.new(temp_board, @other_player).fork_exists?
@@ -1,3 +1,3 @@
1
1
  module TicTacToe
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -2,11 +2,14 @@ require 'test_helper'
2
2
 
3
3
  class PlayerPresenterTest < MiniTest::Unit::TestCase
4
4
  def setup
5
- @player_mock = OpenStruct.new(letter: 'x', type: 'mock')
5
+ @player_mock = OpenStruct.new(:letter => 'x')
6
+ @player_mock.instance_eval do
7
+ def type; "mock" end
8
+ end
6
9
  end
7
10
 
8
11
  def test_move_json
9
- assert_equal({letter: 'x', type: 'mock', move: '1'}.to_json,
12
+ assert_equal({:letter => 'x', :type => 'mock', :move => '1'}.to_json,
10
13
  TicTacToe::Presenter::Player.new(@player_mock).move_json('1'))
11
14
  end
12
15
  end
data/test/player_test.rb CHANGED
@@ -45,6 +45,7 @@ end
45
45
 
46
46
  class ComputerPlayerTest < MiniTest::Unit::TestCase
47
47
  class SolverMock
48
+ def initialize(_x, _y); end
48
49
  def solve
49
50
  [0, 0]
50
51
  end
data/test/solver_test.rb CHANGED
@@ -158,7 +158,8 @@ module SharedSolverTests
158
158
  end
159
159
 
160
160
  def solve!
161
- @board.play_at(*@solver.solve, 'x')
161
+ x, y = @solver.solve
162
+ @board.play_at(x, y, 'x')
162
163
  end
163
164
  end
164
165
 
data/test/test_helper.rb CHANGED
@@ -1,6 +1,3 @@
1
- require 'simplecov'
2
- SimpleCov.start
3
-
4
1
  require 'tic_tac_toe'
5
2
  require 'minitest/pride'
6
3
  require 'minitest/unit'
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.1
5
+ version: 0.5.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Eric Koslow