search.rb
# Constructs two arrays to represent the pieces in the positions designated by the current
#   FEN position.  Two single dimension 120 length arrays are used to represent the board
#   The additional squares are used as padding to avoid the costly amount of
#   conditional statements involved in moving a knight
Constructs two arrays to represent the pieces in the positions designated by the current
FEN position.  Two single dimension 120 length arrays are used to represent the board
The additional squares are used as padding to avoid the costly amount of
conditional statements involved in moving a knight
Constructs two arrays to represent the pieces in the positions designated by the current FEN position . Two single dimension 120 length arrays are used to represent the board The additional squares are used as padding to avoid the costly amount of conditional statements involved in moving a knight
def make_board
    @colors, @squares = Array.new(120) { 6 }, Array.new(120) { 6 }
    @kings, piece_count = [nil, nil], 0
    120.times do |i|
      if i < 21 || i % 10 == 0 || i % 10 == 9 || i > 98
        @colors[i], @squares[i] = -1, -1
      end
    end
    @fen.split.first.split('/').map do |row|
        row.chars.map { |sq| sq.between?('1', '8') ? sq.to_i.times.map { '6' } : sq }
    end.flatten.each_with_index do |sq, i|
      color, piece = FEN[sq][0], FEN[sq][1]
      @colors[SQ[i]], @squares[SQ[i]] = color, piece
      piece_count += 1 if piece != EMPTY
      @kings[color] = SQ[i] if piece == K
    end
    @stage = piece_count < 16 ? LATE : MID
    nil
  end
def make_board @colors , @squares = Array . new ( 120 ) { 6 } , Array . new ( 120 ) { 6 } @kings , piece_count = [ nil , nil ] , 0 120 . times do | i | if i < 21 || i % 10 == 0 || i % 10 == 9 || i > 98 @colors [ i ] , @squares [ i ] = - 1 , - 1 end end @fen . split . first . split ( '/' ) . map do | row | row . chars . map { | sq | sq . between? ( '1' , '8' ) ? sq . to_i . times . map { '6' } : sq } end . flatten . each_with_index do | sq , i | color , piece = FEN [ sq ] [ 0 ] , FEN [ sq ] [ 1 ] @colors [ SQ [ i ] ] , @squares [ SQ [ i ] ] = color , piece piece_count += 1 if piece != EMPTY @kings [ color ] = SQ [ i ] if piece == K end @stage = piece_count < 16 ? LATE : MID nil end
Constructs two arrays to represent the pieces in the positions designated by the current
FEN position.
Constructs two arrays to represent the pieces in the positions designated by the current FEN position .