<commit_before>class Player  

  attr_reader :mark

  def initialize(mark)
    @mark = mark
    puts "Player #{mark} initialized."
  end

  def choose_move(board, winning_combos)
    open_positions = board.all_open_positions
    puts "Considering the following positions #{open_positions}."
    # can I win
    move = choose_winning_move_if_available(open_positions, board, winning_combos)
    if move
      return move
    end
    
    move = prevent_winning_move_if_necessary(open_positions, board, winning_combos)
    if move
      return move
    end

    move = choose_probable_winning_move(open_positions, board, winning_combos)
    if move
      return move
    end

    #choose random open position
    open_positions[rand(open_positions.length)]
  end

  def choose_winning_move_if_available(open_positions, board, winning_combos)
    open_positions.each do |position|
      winning_combos.each do |combo|
        if combo.include? position then
          if (2 == board.board_state.chars.values_at(*combo).count(@mark)) then
            puts "Found a winning move for #{@mark}."
            return position
          end
        end
      end
    end
    nil
  end<commit_msg>Added notes of situations to check for in playing.<commit_after>class Player  

  attr_reader :mark

  def initialize(mark)
    @mark = mark
    puts "Player #{mark} initialized."
  end

  def choose_move(board, winning_combos)
    open_positions = board.all_open_positions
    puts "Considering the following positions #{open_positions}."
    # can I win
    move = choose_winning_move_if_available(open_positions, board, winning_combos)
    if move
      return move
    end
    # can I prevent a win   
    move = prevent_winning_move_if_necessary(open_positions, board, winning_combos)
    if move
      return move
    end
    # can I set up a guaranteed win (two places to go next time)
    #
    # can I prevent a guaranteed win

    # can I line up two in a row with an empty space?
    move = choose_probable_winning_move(open_positions, board, winning_combos)
    if move
      return move
    end

    # can I prevent a probable vin
    #
    # can I create a potential win (one mare with two empty spaces)
    #
    # can I prevent a potential win
    #
    # can I move at all

    #choose random open position
    open_positions[rand(open_positions.length)]
  end

  def choose_winning_move_if_available(open_positions, board, winning_combos)
    open_positions.each do |position|
      winning_combos.each do |combo|
        if combo.include? position then
          if (2 == board.board_state.chars.values_at(*combo).count(@mark)) then
            puts "Found a winning move for #{@mark}."
            return position
          end
        end
      end
    end
    nil
  end
{'fraction_non_alphanumeric': 0.06409794742527908, 'fraction_numerical': 0.0007202016564638099, 'mean_word_length': 2.743935309973046, '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': '6116350', 'n_tokens_mistral': 841, 'n_tokens_neox': 805, 'n_words': 258}