lib/chess/board.rb
# Given a color, returns true if the color's king is checkmated
Given a color, returns true if the color's king is checkmated
Given a color returns true if the color ' s king is checkmated
def checkmate?(color)
      king = find_king(color)
      return false unless check?(color, king.location)
      checking_pieces = pieces_checking_king(color, king.location)
      if checking_pieces.length == 1
        return false if escape_checkmate_by_kill?(color, checking_pieces[0])
      end
      moves = all_valid_moves(king.location, king.moves)
      moves.all? do |move|
        current_state = Marshal.load(Marshal.dump(@state))
        @state[king.location[0]][king.location[1]] = nil 
        @state[move[0]][move[1]] = King.new(color, move) 
        in_check = check?(color, move)
        @state = current_state 
        in_check
      end
    end
def checkmate? ( color ) king = find_king ( color ) return false unless check? ( color , king . location ) checking_pieces = pieces_checking_king ( color , king . location ) if checking_pieces . length == 1 return false if escape_checkmate_by_kill? ( color , checking_pieces [ 0 ] ) end moves = all_valid_moves ( king . location , king . moves ) moves . all? do | move | current_state = Marshal . load ( Marshal . dump ( @state ) ) @state [ king . location [ 0 ] ] [ king . location [ 1 ] ] = nil @state [ move [ 0 ] ] [ move [ 1 ] ] = King . new ( color , move ) in_check = check? ( color , move ) @state = current_state in_check end end
Given a color, returns true if the color's king is checkmated
Given a color returns true if the color ' s king is checkmated
# To test out the # king's move # Set state back to actual current state
color
<not_specific>