Skip to content

Commit

Permalink
Updated setup route to check for computer move as first move
Browse files Browse the repository at this point in the history
  • Loading branch information
lisahamm committed Mar 11, 2015
1 parent a981307 commit 444ff4e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/lisahamm/ruby_ttt.git
revision: a96705779a65b9d7202498ac91f06df2266850fa
revision: 68400f7aeac4dcfe44107469cbc798b13e8594f8
specs:
tic_tac_toe (0.0.1)

Expand Down
12 changes: 10 additions & 2 deletions tic_tac_toe_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ class TicTacToeController < Sinatra::Base
flash[:errors] = @setup.errors
erb :index
else
session[:game] = create_game(params)
game = create_game(params)
if computer_opponent(params) == 'player1'
game.take_turn(generate_ai_move)
switch_turn
end
session[:game] = game
redirect to('/game')
end
end
Expand All @@ -37,9 +42,12 @@ class TicTacToeController < Sinatra::Base
move = params[:move].to_i
game.take_turn(move)
game.switch_turn
redirect to('/game_over') if !game.in_progress?
game.take_turn(game.generate_ai_move)
game.switch_turn
redirect to('/game_over') if !game.in_progress?
session[:game] = game
session[:moves] = game.board.to_array
redirect to('/game_over') if !game.in_progress?
redirect to('/game')
end

Expand Down

0 comments on commit 444ff4e

Please sign in to comment.