module CastleHelpers
Public Instance Methods
black_castle(column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 29 def black_castle(column) if short_castle?(column) @short_castle = true at(7,7) else @short_castle = false at(0,7) end end
castle(piece, column, row)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 2 def castle(piece, column, row) validate_castle(piece, column) update_castles_after_king_move(piece.color) execute_castle(piece, column, row) end
castling_rook(piece, column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 43 def castling_rook(piece, column) select_rook(piece, column) end
execute_castle(piece, column, row)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 12 def execute_castle(piece, column, row) piece.move(column, row) lngth = @short_castle ? 2 : 3 @castling_rook = castling_rook(piece, column) @castling_rook.move((@castling_rook.column - lngth).abs, row) end
rook_moved?(piece, column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 39 def rook_moved?(piece, column) castling_rook(piece, column)&.moved end
select_rook(piece, column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 47 def select_rook(piece, column) if piece.row == 0 white_castle(column) elsif piece.row == 7 black_castle(column) end end
short_castle?(column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 55 def short_castle?(column) column == 6 end
validate_castle(piece, column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 8 def validate_castle(piece, column) !piece.moved && !rook_moved?(piece, column) && fen_allows?(piece,column) end
white_castle(column)
click to toggle source
# File lib/bchess/helpers/castle_helpers.rb, line 19 def white_castle(column) if short_castle?(column) @short_castle = true at(7,0) else @short_castle = false at(0,0) end end