コード例 #1
0
ファイル: Knight.cs プロジェクト: joedav/ConsoleChess
        /// <summary>
        /// Possibles movements
        /// </summary>
        /// <returns>Possibles movements of kinight</returns>
        public override bool[,] PossibleMovements()
        {
            bool[,] possiblesMovements = new bool[Board.Rows, Board.Columns];
            Position position = new Position(0, 0);

            for (int i = 0; i < Board.Rows; i++)
            {
                for (int j = 0; j < Board.Columns; j++)
                {
                    position.SetValues(i, j);
                    if ((Board.IsPositionValid(position) && CanMove(position)) && (Position.Row - i == 2 && Position.Column - j == 1) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (Position.Row - i == 2 && j - Position.Column == 1) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (i - Position.Row == 2 && j - Position.Column == 1) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (i - Position.Row == 2 && Position.Column - j == 1) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (Position.Row - i == 1 && Position.Column - j == 2) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (Position.Row - i == 1 && j - Position.Column == 2) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (i - Position.Row == 1 && j - Position.Column == 2) ||
                        (Board.IsPositionValid(position) && CanMove(position)) && (i - Position.Row == 1 && Position.Column - j == 2))
                    {
                        possiblesMovements[i, j] = true;
                    }

                    else
                    {
                        possiblesMovements[i, j] = false;
                    }
                }
            }
            return(possiblesMovements);
        }
コード例 #2
0
ファイル: Rook.cs プロジェクト: MatheusMoselli/Chess
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position pos = new Position(0, 0);

            // Up
            pos.DefineValues(Position.Line - 1, Position.Column);
            while (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color)
                {
                    break;
                }
                pos.Line -= 1;
            }

            // Down
            pos.DefineValues(Position.Line + 1, Position.Column);
            while (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color)
                {
                    break;
                }
                pos.Line += 1;
            }

            // Right
            pos.DefineValues(Position.Line, Position.Column + 1);
            while (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color)
                {
                    break;
                }
                pos.Column += 1;
            }

            // Left
            pos.DefineValues(Position.Line, Position.Column - 1);
            while (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
                if (Board.UniquePiece(pos) != null && Board.UniquePiece(pos).Color != Color)
                {
                    break;
                }
                pos.Column -= 1;
            }

            return(mat);
        }
コード例 #3
0
        /// <summary>
        /// Tawer is avaliable to castling
        /// </summary>
        /// <param name="position">Position</param>
        /// <returns>If this piece is avaliable to playmake</returns>
        private bool TowerToCastling(Position position)
        {
            if (Board.IsPositionValid(position))
            {
                Piece piece = Board.Piece(position);

                return(piece != null && piece is Rook && piece.NumberOfMovements == 0 && piece.Color == Color);
            }
            return(false);
        }
コード例 #4
0
ファイル: Bishop.cs プロジェクト: joedav/ConsoleChess
        /// <summary>
        /// Sets possibles movements by piece
        /// </summary>
        /// <returns>Possibles movements</returns>
        public override bool[,] PossibleMovements()
        {
            bool[,] possiblesMovements = new bool[Board.Rows, Board.Columns];
            Position position = new Position(0, 0);

            // NW
            position.SetValues(Position.Row - 1, Position.Column - 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row - 1, position.Column - 1);
            }

            // NE
            position.SetValues(Position.Row - 1, Position.Column + 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row - 1, position.Column + 1);
            }

            // SE
            position.SetValues(Position.Row + 1, Position.Column + 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row + 1, position.Column + 1);
            }

            // SW
            position.SetValues(Position.Row + 1, Position.Column - 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row + 1, position.Column - 1);
            }

            return(possiblesMovements);
        }
コード例 #5
0
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];
            Position pos = new Position(0, 0);

            pos.DefineValues(Position.Line - 1, Position.Column - 2);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line - 2, Position.Column - 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line - 2, Position.Column + 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line - 1, Position.Column + 2);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 1, Position.Column + 2);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 2, Position.Column + 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 2, Position.Column - 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            pos.DefineValues(Position.Line + 1, Position.Column - 2);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }
            return(mat);
        }
コード例 #6
0
        /// <summary>
        /// Validates the origin position
        /// </summary>
        /// <param name="origin">Origin to validate</param>
        public void ValidateOriginPosition(Position origin)
        {
            if (!Board.IsPositionValid(origin))
            {
                throw new BoardException($"Position {origin} is invalid.");
            }

            Piece piece = Board.Piece(origin);

            if (piece == null)
            {
                throw new BoardException("There is not a piece in this chosen position.");
            }

            if (piece.Color != CurrentPlayer)
            {
                throw new BoardException("This piece does not belong to you.");
            }

            if (piece.IsPieceStuck())
            {
                throw new BoardException("This piece is stuck.");
            }
        }
コード例 #7
0
        /// <summary>
        /// Checks the possibles movements of a piece
        /// </summary>
        /// <returns>List of possible moviments</returns>
        public override bool[,] PossibleMovements()
        {
            PossiblesExits             = 0;
            bool[,] possiblesMovements = new bool[Board.Rows, Board.Columns];

            Position position = new Position(0, 0);

            // N
            position.SetValues(Position.Row - 1, Position.Column);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // NE
            position.SetValues(Position.Row - 1, Position.Column + 1);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // E
            position.SetValues(Position.Row, Position.Column + 1);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // SE
            position.SetValues(Position.Row + 1, Position.Column + 1);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // S
            position.SetValues(Position.Row + 1, Position.Column);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // SW
            position.SetValues(Position.Row + 1, Position.Column - 1);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // W
            position.SetValues(Position.Row, Position.Column - 1);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // NW
            position.SetValues(Position.Row - 1, Position.Column - 1);
            if (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                PossiblesExits++;
            }

            // #SpecialPlay - Castling
            if (NumberOfMovements == 0 && !Match.IsCheck)
            {
                // little castling
                Position posT0 = new Position(Position.Row, Position.Column + 3);
                if (TowerToCastling(posT0))
                {
                    Position p1 = new Position(Position.Row, Position.Column + 1);
                    Position p2 = new Position(Position.Row, Position.Column + 2);
                    if (Board.Piece(p1) is null && Board.Piece(p2) is null)
                    {
                        possiblesMovements[p2.Row, p2.Column] = true;
                    }
                }

                // big castling
                Position posT1 = new Position(Position.Row, Position.Column - 4);
                if (TowerToCastling(posT1))
                {
                    Position p1 = new Position(Position.Row, Position.Column - 1);
                    Position p2 = new Position(Position.Row, Position.Column - 2);
                    Position p3 = new Position(Position.Row, Position.Column - 3);
                    if (Board.Piece(p1) is null && Board.Piece(p2) is null && Board.Piece(p3) is null)
                    {
                        possiblesMovements[p2.Row, p2.Column] = true;
                    }
                }
            }

            return(possiblesMovements);
        }
コード例 #8
0
        /// <summary>
        /// Implements the possibles movements
        /// </summary>
        /// <returns>Possibles movements</returns>
        public override bool[,] PossibleMovements()
        {
            bool[,] possiblesMovements = new bool[Board.Rows, Board.Columns];
            Position position = new Position(0, 0);

            for (int i = 0; i < Board.Rows; i++)
            {
                for (int j = 0; j < Board.Columns; j++)
                {
                    position.SetValues(i, j);
                    if (Color is Color.White)
                    {
                        if ((Board.IsPositionValid(position) && CanMove(position) && Position != null) && (
                                (!Board.ExistsPiece(position) && Position.Row - i == 1 && Position.Column == j) ||
                                (!Board.ExistsPiece(position) && (NumberOfMovements < 1) && Position.Row - i == 2 && Position.Column == j) ||
                                (ExistsEnemy(position) && Position.Row - i == 1 && Position.Column - j == 1) ||
                                (ExistsEnemy(position) && Position.Row - i == 1 && j - Position.Column == 1)))
                        {
                            possiblesMovements[i, j] = true;
                        }
                    }
                    else if (Color is Color.Black)
                    {
                        if ((Board.IsPositionValid(position) && CanMove(position) && Position != null) && (
                                (!Board.ExistsPiece(position) && i - Position.Row == 1 && Position.Column == j) ||
                                (!Board.ExistsPiece(position) && (NumberOfMovements < 1) && i - Position.Row == 2 && Position.Column == j) ||
                                (ExistsEnemy(position) && i - Position.Row == 1 && j - Position.Column == 1) ||
                                (ExistsEnemy(position) && i - Position.Row == 1 && Position.Column - j == 1)))
                        {
                            possiblesMovements[i, j] = true;
                        }
                    }
                }
            }
            // Checks enpassant
            if (Position != null)
            {
                Position left       = new Position(Position.Row, Position.Column - 1);
                Position right      = new Position(Position.Row, Position.Column + 1);
                Piece    pieceLeft  = null;
                Piece    pieceRight = null;
                if (Board.IsPositionValid(left))
                {
                    pieceLeft = Board.Piece(left);
                }
                if (Board.IsPositionValid(right))
                {
                    pieceRight = Board.Piece(right);
                }

                // Black
                if (Position.Row == 4)
                {
                    if (Board.IsPositionValid(left) && ExistsEnemy(left) && Match.EnableEnPassant == pieceLeft)
                    {
                        possiblesMovements[left.Row + 1, left.Column] = true;
                    }
                    else if (Board.IsPositionValid(right) && ExistsEnemy(right) && Match.EnableEnPassant == pieceRight)
                    {
                        possiblesMovements[right.Row + 1, right.Column] = true;
                    }
                }
                // White
                else if (Position.Row == 3)
                {
                    if (Board.IsPositionValid(left) && ExistsEnemy(left) && Match.EnableEnPassant == pieceLeft)
                    {
                        possiblesMovements[left.Row - 1, left.Column] = true;
                    }
                    else if (Board.IsPositionValid(right) && ExistsEnemy(right) && Match.EnableEnPassant == pieceRight)
                    {
                        possiblesMovements[right.Row - 1, right.Column] = true;
                    }
                }
            }

            return(possiblesMovements);
        }
コード例 #9
0
        /// <summary>
        /// Possibles movements
        /// </summary>
        /// <returns></returns>
        public override bool[,] PossibleMovements()
        {
            bool[,] possiblesMovements = new bool[Board.Rows, Board.Columns];
            Position position = new Position(0, 0);

            // N
            for (int i = Position.Row - 1; i >= 0; i--)
            {
                position.SetValues(i, Position.Column);
                if (Board.IsPositionValid(position) && CanMove(position))
                {
                    possiblesMovements[position.Row, position.Column] = true;
                }

                if (Board.Piece(position) != null && Board.Piece(position).Color != Color || (Board.Piece(position) != null && Board.Piece(position).Color == Color))
                {
                    break;
                }
            }

            // E
            for (int i = Position.Column + 1; i <= 7; i++)
            {
                position.SetValues(Position.Row, i);
                if (Board.IsPositionValid(position) && CanMove(position))
                {
                    possiblesMovements[position.Row, position.Column] = true;
                }

                if ((Board.Piece(position) != null && Board.Piece(position).Color != Color) || (Board.Piece(position) != null && Board.Piece(position).Color == Color))
                {
                    break;
                }
            }

            // S
            for (int i = Position.Row + 1; i <= 7; i++)
            {
                position.SetValues(i, Position.Column);
                if (Board.IsPositionValid(position) && CanMove(position))
                {
                    possiblesMovements[position.Row, position.Column] = true;
                }

                if (Board.Piece(position) != null && Board.Piece(position).Color != Color || (Board.Piece(position) != null && Board.Piece(position).Color == Color))
                {
                    break;
                }
            }

            // W
            for (int i = Position.Column - 1; i >= 0; i--)
            {
                position.SetValues(Position.Row, i);
                if (Board.IsPositionValid(position) && CanMove(position))
                {
                    possiblesMovements[position.Row, position.Column] = true;
                }

                if (Board.Piece(position) != null && Board.Piece(position).Color != Color || (Board.Piece(position) != null && Board.Piece(position).Color == Color))
                {
                    break;
                }
            }

            // NW
            position.SetValues(Position.Row - 1, Position.Column - 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row - 1, position.Column - 1);
            }

            // NE
            position.SetValues(Position.Row - 1, Position.Column + 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row - 1, position.Column + 1);
            }

            // SE
            position.SetValues(Position.Row + 1, Position.Column + 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row + 1, position.Column + 1);
            }

            // SW
            position.SetValues(Position.Row + 1, Position.Column - 1);
            while (Board.IsPositionValid(position) && CanMove(position))
            {
                possiblesMovements[position.Row, position.Column] = true;
                if (Board.Piece(position) != null && Board.Piece(position).Color != Color)
                {
                    break;
                }
                position.SetValues(position.Row + 1, position.Column - 1);
            }

            return(possiblesMovements);
        }
コード例 #10
0
ファイル: Pawn.cs プロジェクト: MatheusMoselli/Chess
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];
            Position pos = new Position(0, 0);

            if (Color == Color.White)
            {
                pos.DefineValues(Position.Line - 1, Position.Column);
                if (Board.IsPositionValid(pos) && Free(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 2, Position.Column);
                Position p2 = new Position(Position.Line - 1, Position.Column);
                if (Board.IsPositionValid(p2) && Free(p2) && Board.IsPositionValid(pos) && Free(pos) && ManyMoves == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 1, Position.Column - 1);
                if (Board.IsPositionValid(pos) && IsThereEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line - 1, Position.Column + 1);
                if (Board.IsPositionValid(pos) && IsThereEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                // #SpecialPlay
                // EnPassant
                if (Position.Line == 3)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.IsPositionValid(left) && IsThereEnemy(left) && Board.UniquePiece(left) == Match.VulnerableEnPassant)
                    {
                        mat[left.Line - 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.IsPositionValid(right) && IsThereEnemy(right) && Board.UniquePiece(right) == Match.VulnerableEnPassant)
                    {
                        mat[right.Line - 1, right.Column] = true;
                    }
                }
            }
            else
            {
                pos.DefineValues(Position.Line + 1, Position.Column);
                if (Board.IsPositionValid(pos) && Free(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                Position p2 = new Position(Position.Line + 1, Position.Column);
                pos.DefineValues(Position.Line + 2, Position.Column);
                if (Board.IsPositionValid(p2) && Free(p2) && Board.IsPositionValid(pos) && Free(pos) && ManyMoves == 0)
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 1, Position.Column + 1);
                if (Board.IsPositionValid(pos) && IsThereEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                pos.DefineValues(Position.Line + 1, Position.Column - 1);
                if (Board.IsPositionValid(pos) && IsThereEnemy(pos))
                {
                    mat[pos.Line, pos.Column] = true;
                }

                // #SpecialPlay
                // EnPassant
                if (Position.Line == 4)
                {
                    Position left = new Position(Position.Line, Position.Column - 1);
                    if (Board.IsPositionValid(left) && IsThereEnemy(left) && Board.UniquePiece(left) == Match.VulnerableEnPassant)
                    {
                        mat[left.Line + 1, left.Column] = true;
                    }
                    Position right = new Position(Position.Line, Position.Column + 1);
                    if (Board.IsPositionValid(right) && IsThereEnemy(right) && Board.UniquePiece(right) == Match.VulnerableEnPassant)
                    {
                        mat[right.Line + 1, right.Column] = true;
                    }
                }
            }
            return(mat);
        }
コード例 #11
0
        public override bool[,] PossibleMoviments()
        {
            bool[,] mat = new bool[Board.Lines, Board.Columns];

            Position pos = new Position(0, 0);

            // Up
            pos.DefineValues(Position.Line - 1, Position.Column);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Up + Right
            pos.DefineValues(Position.Line - 1, Position.Column + 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Right
            pos.DefineValues(Position.Line, Position.Column + 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Right + Down
            pos.DefineValues(Position.Line + 1, Position.Column + 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Down
            pos.DefineValues(Position.Line + 1, Position.Column);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Down + Left
            pos.DefineValues(Position.Line + 1, Position.Column - 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Left
            pos.DefineValues(Position.Line, Position.Column - 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // Left + Up
            pos.DefineValues(Position.Line - 1, Position.Column - 1);
            if (Board.IsPositionValid(pos) && CanMove(pos))
            {
                mat[pos.Line, pos.Column] = true;
            }

            // #SpecialPlay
            if (ManyMoves == 0 && !Match.Check)
            {
                // Castle Kingside - roque pequeno
                Position positionOfRook = new Position(Position.Line, Position.Column + 3);
                if (testRookToCastle(positionOfRook))
                {
                    Position p1 = new Position(Position.Line, Position.Column + 1);
                    Position p2 = new Position(Position.Line, Position.Column + 2);

                    if (Board.UniquePiece(p1) == null && Board.UniquePiece(p2) == null)
                    {
                        mat[Position.Line, Position.Column + 2] = true;
                    }
                    {
                    }
                }

                // Castle Queenside - roque grande
                Position positionOfRookQueenSide = new Position(Position.Line, Position.Column - 4);
                if (testRookToCastle(positionOfRookQueenSide))
                {
                    Position p1 = new Position(Position.Line, Position.Column - 1);
                    Position p2 = new Position(Position.Line, Position.Column - 2);
                    Position p3 = new Position(Position.Line, Position.Column - 3);

                    if (Board.UniquePiece(p1) == null && Board.UniquePiece(p2) == null && Board.UniquePiece(p3) == null)
                    {
                        mat[Position.Line, Position.Column - 2] = true;
                    }
                    {
                    }
                }
            }

            return(mat);
        }