search.rb
# Determines whether the current side king is being attacked or not..
Determines whether the current side king is being attacked or not
Determines whether the current side king is being attacked or not
def in_check?
    k = @kings[@mx]
    8.times do |i|
      if @squares[k + STEP[i]] == N
        return true if @colors[k + STEP[i]] == @mn
      end
      sq = k + OCTL[i]
      sq += OCTL[i] while @colors[sq] == EMPTY
      next unless @colors[sq] == @mn
      case @squares[sq]
      when Q; return true
      when B; return true if i < 4
      when R; return true if i > 3
      when P; return true if k + DIR[@mx] - 1 == sq || k + DIR[@mx] + 1 == sq
      when K; return true if sq - (k + OCTL[i]) == 0
      else next end
    end
    false
  end
def in_check? k = @kings [ @mx ] 8 . times do | i | if @squares [ k + STEP [ i ] ] == N return true if @colors [ k + STEP [ i ] ] == @mn end sq = k + OCTL [ i ] sq += OCTL [ i ] while @colors [ sq ] == EMPTY next unless @colors [ sq ] == @mn case @squares [ sq ] when Q ; return true when B ; return true if i < 4 when R ; return true if i > 3 when P ; return true if k + DIR [ @mx ] - 1 == sq || k + DIR [ @mx ] + 1 == sq when K ; return true if sq - ( k + OCTL [ i ] ) == 0 else next end end false end
Determines whether the current side king is being attacked or not..
Determines whether the current side king is being attacked or not ..