8queens.rb
# ==========================================================================
# --------------------------------------------------------------------------
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
#
#   HW #1 CONFLICT_COUNTING FUNCTION:
#
#       ignore hit at current tile
#       hit all in current row & column
#       hit all in current positive and negative diagonals
#
#
# . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
# --------------------------------------------------------------------------
# ==========================================================================



HW #1 CONFLICT_COUNTING FUNCTION.

ignore hit at current tile
hit all in current row & column
hit all in current positive and negative diagonals


HW #1 CONFLICT_COUNTING FUNCTION . ignore hit at current tile hit all in current row & column hit all in current positive and negative diagonals
def update_conflicts(amt=1)
        pos = [@mapx, @mapy]
        i = 0
        j = @mapy
        loop do
            if i == @board.w+1
                break
            end
            if i != @mapx
                @board.at(i,j).hit(amt)
            end
            i += 1
        end
        i = @mapx
        j = 0
        loop do
            if j == @board.h+1
                break
            end
            if j != @mapy
                @board.at(i,j).hit(amt)
            end
            j += 1
        end
        max = pos.max
        min = pos.min
        dif = max - min
        if @mapx == max
            dx = dif
            dy = 0
        else
            dx = 0
            dy = dif
        end
        i = dx
        j = dy
        loop do
            if i == @board.w+1 || j == @board.h+1
                break
            end
            if i != @mapx && j != @mapy
                @board.at(i,j).hit(amt)
            end
            i += 1
            j += 1
        end
        ht = @board.h
        y = ht - @mapy
        x = @mapx
        max = [x,y].max
        min = [x,y].min
        dif = max - min
        if x == max
            dx = dif
            dy = ht
        else
            dx = 0
            dy = ht - dif
        end
        i = dx
        j = dy
        loop do
            if i == @board.w+1 || j < 0
                break
            end
            if i != @mapx && j != @mapy
                @board.at(i,j).hit(amt)
            end
            i += 1
            j -= 1
        end
    end
def update_conflicts ( amt = 1 ) pos = [ @mapx , @mapy ] i = 0 j = @mapy loop do if i == @board . w + 1 break end if i != @mapx @board . at ( i , j ) . hit ( amt ) end i += 1 end i = @mapx j = 0 loop do if j == @board . h + 1 break end if j != @mapy @board . at ( i , j ) . hit ( amt ) end j += 1 end max = pos . max min = pos . min dif = max - min if @mapx == max dx = dif dy = 0 else dx = 0 dy = dif end i = dx j = dy loop do if i == @board . w + 1 || j == @board . h + 1 break end if i != @mapx && j != @mapy @board . at ( i , j ) . hit ( amt ) end i += 1 j += 1 end ht = @board . h y = ht - @mapy x = @mapx max = [ x , y ] . max min = [ x , y ] . min dif = max - min if x == max dx = dif dy = ht else dx = 0 dy = ht - dif end i = dx j = dy loop do if i == @board . w + 1 || j < 0 break end if i != @mapx && j != @mapy @board . at ( i , j ) . hit ( amt ) end i += 1 j -= 1 end end
# for ease
 # left to right
 # stop if border reached
 # top to bottom
 # stop if border reached
 # negative diagonal
 #  (start from topleft)
 # top -> bottom
 # left -> right
 # stop if border reached
 # positive diagonal
 #  (start from bottomleft)
 # bottom -> top
 # left -> right
 # stop if border reached

amt