<commit_before>class Skirmish::Turn < ActiveRecord::Base
  belongs_to :game, class_name: 'Skirmish::Game'
  has_many :moves, class_name: 'Skirmish::Move', dependent: :destroy

  def self.add_move(move, game)
    turn = current_turn_for_game(game)
    turn.moves << move

    if game.player_count > 1 && game.player_count == turn.moves.count
      Skirmish::Game.process_turn(turn)
    end
  end

  def self.current_turn_for_game(game)
    turn = where(game_id: game.id).order('created_at DESC').limit(1).first
    turn ||= Skirmish::Turn.create(game_id: game.id)
    turn
  end
end
<commit_msg>Retrieve most recent completed game turn instead of first<commit_after>class Skirmish::Turn < ActiveRecord::Base
  belongs_to :game, class_name: 'Skirmish::Game'
  has_many :moves, class_name: 'Skirmish::Move', dependent: :destroy

  def self.add_move(move, game)
    turn = current_turn_for_game(game)
    turn.moves << move

    if game.player_count > 1 && game.player_count == turn.moves.count
      Skirmish::Game.process_turn(turn)
    end
  end

  # todo need test to ensure it returns the correct turn
  def self.current_turn_for_game(game)
    turn = where(game_id: game.id, completed: false).first
    turn ||= Skirmish::Turn.create(game_id: game.id)
    turn
  end
end

{'fraction_non_alphanumeric': 0.11547525530243519, 'fraction_numerical': 0.002356637863315004, 'mean_word_length': 4.242798353909465, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, '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': '6930150', 'n_tokens_mistral': 447, 'n_tokens_neox': 440, 'n_words': 99}