/// <summary> /// Checks if the current active cards are a set /// If they are removes them and updates score' /// if not it removes them from the active set forcing player to start over selection /// </summary> /// <returns></returns> public IEnumerator CheckSet() { yield return(null); var materialHashSet = new HashSet <Material>(); var countHashSet = new HashSet <int>(); var shapeHashSet = new HashSet <GameObject>(); foreach (var card in activeCards) { var cardProperties = card.GetComponent <CardProperties>(); materialHashSet.Add(cardProperties.color); countHashSet.Add(cardProperties.count); shapeHashSet.Add(cardProperties.shape); } //if all 3 card components are different score if (activeCards.Count == 3 && materialHashSet.Count == 3 && countHashSet.Count == 3 && shapeHashSet.Count == 3) { // IMMEDIATELY need to remove cards from the active set. webSocketManager.SendLog("found a valid set, including:"); cardsToRemove = new List <GameObject>(); for (int i = 0; i < 3; i++) { cardsToRemove.Add(activeCards[i]); webSocketManager.SendLog("active card: " + CardProperties.Stringify(activeCards[i])); } // Clearing this now means that no moveement will modify the set of // active cards while the set is processing activeCards.Clear(); ChangeCardColors(1, cardsToRemove); webSocketManager.SendLog("successfully changed the card colors"); #if !SIMULATING yield return(new WaitForSeconds(.25f)); #endif #if SIMULATING yield return(null); #endif for (int i = 0; i < 3; i++) { cardsToRemove[i].SetActive(false); webSocketManager.SendLog("successfully marked card " + CardProperties.Stringify(cardsToRemove[i]) + " as inactive"); } cardsToRemove.Clear(); webSocketManager.SendLog("emptied list of cards to remove"); yield return(null); #if !SIMULATING yield return(new WaitForSeconds(.25f)); #endif scorekeeper.ScoredSet(); turnController.AddMovesOnSet(scorekeeper.score); webSocketManager.SendLog("added a set and extra turns"); AddMoreCards(); webSocketManager.SendLog("added new cards"); #if !SIMULATING List <string> cardStringArray = new List <string>(); for (int i = 0; i < propPlacement.cards.Length; i++) { cardStringArray.Add(CardProperties.Stringify(propPlacement.cards[i])); } string cardsString = String.Join(", ", cardStringArray.ToArray()); Dictionary <string, string> strData = new Dictionary <string, string>() { { "formed", "YES" }, { "score", (scorekeeper.score).ToString() }, { "cards", cardsString } }; webSocketManager.Send("set", strData, null); #endif } else if (activeCards.Count >= 3 || (materialHashSet.Count < activeCards.Count || countHashSet.Count < activeCards.Count || shapeHashSet.Count < activeCards.Count)) { ChangeCardColors(2, activeCards); } else { ChangeCardColors(0, activeCards); } // I believe this is only relevant if you are simulating #if !SIMULATING yield return(null); #endif #if SIMULATING MainControl mainControl = FindObjectOfType <MainControl>(); yield return(null); mainControl.updating_cards = false; #endif yield break; }