//判断城堡当前是否有单位存在 false没有 true有 public bool JudgeCastleHaveUnit(CastleType castleType) { if (castleType == CastleType.ThePlayerCastle) { if (castlePlayer.itemBrick.rolePlayer == null) { return(false); } else { return(true); } } else if (castleType == CastleType.TheEnemyCastle) { if (castleEnemy.itemBrick.rolePlayer == null) { return(false); } else { return(true); } } return(false); }
private static bool CastlingNoPiecesInBetween(King king, Board board, CastleType type) { foreach (var square in king.GetCastleInBetweenPositions(type)) { if (board.IsAnyPieceInSquare(square)) { return(false); } } return(true); }
private static bool CastlePiecesHaveNotBeenMoved(King king, Board board, CastleType castleType) { if (king.HasBeenMoved) { return(false); } var rookSquare = board[king.GetCastleRookStartingSquare(castleType)]; return(rookSquare.Piece != null && !rookSquare.Piece.HasBeenMoved); }
public Castle(King king, Rook rook, Board board, CastleType type) : base(true, king, null, board[king.GetCastleStartingPosition()], board[king.GetCastleEndingPosition(type)], null) { _type = type; _board = board; _rook = rook; _rookStartingPosition = board[King.GetCastleRookStartingSquare(type)]; _rookEndingPosition = board[King.GetCastleRookEndingPosition(type)]; }
internal SquareCoordinate GetCastleEndingPosition(CastleType type) { switch (type) { case CastleType.KingSide: return(new SquareCoordinate(Color.FirstRank, 7)); case CastleType.QueenSide: return(new SquareCoordinate(Color.FirstRank, 3)); default: throw new NotImplementedException(); } }
private bool CanCastle(CastleType castleType) { var castle = this.Board.GetCastleAvailabity(this.Player); if (!castle.HasFlag(castleType)) return false; if (this.Board.IsInCheck()) return false; var testSquare = castleType.GetRookSquare(this.Player); for (int i = 0; i < castleType.GetRookDistance(); i++) { testSquare = testSquare.Move(castleType.GetRookMoveDirection()).Value; if (this.Board[testSquare] != null || this.Board.IsUnderAttack(testSquare, this.Player.Opponent())) return false; } return true; }
internal IEnumerable <SquareCoordinate> GetCastleInBetweenPositions(CastleType type) { switch (type) { case CastleType.KingSide: yield return(new SquareCoordinate(Color.FirstRank, 6)); yield return(new SquareCoordinate(Color.FirstRank, 7)); break; case CastleType.QueenSide: yield return(new SquareCoordinate(Color.FirstRank, 4)); yield return(new SquareCoordinate(Color.FirstRank, 3)); break; default: throw new NotImplementedException(); } }
public static object ConvertType(CastleType type, object value) { switch (type) { case CastleType.UniqueIdentifier: case CastleType.Text: return(value.ToString()); case CastleType.Integer: return(int.Parse(value.ToString())); case CastleType.Float: return(float.Parse(value.ToString())); case CastleType.Boolean: return(bool.Parse(value.ToString())); case CastleType.Flags: return(uint.Parse(value.ToString())); case CastleType.Enum: return(int.Parse(value.ToString())); case CastleType.Image: return(value.ToString()); case CastleType.Color: return(uint.Parse(value.ToString())); case CastleType.Ref: CastleRef refObj = value as CastleRef; if (refObj == null) { return(null); } return(refObj.Referencedstring); } return(null); }
internal ISet <SquareCoordinate> GetCastlingSquares(CastleType type) { switch (type) { case CastleType.KingSide: return(new HashSet <SquareCoordinate> { new SquareCoordinate(Color.FirstRank, 5), new SquareCoordinate(Color.FirstRank, 6), new SquareCoordinate(Color.FirstRank, 7) }); case CastleType.QueenSide: return(new HashSet <SquareCoordinate> { new SquareCoordinate(Color.FirstRank, 5), new SquareCoordinate(Color.FirstRank, 4), new SquareCoordinate(Color.FirstRank, 3) }); default: throw new NotImplementedException(); } }
private static bool CastlingSquaresAreNotControlledByOpponent(King king, Board board, CastleType castleType) { foreach (var square in king.GetCastlingSquares(castleType)) { if (board.IsInOpponentControl(board[square], king.Color)) { return(false); } } return(true); }
public CastleMove(Player actorPlayer, CastleType castleType) { ActorPlayer_ = actorPlayer; CastleType_ = castleType; }
public KingCastleMove(Piece piece, Square target, CastleType castle) : base(piece, target) { this.Castle = castle; }
internal static bool CanCastle(King king, Board board, CastleType castleType) { return(CastlePiecesHaveNotBeenMoved(king, board, castleType) && CastlingNoPiecesInBetween(king, board, castleType) && CastlingSquaresAreNotControlledByOpponent(king, board, castleType)); }
public bool castle(ChessSide side, ColorType color, CastleType castle) { if (!side.King.CanCastle) { debug (Catalog.GetString("Cant castle (") + side.King); return false; } if (side.King.File != ChessBoardConstants.FILE_E) { debug (Catalog.GetString("King not available ") + side.King); return false; } int file; if (castle == CastleType.LONG_CASTLE) { file = ChessBoardConstants.FILE_A; } else { file = ChessBoardConstants.FILE_H; } int rank; if (color == ColorType.WHITE) rank = 0; else rank = 7; if (positions[rank, file] == null) { debug (Catalog.GetString("Rook not available")); return false; } int i1, i2; if (castle == CastleType.LONG_CASTLE) { i1 = ChessBoardConstants.FILE_B; i2 = ChessBoardConstants.FILE_E; } else { i1 = ChessBoardConstants.FILE_F; i2 = ChessBoardConstants.FILE_H; } for (int i = i1; i < i2; i++) { if (positions[rank, i] != null) { // some pieces blocking.. cannot castle return false; } } IList attackers = new ArrayList (); ChessPiece. getAttackers ((color == ColorType. WHITE ? whites : blacks), (color == ColorType. WHITE ? blacks : whites), rank, ChessBoardConstants. FILE_E, positions, null, attackers); // check if king is under attack. // cannot castle in that case if (attackers.Count > 0) { return false; } if (castle == CastleType.LONG_CASTLE) i1 = ChessBoardConstants.FILE_C; for (int i = i1; i < i2; i++) { attackers.Clear (); ChessPiece. getAttackers ((color == ColorType. WHITE ? whites : blacks), (color == ColorType. WHITE ? blacks : whites), rank, i, positions, null, attackers); if (attackers.Count > 0) { // king will be under attack in this case return false; } } if (castle == CastleType.SHORT_CASTLE) { setPiece (side.King, rank, ChessBoardConstants. FILE_G); setPiece (positions [rank, ChessBoardConstants. FILE_H], rank, ChessBoardConstants. FILE_F); removePiece (rank, ChessBoardConstants. FILE_E); removePiece (rank, ChessBoardConstants. FILE_H); lastMoveInfo.movedPiece = side.King; lastMoveInfo.SetInfo (rank, ChessBoardConstants. FILE_E, rank, ChessBoardConstants. FILE_G, true); } else { setPiece (side.King, rank, ChessBoardConstants. FILE_C); setPiece (positions [rank, ChessBoardConstants. FILE_A], rank, ChessBoardConstants. FILE_D); removePiece (rank, ChessBoardConstants. FILE_E); removePiece (rank, ChessBoardConstants. FILE_A); lastMoveInfo.movedPiece = side.King; lastMoveInfo.SetInfo (rank, ChessBoardConstants. FILE_E, rank, ChessBoardConstants. FILE_C, true); } FlipTurn (); return true; }
private void SetCastleAvailability(string text) { CastleType black = (CastleType)0; CastleType white = (CastleType)0; foreach (char c in text) { switch (c) { case 'K': white = white | CastleType.KingSide; break; case 'Q': white = white | CastleType.QueenSide; break; case 'k': black = black | CastleType.KingSide; break; case 'q': black = black | CastleType.QueenSide; break; } } this.BlackCastleAvailability = black; this.WhiteCastleAvailability = white; }
private static string GetNotation(CastleType castleType, PlayerColor color) { string notation = ""; switch (castleType) { case CastleType.KingSide: notation = "k"; break; case CastleType.QueenSide: notation = "q"; break; case CastleType.QueenOrKingSide: notation = "kq"; break; } return color == PlayerColor.White ? notation.ToUpper() : notation.ToLower(); }
private Move GetCastleMove(Board board, King king, CastleType castleType) { var rook = board[king.GetCastleRookStartingSquare(castleType)].Piece as Rook; return(new Castle(king, rook, board, castleType)); }