/** * Generate legal destinations that will save the King piece from check * * @param king The King piece * @param threat The Piece threatening the King piece */ protected void genLegalDestsSaveKing(Piece king, Piece threat) { if ((isBlack() ? m_board.getGame().getBlackRules() : m_board.getGame().getWhiteRules()) .objectivePiece(isBlack()) == this) return; if (king == null) return; Iterator<Square> oldLegalDests = getLegalDests().iterator(); Square sq = null; if (m_captured) return; List<Square> legalDests = Lists.newArrayList(); setLegalDests(legalDests); while (oldLegalDests.hasNext()) { sq = oldLegalDests.next(); if (threat.isBlockable(sq, king)) getLegalDests().add(sq); else if (sq.equals(threat.getSquare())) getLegalDests().add(sq); } }