<commit_before>require 'bundler/setup'
Bundler.require(:default)
require_relative 'warcards/gameplay'
require 'querinator'

module Cardgame
  class Game
    def initialize
      @questions = Querinator::Game.new.get_questions
      @deck      = Deck.new
      @player    = Player.new
      @ai        = Ai.new
      @gameplay  = Gameplay.new(:deck => @deck, :player => @player, :ai => @ai)
      @gameplay.shuffle
      @gameplay.deal
    end

    def run
      loop do
        @gameplay.game_over?
        @gameplay.rearm?
        @gameplay.show_cards
        @gameplay.war?
        result = @gameplay.contest

        output_cli(result)

        continue?
        @gameplay.discard(result)
      end
    end

    def output_cli(result)
      puts "#{result[:winner].name} won"
      puts "Player has #{@gameplay.player.stack.length + @gameplay.player.discard.length + 1} cards.\tAI has #{@gameplay.ai.stack.length + @gameplay.ai.discard.length + 1} cards."
      if result[:winner] == @gameplay.player
        if test_player
          puts "Correct! Yay!"
        else
          puts "Oooh. I'm sorry. The correct answer was 'TODO'. #{@gameplay.ai.name} became the winner."
          result[:winner] = @gameplay.ai
        end
      else
        if test_ai
          puts "Ai was correct."
        else
          puts "Ai was wrong. #{@gameplay.player.name} became the winner!"
          result[:winner] = @gameplay.player
        end
      end
    end

    def continue?
      puts "go again?\n"
      next_round = gets
      if next_round.downcase.chomp.include? "n"
        puts "You ended the game"
        exit
      end
    end

    def test_player
      question = @questions.sample
      puts question.pose
      answer = gets<commit_msg>extracted methods to simplify. ended up creating long chain of methods passing the same object along step-by-step. Not sure this is good or bad.<commit_after>require 'bundler/setup'
Bundler.require(:default)
require_relative 'warcards/gameplay'
require 'querinator'

module Cardgame
  class Game
    def initialize
      @questions = Querinator::Game.new.get_questions
      @deck      = Deck.new
      @player    = Player.new
      @ai        = Ai.new
      @gameplay  = Gameplay.new(:deck => @deck, :player => @player, :ai => @ai)
      @gameplay.shuffle
      @gameplay.deal
    end

    def run
      loop do
        @gameplay.game_over?
        @gameplay.rearm?
        @gameplay.show_cards
        @gameplay.war?
        result = @gameplay.contest

        output_cli(result)

        continue?
        @gameplay.discard(result)
      end
    end

    def output_cli(result)
      puts "#{result[:winner].name} won"
      puts "Player has #{@gameplay.player.stack.length + @gameplay.player.discard.length + 1} cards.\tAI has #{@gameplay.ai.stack.length + @gameplay.ai.discard.length + 1} cards."
      challenge_participants(result)
    end

    def challenge_participants(result)
      if result[:winner] == @gameplay.player
        challenge_player(result)
      else
        challenge_ai(result)
      end
    end

    def challenge_ai(result)
      if test_ai
        puts "Ai was correct."
      else
        puts "Ai was wrong. #{@gameplay.player.name} became the winner!"
        result[:winner] = @gameplay.player
      end
    end

    def challenge_player(result)
      if test_player
        puts "Correct! Yay!"
      else
        puts "Oooh. I'm sorry. The correct answer was 'TODO'. #{@gameplay.ai.name} became the winner."
        result[:winner] = @gameplay.ai
      end
    end

    def continue?
      puts "go again?\n"
      next_round = gets
      if next_round.downcase.chomp.include? "n"
        puts "You ended the game"
        exit
      end
    end

    def test_player
      question = @questions.sample
      puts question.pose
      answer = gets
{'fraction_non_alphanumeric': 0.10156657963446475, 'fraction_numerical': 0.0010443864229765013, 'mean_word_length': 2.124796084828711, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '2044915', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1194, 'n_words': 304}