<commit_before>require 'pry'
require 'colorize'

class Board
  attr_accessor :pieces

  COLS = 7
  ROWS = 6

  def initialize
    @pieces = [
      [:black, :black, :orange, :orange, :black, :black],
      [:black, nil, :white, :orange, nil, :black],
      [:red, :white, nil, :orange, nil, nil],
      [:white, nil, nil, :yellow, nil, nil],
      [:red, nil, nil, nil, nil, nil],
      [:black, nil, nil, nil, nil, :black],
      [:black, :black, nil, nil, :black, :black]
    ]
  end

  def draw
    ROWS.times do |i|
      row(ROWS - 1 - i).each do |char|
        print "\u25A0 ".colorize(char || :light_black).bold
      end
      print "\n"
    end
  end

  def won?
    ROWS.times.find do |r|
      COLS.times.find do |c|
        point_won?(r, c)
      end
    end
  end

  def point_won?(row, column)
    possible_wins(row, column).find do |items|
      items.compact.size == 4 and items.uniq.length == 1
    end
  end

  def possible_wins(row, column)
    directions = {n: [-1, 0], w: [0, -1], nw: [-1, -1], ne: [-1, 1]}
    directions.keys.map do |direction|
      relative_direction = directions[direction]
      (0..3).map do |i|
        x = row + (relative_direction[0] * i)
        y = column + (relative_direction[1] * i)
        pieces[x][y] if x >= 0 and y >= 0
      end
    end
  end

  def row(id)
    pieces.collect { |el| el[id] }
  end

  def column(id)
    pieces[id]
  end

end

board = Board.new
board.draw
if board.won?
  puts "Somebody won!"
else
  puts "Fail."
end
<commit_msg>Add dynamic board and ability to place pieces dynamically.<commit_after>require 'pry'
require 'colorize'

class Board
  attr_accessor :pieces

  COLS = 7
  ROWS = 6

  def initialize
    @pieces = ([nil] * COLS).map { [nil] * ROWS }
  end

  def draw
    ROWS.times do |i|
      row(ROWS - 1 - i).each do |char|
        print "\u25A0 ".colorize(char || :light_black).bold
      end
      print "\n"
    end
  end

  def won?
    ROWS.times.find do |r|
      COLS.times.find do |c|
        point_won?(r, c)
      end
    end
  end

  def point_won?(row, column)
    possible_wins(row, column).find do |items|
      items.compact.size == 4 and items.uniq.length == 1
    end
  end

  def possible_wins(row, column)
    directions = {n: [-1, 0], w: [0, -1], nw: [-1, -1], ne: [-1, 1]}
    directions.keys.map do |direction|
      relative_direction = directions[direction]
      (0..3).map do |i|
        x = row + (relative_direction[0] * i)
        y = column + (relative_direction[1] * i)
        pieces[x][y] if x >= 0 and y >= 0
      end
    end
  end

  def place(col, val)
    id = column(col).each_with_index.find { |el, i| el.nil? }[1]
    column(col)[id] = val
  end

  def row(id)
    pieces.collect { |el| el[id] }
  end

  def column(id)
    pieces[id]
  end
end

board = Board.new

while !board.won?
  board.draw
  print 'What would you like to do: '
  input = gets.chomp
  unless input.match /\A[^\d]/
    board.place(input.to_i, :red)
  end
end
board.draw

{'fraction_non_alphanumeric': 0.14789915966386555, 'fraction_numerical': 0.015126050420168067, 'mean_word_length': 2.263157894736842, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '4053090', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1120, 'n_words': 330}