Esempio n. 1
0
        private List <Square> searchForAvailableSquaresInGivenDirection(Predicate <Square> squareMatcher, Position startingSquarePosition, short maximumDistance, Direction direction)
        {
            var matchingSquares = new List <Square>();

            for (short distance = 1; distance <= maximumDistance; distance++)
            {
                Vec2 <long> position = startingSquarePosition + ((Vec2 <short>)direction * distance);
                //todo: can't convert to uint here if we have negative coord
                Vec2 <int> boardPosition = position.ConvertMemberType <int>();

                Optional <Square> square = checkForMatchingSquare(squareMatcher, boardPosition);

                if (square.HasValue)
                {
                    matchingSquares.Add(square.Object);

                    if (square.Object.IsOccupied)
                    {
                        break;
                    }
                }
                else
                {
                    break;
                }
            }

            return(matchingSquares);
        }
Esempio n. 2
0
        private Optional <Square> checkForMatchingSquare(Predicate <Square> squareMatcher, Vec2 <int> position)
        {
            if (IsInsideBounds(position))
            {
                Square square = this[position.ConvertMemberType <uint>()];

                if (squareMatcher(square))
                {
                    return(square);
                }
                else
                {
                    return(Optional <Square> .Empty);
                }
            }
            else
            {
                return(Optional <Square> .Empty);
            }
        }