Пример #1
0
 public void DestinyPositionValidation(Position origin, Position destiny)
 {
     if (!Board.ChessPiece(origin).CanMoveTo(destiny))
     {
         throw new ChessBoardException("Posição de Destino inválida!");
     }
 }
Пример #2
0
        public override bool[,] PossibleMovements()
        {
            bool[,] chessmanPossibleMoves = new bool[Board.Rows, Board.Columns];

            Position movementPosition = new Position(0, 0);

            movementPosition.SetValues(PiecePosition.Row - 1, PiecePosition.Column - 1);
            while (Board.ValidatePosition(movementPosition) && CanMove(movementPosition))
            {
                chessmanPossibleMoves[movementPosition.Row, movementPosition.Column] = true;
                if (Board.ChessPiece(movementPosition) != null && Board.ChessPiece(movementPosition).PieceColor != PieceColor)
                {
                    break;
                }
                movementPosition.SetValues(PiecePosition.Row - 1, PiecePosition.Column - 1);
            }

            movementPosition.SetValues(PiecePosition.Row - 1, PiecePosition.Column + 1);
            while (Board.ValidatePosition(movementPosition) && CanMove(movementPosition))
            {
                chessmanPossibleMoves[movementPosition.Row, movementPosition.Column] = true;
                if (Board.ChessPiece(movementPosition) != null && Board.ChessPiece(movementPosition).PieceColor != PieceColor)
                {
                    break;
                }
                movementPosition.SetValues(PiecePosition.Row - 1, PiecePosition.Column + 1);
            }

            movementPosition.SetValues(PiecePosition.Row + 1, PiecePosition.Column + 1);
            while (Board.ValidatePosition(movementPosition) && CanMove(movementPosition))
            {
                chessmanPossibleMoves[movementPosition.Row, movementPosition.Column] = true;
                if (Board.ChessPiece(movementPosition) != null && Board.ChessPiece(movementPosition).PieceColor != PieceColor)
                {
                    break;
                }
                movementPosition.SetValues(PiecePosition.Row + 1, PiecePosition.Column + 1);
            }

            movementPosition.SetValues(PiecePosition.Row + 1, PiecePosition.Column - 1);
            while (Board.ValidatePosition(movementPosition) && CanMove(movementPosition))
            {
                chessmanPossibleMoves[movementPosition.Row, movementPosition.Column] = true;
                if (Board.ChessPiece(movementPosition) != null && Board.ChessPiece(movementPosition).PieceColor != PieceColor)
                {
                    break;
                }
                movementPosition.SetValues(PiecePosition.Row + 1, PiecePosition.Column - 1);
            }

            return(chessmanPossibleMoves);
        }
Пример #3
0
 public void OriginPositionValidation(Position position)
 {
     if (Board.ChessPiece(position) == null)
     {
         throw new ChessBoardException("Não existe peça na posição de origem escolhida!");
     }
     if (CurrentPlayer != Board.ChessPiece(position).PieceColor)
     {
         throw new ChessBoardException("A peça de origem escolhida não é sua!");
     }
     if (!Board.ChessPiece(position).PossibleMovementsExists())
     {
         throw new ChessBoardException("Não há movimentos possíveis para a peça de origem escolhida!");
     }
 }
Пример #4
0
        private bool CanMove(Position position)
        {
            Chessman chessman = Board.ChessPiece(position);

            return(chessman == null || chessman.PieceColor != PieceColor);
        }
Пример #5
0
 private bool Empty(Position position)
 {
     return(Board.ChessPiece(position) == null);
 }
Пример #6
0
        private bool ExistEnemy(Position position)
        {
            Chessman chessman = Board.ChessPiece(position);

            return(chessman != null && chessman.PieceColor != PieceColor);
        }