protected virtual List <Drop> GetValidDrops(Player player, Position on, bool returnIfAny) { ChessUtilities.ThrowIfNull(on, nameof(on)); if (GetPieceAt(on) != null || WhoseTurn != player) { return(new List <Drop>()); } if (WouldBeInCheckAfter(new Drop(new Queen(player), on, player), player)) { return(new List <Drop>()); } bool isValidForPawns = on.Rank != 1 && on.Rank != 8; var valid = new List <Drop>(); foreach (Piece p in (player == Player.White ? whitePocket : blackPocket)) { if (p is Pawn && !isValidForPawns) { continue; } var d = new Drop(p, on, player); if (!valid.Contains(d)) { valid.Add(d); if (returnIfAny) { return(valid); } } } return(valid); }
public virtual bool ApplyDrop(Drop drop, bool alreadyValidated) { ChessUtilities.ThrowIfNull(drop, nameof(drop)); if (!alreadyValidated && !IsValidDrop(drop)) { return(false); } SetPieceAt(drop.Destination.File, drop.Destination.Rank, drop.ToDrop); (drop.Player == Player.White ? whitePocket : blackPocket).Remove(drop.ToDrop); i_halfMoveClock++; if (drop.Player == Player.Black) { i_fullMoveNumber++; } WhoseTurn = ChessUtilities.GetOpponentOf(WhoseTurn); AddDetailedMove(new CrazyhouseDetailedMove(drop, "")); // placeholder without SAN for IsCheckmated/IsInCheck string san = string.Format("{0}@{1}{2}", drop.ToDrop is Pawn ? "" : char.ToUpperInvariant(drop.ToDrop.GetFenCharacter()).ToString(), drop.Destination.ToString().ToLowerInvariant(), IsCheckmated(WhoseTurn) ? "#" : (IsInCheck(WhoseTurn) ? "+" : "")); RemoveLastDetailedMove(); AddDetailedMove(new CrazyhouseDetailedMove(drop, san)); return(true); }
public virtual bool WouldBeInCheckAfter(Drop drop, Player player) { var copy = new CrazyhouseChessGame(GetFen()); copy.SetPieceAt(drop.Destination.File, drop.Destination.Rank, drop.ToDrop); return(copy.IsInCheck(player)); }
public virtual bool WouldBeInCheckAfter(Drop drop, Player player) { CrazyhouseChessGame copy = new CrazyhouseChessGame(GetFen()); copy.ApplyDrop(drop, true); return(copy.IsInCheck(player)); }
protected virtual bool IsValidDrop(Drop drop, bool validateCheck, bool careAboutWhoseTurnItIs) { ChessUtilities.ThrowIfNull(drop, nameof(drop)); if (careAboutWhoseTurnItIs && drop.Player != WhoseTurn) { return(false); } if (GetPieceAt(drop.Destination) != null) { return(false); } if (drop.Player == Player.White) { if (!whitePocket.Contains(drop.ToDrop)) { return(false); } } else { if (!blackPocket.Contains(drop.ToDrop)) { return(false); } } if (drop.ToDrop is Pawn) { if (drop.Destination.Rank == 1 || drop.Destination.Rank == 8) { return(false); } } if (validateCheck) { if (WouldBeInCheckAfter(drop, drop.Player)) { return(false); } } return(true); }
public virtual bool ApplyDrop(Drop drop, bool alreadyValidated) { ChessUtilities.ThrowIfNull(drop, "drop"); if (!alreadyValidated && !IsValidDrop(drop)) { return(false); } SetPieceAt(drop.Destination.File, drop.Destination.Rank, drop.ToDrop); (drop.Player == Player.White ? whitePocket : blackPocket).Remove(drop.ToDrop); i_halfMoveClock++; if (drop.Player == Player.Black) { i_fullMoveNumber++; } WhoseTurn = ChessUtilities.GetOpponentOf(WhoseTurn); AddDetailedMove(new CrazyhouseDetailedMove(drop)); return(true); }
public override bool HandleSpecialPgnMove(string move, Player player) { if (move.Length != 3 && move.Length != 4) { throw new PgnException("Crazyhouse drop has to be 3 or 4 letters."); } Drop d = null; if (move.Length == 3) { d = new Drop(new Pawn(player), new Position(move.Remove(0, 1)), player); } else { d = new Drop(MapPgnCharToPiece(move[0], player), new Position(move.Remove(0, 2)), player); } if (!ApplyDrop(d, false)) { throw new PgnException("Invalid crazyhouse drop: " + move); } return(false); }
public CrazyhouseDetailedMove(Drop drop) { IsDrop = true; _drop = drop; Player = drop.Player; }
public bool IsValidDrop(Drop drop) { return(IsValidDrop(drop, true, true)); }