コード例 #1
0
    public HashSet <Coordinate> GetValidPlayableSpaces()
    {
        if (ValidPlayableSpacesCache != null && ValidPlayableSpacesCache.Count > 0)
        {
            return(ValidPlayableSpacesCache);
        }

        // For every played card, add every neighboring coordinate to a HashSet (no duplicates)
        HashSet <Coordinate> neighborsOfHappyCoordinates    = new HashSet <Coordinate>(GetHappyCoordinates().SelectMany(coordinate => coordinate.GetNeighbors()));
        HashSet <Coordinate> neighborsOfNotHappyCoordinates = new HashSet <Coordinate>(GetNotHappyCoordinates().SelectMany(coordinate => coordinate.GetNeighbors()));
        HashSet <Coordinate> finalCut = new HashSet <Coordinate>();

        // For each considered Coordinate, if all the following is true, consider that spot valid:
        // - there are no cards on that spot
        // - there are no happy cards neighboring that spot
        foreach (Coordinate consideredCoordinate in neighborsOfNotHappyCoordinates)
        {
            if (PlayedCards.ContainsKey(consideredCoordinate))
            {
                continue;
            }

            if (neighborsOfHappyCoordinates.Contains(consideredCoordinate))
            {
                continue;
            }

            finalCut.Add(consideredCoordinate);
        }

        ValidPlayableSpacesCache = finalCut;

        return(finalCut);
    }
コード例 #2
0
    public bool ShouldCoordinateBeIncompletable(Coordinate forCoordinate)
    {
        if (!PlayedCards.ContainsKey(forCoordinate))
        {
            Debug.LogError($"Asked if coordinate {forCoordinate.ToString()} should be incompleteable, but that coordinate isn't in this play field.");
            return(false);
        }

        int requiredNeighbors  = PlayedCards[forCoordinate].FaceValue;
        int occuppiedNeighbors = OccuppiedNeighborsAtCoordinate(forCoordinate);

        if (requiredNeighbors == occuppiedNeighbors)
        {
            return(false); // Presumably already happy
        }

        HashSet <Coordinate> validSpaces = GetValidPlayableSpaces();

        int playableSpotNeighbors = forCoordinate.GetNeighbors().Count(neighbor => validSpaces.Contains(neighbor));

        if (occuppiedNeighbors + playableSpotNeighbors < requiredNeighbors)
        {
            return(true);
        }
        return(false);
    }
コード例 #3
0
    public void SetCard(CardData forCard, Coordinate onCoordinate)
    {
        ValidPlayableSpacesCache = null;
        NotHappyCoordinatesCache.Add(onCoordinate);
        HappyCoordinatesAreDirty = true;

        if (PlayedCards.ContainsKey(onCoordinate))
        {
            PlayedCards[onCoordinate] = forCard;
        }
        else
        {
            PlayedCards.Add(onCoordinate, forCard);
        }
    }
コード例 #4
0
    public bool ShouldCoordinateBeHappy(Coordinate forCoordinate)
    {
        if (!PlayedCards.ContainsKey(forCoordinate))
        {
            Debug.LogError($"Asked if coordinate {forCoordinate.ToString()} should be happy, but that coordinate isn't in this play field.");
            return(false);
        }

        int neighbors = OccuppiedNeighborsAtCoordinate(forCoordinate);

        if (PlayedCards[forCoordinate].FaceValue == neighbors)
        {
            return(true);
        }

        return(false);
    }
コード例 #5
0
    public int OccuppiedNeighborsAtCoordinate(Coordinate forCoordinate)
    {
        int answer = forCoordinate.GetNeighbors().Count(neighbor => PlayedCards.ContainsKey(neighbor));

        return(answer);
    }