コード例 #1
0
        public void ToString_WhenKingSideWhite_ShouldBeOO()
        {
            // Arrange
            var move = new CastleMove(
                new SimpleMove(new Point(4, 0), new Point(6, 0)),
                new SimpleMove(new Point(7, 0), new Point(5, 0))
                );

            // Act
            var result = move.ToString();

            // Assert
            result.Should().Be("O-O");
        }
コード例 #2
0
        public void ToString_WhenQueenSideBlack_ShouldBeOOO()
        {
            // Arrange
            var move = new CastleMove(
                new SimpleMove(new Point(4, 7), new Point(2, 7)),
                new SimpleMove(new Point(0, 7), new Point(3, 7))
                );

            // Act
            var result = move.ToString();

            // Assert
            result.Should().Be("O-O-O");
        }
コード例 #3
0
        public void ApplyCastleMove(CastleMove move)
        {
            bool applied = false;

            foreach (QuantumHarmonic harmonic in Harmonics_)
            {
                if (harmonic.Board.CheckCastleMoveApplicable(move))
                {
                    harmonic.Board.ApplyCastleMove(move);
                    applied = true;
                }
            }
            UpdateQuantumCheckboard();
            AssertionException.Assert(applied, "Ordinary move couldn't be applied on any harmonic");
        }
コード例 #4
0
ファイル: Move.cs プロジェクト: aayush-pokharel/ChessEngine
            public override bool Equals(object obj)
            {
                if (this == obj)
                {
                    return(true);
                }
                if (!(obj.GetType() == typeof(CastleMove)))
                {
                    return(false);
                }
                CastleMove otherMove = (CastleMove)obj;

                return(base.Equals(otherMove) &&
                       this.castleRook.Equals(otherMove.getCastleRook()));
            }
コード例 #5
0
        public void ApplyCastleMove(CastleMove move)
        {
            AssertionException.Assert(CheckCastleMoveApplicable(move), $"Attempted applying inapplicable castle move");
            int c;

            switch (move.ActorPlayer)
            {
            case Player.White:
                c = 0;
                break;

            case Player.Black:
                c = 7;
                break;

            default: throw new AssertionException($"Unsupported player: {move.ActorPlayer}");
            }

            switch (move.CastleType)
            {
            case CastleType.Left:
                this[0, c] = null;
                this[1, c] = null;
                this[2, c] = new Piece(move.ActorPlayer, PieceType.King);
                this[3, c] = new Piece(move.ActorPlayer, PieceType.Rook);
                this[4, c] = null;
                break;

            case CastleType.Right:
                this[4, c] = null;
                this[5, c] = new Piece(move.ActorPlayer, PieceType.Rook);
                this[6, c] = new Piece(move.ActorPlayer, PieceType.King);
                this[7, c] = null;
                break;

            default:
                throw new AssertionException($"Unsupported castle type: {move.CastleType}");
            }
        }
コード例 #6
0
        public bool CheckCastleMoveApplicable(CastleMove move)
        {
            int c;

            switch (move.ActorPlayer)
            {
            case Player.White:
                c = 0;
                break;

            case Player.Black:
                c = 7;
                break;

            default: throw new AssertionException($"Unsupported player: {move.ActorPlayer}");
            }

            switch (move.CastleType)
            {
            case CastleType.Left: return
                    (this[0, c] == new Piece(move.ActorPlayer, PieceType.Rook) &&
                     this[1, c] == null &&
                     this[2, c] == null &&
                     this[3, c] == null &&
                     this[4, c] == new Piece(move.ActorPlayer, PieceType.King));

            case CastleType.Right: return
                    (this[4, c] == new Piece(move.ActorPlayer, PieceType.King) &&
                     this[5, c] == null &&
                     this[6, c] == null &&
                     this[7, c] == new Piece(move.ActorPlayer, PieceType.Rook));

            default:
                throw new AssertionException($"Unsupported castle type: {move.CastleType}");
            }
        }
コード例 #7
0
ファイル: CastleBehaviour.cs プロジェクト: Beeboh/Chess
        public override ReadOnlyCollection <Move> GetCandidateMoves(BoardState board, ChessPiece piece)
        {
            List <Move> CandidateMoves = new List <Move>();

            if (!piece.HasMoved)
            {
                int RookRow    = piece.Row + YRookSearch * RookSearchRange;
                int RookColumn = piece.Column + XRookSearch * RookSearchRange;
                if (board.ValidTile(RookRow, RookColumn))
                {
                    Tile RookTile = board[RookRow, RookColumn];
                    if (!RookTile.IsVacant)
                    {
                        if (RookTile.Piece is Rook)
                        {
                            if (!RookTile.Piece.HasMoved)
                            {
                                bool ValidPieceConditions = true;
                                for (int i = 1; i < RookSearchRange; i++)
                                {
                                    int SearchedRow    = piece.Row + i * YRookSearch;
                                    int SearchedColumn = piece.Column + i * XRookSearch;
                                    if (board.ValidTile(SearchedRow, SearchedColumn))
                                    {
                                        Tile intermediateTile = board[SearchedRow, SearchedColumn];
                                        if (!intermediateTile.IsVacant)
                                        {
                                            ValidPieceConditions = false;
                                            break;
                                        }
                                    }
                                    else
                                    {
                                        ValidPieceConditions = false;
                                        break;
                                    }
                                }
                                if (ValidPieceConditions)
                                {
                                    if (board.ValidTile(RookRow + YRookMove, RookColumn + XRookMove))
                                    {
                                        Tile         NewRookTile = board[RookRow + YRookMove, RookColumn + XRookMove];
                                        MovementMove RookMove    = new MovementMove(RookTile, NewRookTile);
                                        ReadOnlyCollection <Tile> CandidateTiles = GetCandidateTiles(board, piece);
                                        foreach (Tile CandidateTile in CandidateTiles)
                                        {
                                            MovementMove PieceMove  = new MovementMove(board[piece.Row, piece.Column], CandidateTile);
                                            Move         CastleMove = new CastleMove(PieceMove, RookMove);
                                            CandidateMoves.Add(CastleMove);
                                        }
                                    }
                                }
                                //targetting movement squares/in check
                                foreach (Tile tile in board.Tiles)
                                {
                                    if (!tile.IsVacant)
                                    {
                                        if (tile.Piece.Alliance != piece.Alliance)
                                        {
                                            //NOT DONE
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(CandidateMoves.AsReadOnly());
        }
コード例 #8
0
 public bool CheckCastleMoveApplicable(CastleMove move)
 {
     return(Harmonics_.Any((h) => h.Board.GameState == GameState.GameStillGoing &&
                           h.Board.CheckCastleMoveApplicable(move)));
 }
コード例 #9
0
 private string FormatCastle(CastleMove move, IChessPieceFormatter pieceFormatter)
 {
     return(move.Type == CastleMoveType.KingSide ? "OO" : "OOO");
 }