Skip to content

Commit

Permalink
Removed #setup_player method
Browse files Browse the repository at this point in the history
  • Loading branch information
lisahamm committed Mar 11, 2015
1 parent 8a86b19 commit c58ce74
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 20 deletions.
10 changes: 2 additions & 8 deletions lib/tic_tac_toe/game.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@ class Game

def initialize(board=nil, player_settings, current_player_mark)
@board = board ||= Board.new
@player1 = set_player(0, player_settings)
@player2 = set_player(1, player_settings)
@player1 = Player.new(player_settings[0])
@player2 = Player.new(player_settings[1])
@current_player_mark = current_player_mark
end

def set_player(index, player_settings)
mark = player_settings[index][:mark]
Player.new(mark)
end

def board_to_array
board.to_array
end
Expand Down Expand Up @@ -52,6 +47,5 @@ def get_winning_player
def tie?
board.tie_game?
end

end
end
6 changes: 2 additions & 4 deletions spec/ai_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,16 @@ module TicTacToe
it "selects the winning move when able to win" do
cells = ['O', 'O', nil, 'X', 'X', nil, nil, nil, nil]
board = Board.new(size: 3, cells: cells)
ai = AI.new(Player.new('O'))
ai = AI.new('O')
expect(ai.get_move(board)).to eq 2
end

it "blocks winning move when opponent is able to win" do
cells = ['X', 'X', nil, nil, 'O', nil, nil, nil, nil]
board = Board.new(size: 3, cells: cells)
ai = AI.new(Player.new('O'))
ai = AI.new('O')
expect(ai.get_move(board)).to eq 2
end
end


end
end
13 changes: 5 additions & 8 deletions spec/game_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,31 @@

module TicTacToe
describe Game do
let(:player_settings1) {[{mark: 'X', ai: false}, {mark: 'O', ai: true}]}
let(:player_settings2) {[{mark: 'X', ai: true}, {mark: 'O', ai: false}]}
let(:player_settings3) {[{mark: 'X', ai: false}, {mark: 'O', ai: false}]}
let(:game) {Game.new(player_settings1, 'X')}

let(:player_settings) {['X', 'O']}
let(:game) {Game.new(player_settings, player_settings[0])}

let(:game_in_play) do
cells = ['O', 'O', nil,
nil, 'X', nil,
nil, nil, nil]
board = Board.new(cells: cells)
Game.new(board, player_settings3, 'X')
Game.new(board, player_settings, 'X')
end

let(:won_game) do
cells = ['X', 'X', 'O',
'O', 'X', 'X',
'X', 'O', 'X']
board = Board.new(cells: cells)
Game.new(board, player_settings3, 'X')
Game.new(board, player_settings, 'X')
end

let(:tie_game) do
cells = ['X', 'X', 'O',
'O', 'O', 'X',
'X', 'O', 'X']
board = Board.new(cells: cells)
Game.new(board, player_settings3, 'X')
Game.new(board, player_settings, 'X')
end

describe "#take_turn" do
Expand Down
Binary file modified tic_tac_toe-0.0.1.gem
Binary file not shown.

0 comments on commit c58ce74

Please sign in to comment.