The king is the most important piece in chess, and if a players king is put in checkmate, the game is over. The king can move one square horizontally, vertically, or diagonally, unless the move would place the king in check or the square is already occupied by a friendly piece). The king can capture an undefended enemy piece if it is occupying an adjacent square). The king can also make a special move called castling, in conjunction with a rook of the same color, where the king moves two squares horizontally towards one of its rooks, and that rook is placed on the square over which the king crossed). Castling is permissible under certain conditions, such as neither the king nor the castling rook having previously moved). The king can never move into check, and if a king is put in check, it must get out of check. The kings movement is limited compared to other chess pieces, and it is usually kept safe and protected behind friendly pawns in the opening and middlegame). However, in the endgame, the king can play an active role as an offensive piece and assist in capturing the opponents pieces).