diff --git a/Gemfile.lock b/Gemfile.lock index 030be6e..610ff30 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: git://github.com/lisahamm/ruby_ttt.git - revision: a96705779a65b9d7202498ac91f06df2266850fa + revision: 68400f7aeac4dcfe44107469cbc798b13e8594f8 specs: tic_tac_toe (0.0.1) diff --git a/tic_tac_toe_controller.rb b/tic_tac_toe_controller.rb index 86005d2..e0b3249 100644 --- a/tic_tac_toe_controller.rb +++ b/tic_tac_toe_controller.rb @@ -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 @@ -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