Пример #1
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && boardLogic.IsDiagonalEmpty(x1, y1, x2, y2, board)))
                        {
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                    }

                    if (!board.IsEmpty(x2, y2) && !boardLogic.IsAlly(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        if ((Math.Abs(x2 - x1) == Math.Abs(y2 - y1) && boardLogic.IsDiagonalEmpty(x1, y1, x2, y2, board)))
                        {
                            board.Remove(x2, y2);
                            board.Move(x1, y1, x2, y2);
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Пример #2
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                if (!board.IsEmpty(x1, y1) && IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (board.IsEmpty(x2, y2) && !boardLogic.IsCastling(x1, y1, x2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Move(x1, y1, x2, y2);
                        boardLogic.CastlingChanges(x1, y1, x2, y2, this);
                        return(true);
                    }

                    if (!board.IsEmpty(x2, y2) && !boardLogic.IsAlly(x1, y1, x2, y2, board) && !boardLogic.IsCastling(x1, y1, x2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Remove(x2, y2);
                        board.Move(x1, y1, x2, y2);
                        boardLogic.CastlingChanges(x1, y1, x2, y2, this);
                        return(true);
                    }

                    if (board.IsEmpty(x2, y2) && boardLogic.IsCastling(x1, y1, x2, board) && boardLogic.CanCastling(x1, y1, x2, board))
                    {
                        board.Move(x1, y1, x2, y2);
                        boardLogic.MoveRookCastling(x1, y1, x2, board);
                        CanCastling = false;
                        return(true);
                    }
                }
            }

            return(false);
        }
Пример #3
0
        public void IsInRange(int x1, int y1, int x2, int y2, bool expected)
        {
            // Arrange
            var board = new BoardLogic(true);

            // Act
            var result = board.IsInRange(x1, y1, x2, y2);

            // Assert
            Assert.AreEqual(expected, result);
        }
Пример #4
0
        public override bool LogicMove(int x1, int y1, int x2, int y2, Board board, BoardLogic boardLogic)
        {
            if (boardLogic.IsInRange(x1, y1, x2, y2))
            {
                PieceBase piece = board.GetPiece(x1, y1);
                if (!board.IsEmpty(x1, y1) && piece.IsValidMove(x1, y1, x2, y2, board.Turn, board))
                {
                    if (boardLogic.IsPawnCapturing(x1, x2) && !board.IsEmpty(x2, y2) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Remove(x2, y2);
                        board.Move(x1, y1, x2, y2);
                        if (boardLogic.Promoting(y2))
                        {
                            board.Promotion(x2, y2, board.Turn);
                        }
                        return(true);
                    }

                    if (boardLogic.IsPawnCapturing(x1, x2) && boardLogic.EnPassant(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.RemoveCapturePassant(x1, y1, x2, y2);
                        board.Move(x1, y1, x2, y2);
                        return(true);
                    }

                    if (!boardLogic.IsPawnCapturing(x1, x2) && board.IsEmpty(x2, y2) && boardLogic.IsLineEmpty(x1, y1, x2, y2, board) && !boardLogic.CantMoveIsCheck(x1, y1, x2, y2, board))
                    {
                        board.Move(x1, y1, x2, y2);
                        boardLogic.UpDateEnPassant(y1, y2, piece, board);
                        if (boardLogic.Promoting(y2))
                        {
                            board.Promotion(x2, y2, board.Turn);
                        }
                        return(true);
                    }
                }
            }

            return(false);
        }