void CrazyhouseBoard::generateMovesForPiece(QVarLengthArray<Move>& moves,
					    int pieceType,
					    int square) const
{
	// Generate drops
	if (square == 0)
	{
		const int size = arraySize();
		const int maxRank = height() - 2;
		for (int i = 0; i < size; i++)
		{
			Piece tmp = pieceAt(i);
			if (!tmp.isEmpty())
				continue;
			if (pieceType == Pawn)
			{
				Square sq(chessSquare(i));
				if (sq.rank() < 1 || sq.rank() > maxRank)
					continue;
			}

			moves.append(Move(0, i, pieceType));
		}
	}
	else
		WesternBoard::generateMovesForPiece(moves, pieceType, square);
}
/*! Returns true if the king of \a side can reach the eighth rank */
bool RacingKingsBoard::canFinish(Side side)
{
	QVarLengthArray<Move> moves;
	WesternBoard::generateMovesForPiece(moves, King, kingSquare(side));
	for (const Move& m: moves)
	{
		Square targetSq = chessSquare(m.targetSquare());
		if (targetSq.rank() == 7
		&&  vIsLegalMove(m) )
			return true;
	}
	return false;
}
Exemple #3
0
bool HordeBoard::vIsLegalMove(const Move& m)
{
	if (!StandardBoard::vIsLegalMove(m))
		return false;

	/*
	 * Workaround for Stockfish (lichess.org) asymmetry:
	 * accept en passant on 3rd (6th) rank only.
	 */
	int src = m.sourceSquare();
	int tgt = m.targetSquare();
	Piece piece = pieceAt(src);

	if (piece.type() != Pawn
	|| tgt != enpassantSquare())
		return true;

	int targetRank = chessSquare(tgt).rank();
	return targetRank == 2 || targetRank == height() - 3;
}
/*! Returns true if the king of \a side is on the eighth rank */
bool RacingKingsBoard::finished(Side side) const
{
	Square ksq = chessSquare(kingSquare(side));
	return (ksq.rank() == 7);
}