<commit_before>require 'json'

require 'rack_tac_toe'
require 'tic_tac_toe/core/player'

module TicTacToe
  module Web

    class RackShell
      attr_accessor :current_move

      def self.new_shell
        router = TicTacToe::Web::Router.new
        shell = RackShell.new(router)

        router.add_route("/", :GET) do |_|
          TicTacToe::Web::View::Home.render(nil)
        end

        router.add_route("/new-game", :POST) do |env|
          req = Rack::Request.new(env)
          game = TicTacToe::Core::Game.new_game
          game.set_players(*shell.get_players(req))
          req.session[:game] = game

          TicTacToe::Web::View::Game.render(game)
        end

        router.add_route("/make-move", :POST) do |env|
          req = Rack::Request.new(env)
          shell.current_move= req["move"]
          game = req.session[:game]

          if game
            shell.do_game_turn(game)
          end

          shell.render_game(game)
        end

        return shell
      end

      def initialize(router)
        @router = router

        @will_block = true
        @can_retry  = false
      end
      include TicTacToe::Core::Player

      def get_move(_)
        unless current_move.nil?
          move = current_move
          @current_move = nil
          Integer(move)
        end
      end

      def set_marks(_, _)
      end

      def call(env)
        @router.match(env)
      end

      def get_players(req)
        [get_player(req["player1"]),
         get_player(req["player2"])]
      end

      def do_game_turn(game)
        game.next_turn
      end

      def render_game(game)
        if game && !game.finished?
          TicTacToe::Web::View::Game.render(game)
        elsif game && game.finished?
          TicTacToe::Web::View::FinishedGame.render(game)
        else
          "No game was found for this session."
        end
      end

      private
      def get_player(type)
        case type
        when "h", "human"
          return self
        when "r", "random"
          return TicTacToe::Core::Player::Random.new(Random.new)
        when "a", "ai"
          return TicTacToe::Core::Player::Minimax.new
        end
      end<commit_msg>Inline do_turn method in RackShell<commit_after>require 'json'

require 'rack_tac_toe'
require 'tic_tac_toe/core/player'

module TicTacToe
  module Web

    class RackShell
      attr_accessor :current_move

      def self.new_shell
        router = TicTacToe::Web::Router.new
        shell = RackShell.new(router)

        router.add_route("/", :GET) do |_|
          TicTacToe::Web::View::Home.render(nil)
        end

        router.add_route("/new-game", :POST) do |env|
          req = Rack::Request.new(env)
          game = TicTacToe::Core::Game.new_game
          game.set_players(*shell.get_players(req))
          req.session[:game] = game

          TicTacToe::Web::View::Game.render(game)
        end

        router.add_route("/make-move", :POST) do |env|
          req = Rack::Request.new(env)
          shell.current_move= req["move"]
          game = req.session[:game]

          game.next_turn unless game.nil?

          shell.render_game(game)
        end

        return shell
      end

      def initialize(router)
        @router = router

        @will_block = true
        @can_retry  = false
      end
      include TicTacToe::Core::Player

      def get_move(_)
        unless current_move.nil?
          move = current_move
          @current_move = nil
          Integer(move)
        end
      end

      def set_marks(_, _)
      end

      def call(env)
        @router.match(env)
      end

      def get_players(req)
        [get_player(req["player1"]),
         get_player(req["player2"])]
      end

      def render_game(game)
        if game && !game.finished?
          TicTacToe::Web::View::Game.render(game)
        elsif game && game.finished?
          TicTacToe::Web::View::FinishedGame.render(game)
        else
          "No game was found for this session."
        end
      end

      private
      def get_player(type)
        case type
        when "h", "human"
          return self
        when "r", "random"
          return TicTacToe::Core::Player::Random.new(Random.new)
        when "a", "ai"
          return TicTacToe::Core::Player::Minimax.new
        end
      end
{'fraction_non_alphanumeric': 0.10853968988660033, 'fraction_numerical': 0.0009257116408238834, 'mean_word_length': 1.849044166117337, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2343127', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1381, 'n_words': 272}