erics_tic_tac_toe 0.5.1 → 0.5.2
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.
- data/lib/tic_tac_toe.rb +1 -0
- data/lib/tic_tac_toe/game.rb +9 -6
- data/lib/tic_tac_toe/presenters/player_presenter.rb +1 -1
- data/lib/tic_tac_toe/strategies/three_by_three_strategy.rb +2 -1
- data/lib/tic_tac_toe/version.rb +1 -1
- data/test/player_presenter_test.rb +5 -2
- data/test/player_test.rb +1 -0
- data/test/solver_test.rb +2 -1
- data/test/test_helper.rb +0 -3
- metadata +1 -1
data/lib/tic_tac_toe.rb
CHANGED
data/lib/tic_tac_toe/game.rb
CHANGED
@@ -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
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
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(
|
33
|
+
@board.play_at(move[0], move[1], @current_player.letter)
|
31
34
|
break if over?
|
32
35
|
|
33
36
|
switch_player
|
@@ -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
|
-
|
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?
|
data/lib/tic_tac_toe/version.rb
CHANGED
@@ -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
|
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
|
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
data/test/solver_test.rb
CHANGED
data/test/test_helper.rb
CHANGED