lib/tak/board.rb
# Consider moving this all out into a board formatter later. It'd be cleaner.
#
# May Matz forgive me for my debugging code here.
Consider moving this all out into a board formatter later. It'd be cleaner.
May Matz forgive me for my debugging code here.
Consider moving this all out into a board formatter later . It ' d be cleaner . May Matz forgive me for my debugging code here .
def to_s
      max_size = board.flatten(1).max.join(' ').size + 1
      counts = flat_counts.map { |c, i|
        set = @piece_sets[c]
        "#{c}: #{i} flats, #{set.flats} remaining pieces, #{set.capstones} remaining capstones"
      }.join("\n")
      board_state = board.reverse.map.with_index { |row, i|
        row_head = "  #{size - i} "
        row_head + row.map { |cell|
          "[%#{max_size}s]" % cell.join(' ')
        }.join(' ')
      }.join("\n")
      footer = ('a'..'h').take(size).map { |c| "%#{max_size + 2}s" % c }.join(' ')
      "#{counts}\n\n#{board_state}\n   #{footer}"
    end
def to_s max_size = board . flatten ( 1 ) . max . join ( ' ' ) . size + 1 counts = flat_counts . map { | c , i | set = @piece_sets [ c ] "#{c}: #{i} flats, #{set.flats} remaining pieces, #{set.capstones} remaining capstones" } . join ( "\n" ) board_state = board . reverse . map . with_index { | row , i | row_head = "  #{size - i} " row_head + row . map { | cell | "[%#{max_size}s]" % cell . join ( ' ' ) } . join ( ' ' ) } . join ( "\n" ) footer = ( 'a' .. 'h' ) . take ( size ) . map { | c | "%#{max_size + 2}s" % c } . join ( ' ' ) "#{counts}\n\n#{board_state}\n   #{footer}" end
Consider moving this all out into a board formatter later.
Consider moving this all out into a board formatter later .