module Printer

Public Instance Methods

clear_all() click to toggle source
# File lib/printer.rb, line 53
def clear_all
  # Reset counters and clear terminal
  @@cell_number = 1
  system "clear" or system "cls"
end
piece_to_string(piece_name) click to toggle source
# File lib/printer.rb, line 89
def piece_to_string(piece_name)
  # Print pieces as two characters
  #   "pawn" -> "pa" , "bishop" -> "BI" , "king" -> "KI" , ...
  #   print nil as "  " so it takes up a two character width on the printed board
  piece_name == nil ? "  " : piece_name[0..1]
end
print_board(piece_locations) click to toggle source
print_end_of_row(row_num) click to toggle source
print_header() click to toggle source
print_start_of_row(row_num) click to toggle source
printer() { |" "| ... } click to toggle source
# File lib/printer.rb, line 60
def printer
  # Prints the board to terminal, based on layout defined by piece_locations

  clear_all
  print_header

  # Print first cell of each row, with row number
  (1..8).each do |row|
    yield "      "
    yield "  XX  ", "#{row}"
    yield "      "
  end

  print_footer
end
substitute_pieces(text, index, color, background_color, piece_locations) click to toggle source
# File lib/printer.rb, line 76
def substitute_pieces(text, index, color, background_color, piece_locations)
  piece = piece_to_string(piece_locations[index][:type])

  piece.upcase! unless piece == "pa"
  piece = piece.colorize(color)

  if background_color == :white
    text.gsub("XX", piece).on_light_white
  else
    text.gsub("XX", piece).on_light_black
  end
end