public void EndShowing() { //Disable buttons etc DisableAllCards(); NotShown.interactable = false; Shown.interactable = false; NoGuess.interactable = false; UnSolvedGuesses.Add(NewGuess); Phase = CPhases.Calculate; Calculate(); }
public void StartGuessRound() { if (Phase == CPhases.Guess) { Submit.interactable = false; NewGuess = new Guess(WeaponCard.Current, RoomCard.Current, SuspectCard.Current, CurrentPlayer); Phase = CPhases.ResultsOfGuess; ShowingPlayer = (CurrentPlayer + 1) % Players.Count; if (CurrentPlayer == 0) { EnableAllCards(); Turn.text = "If " + Players[ShowingPlayer].Name + " showed a card select it, else press 'No'."; } else { Shown.interactable = true; Turn.text = "Did " + Players[ShowingPlayer].Name + " show a card?"; } NotShown.interactable = true; } }
public void Calculate() { //Scenarios: // > If we know ALL the cards a player DOESN'T have, add the rest to what they DO have // > A player DOESN'T have 2 of the cards in a guess that they answered, so they must have the third // > A player has at least 1 of the cards in a guess, so we remove that guess, as no extra information can be gained with it // > If a player only has one slot left for a card they DO have, if 2 guesses (they answered) only have 1 possible answer in common, that is in the solution // > If a player has a card, remove it from UNKNOWN // > If all players DON'T have a card, add it to SOLUTION // > If there is only 1 UNKNOWN left for a category (and it's not in the solution) add it to the solution //- Check any guesses that no-one answered, if we know all the cards of the asker, then add cards they don't own to the solution (and highlight these cards on the grid either way) //- If a player is still asking about a card we assume they have seen, assume that the player who showed them had 2 in that guess, and display (but do not apply) the other possibility foreach (Player P in Players) { //If we know all of this players cards, add the rest to 'Doesn't Have'. if (P.DoesHave.Count == P.NumberOfCards) { if (P.NotHave.Count < AllCardsCount - P.NumberOfCards) { foreach (string s in All) { if (!P.NotHave.Contains(s) && !P.DoesHave.Contains(s)) { P.NotHave.Add(s); } } } } //If we know ALL the cards a player DOESN'T have, add the rest to what they DO have if (P.NotHave.Count == AllCardsCount - P.NumberOfCards) { if (P.DoesHave.Count < P.NumberOfCards) { foreach (string s in All) { if (!P.NotHave.Contains(s) && !P.DoesHave.Contains(s)) { P.DoesHave.Add(s); Unknown.Remove(s); Known.Add(s); } } DiscoveredCardsToNotHave(); } } //Create a list of guesses that were answered by this player. List <Guess> RelevantGuesses = new List <Guess> (); foreach (Guess G in UnSolvedGuesses) { if (G.ShownBy == P.Index) { RelevantGuesses.Add(G); } } //Find guesses where the player could only have answered with one card. foreach (Guess G in RelevantGuesses) { //Don't have 2 of the cards in the guess if (P.CountNOT(G) == 2) { //Add the remaining card to that players 'Does Have' list, and the other players 'Not Have' lists, and update Known and Unknown string DiscoveredCard = P.AddOwnedCard(G); AddDiscoveredToNotHaves(DiscoveredCard, P.Index); //Unknown.Remove (DiscoveredCard); //Known.Add (DiscoveredCard); } } //Remove obsolete guesses foreach (Guess G in RelevantGuesses) { //If no obvious information can be gained from this guess (we know one of the owned cards) if (P.CountHAS(G) > 0) { //Remove it from UNsolved, add it to the cards the other player has seen, and add it to solved (AKA history) UnSolvedGuesses.Remove(G); int Card = P.FindOwnedCard(G); Players [G.ShownTo].HasSeenAll.Add(G.Cards [Card]); SolvedGuesses.Add(new CompletedGuess(G, Card)); } } //NEW METHOD FOR \/: //Create a list of all the cards they COULD have. //For each guess, if it DOESN'T contain one of those cards, the must not have it, so REMOVE it from the list. //If the list contains only ONE card at the end, that must be the card they have. //If 0, show an error. List <string> CouldHave = new List <string> (); //Remove when debugging is finished. foreach (string u in Unknown) { if (P.NotHave.Contains(u) && P.DoesHave.Contains(u)) { Debug.LogError("Unknown is not accurate"); } } CouldHave.AddRange(Unknown); foreach (Guess G in UnSolvedGuesses) { List <string> ToRemove = new List <string> (); foreach (string s in CouldHave) { if (!G.Contains(s)) { ToRemove.Add(s); } } foreach (string s in ToRemove) { CouldHave.Remove(s); } } if (CouldHave.Count == P.NumberOfCards - P.DoesHave.Count) { P.DoesHave.AddRange(CouldHave); Known.AddRange(CouldHave); foreach (string s in CouldHave) { Unknown.Remove(s); } DiscoveredCardsToNotHave(); } //If a player has only one card that is unknown to us: if any two guesses have only one (possible) card in common, add it to DoesHave //Is inefficient, checks each guess combination twice (G2 should start at G1's index + 1). /* * if (P.DoesHave.Count == P.NumberOfCards - 1) { * foreach (Guess G1 in UnSolvedGuesses) { * bool Found = false; * foreach (Guess G2 in UnSolvedGuesses) { * if (G1 == G2) * continue; * int Same = 0; * string PossibleCard = new string (); * for (int i = 0; i < 3; ++i) { * if (G1.Cards [i] == G2.Cards [i]) { * if (!P.NotHave.Contains (G1.Cards [i])) { * Same += 1; * PossibleCard = G1.Cards [i]; * } * } * } * if (Same == 1) { * P.DoesHave.Add (PossibleCard); * Unknown.Remove (PossibleCard); * DiscoveredCardsToNotHave (); * Found = true; * break; * } * } * if (Found) * break; * } * } * //[Could do /\ for 2 cards - eg three guesses only have one in common - but it is exponentially more intensive] */ } //Check if ALL players don't have a card. Add to Solution if they don't. List <string> ToRemove2 = new List <string> (); foreach (string s in Unknown) { bool OwnedByNoOne = true; foreach (Player P in Players) { if (!P.NotHave.Contains(s)) { OwnedByNoOne = false; break; } } if (OwnedByNoOne) { ToRemove2.Add(s); Solution [CategoryIndex(s)] = s; } } Known.AddRange(ToRemove2); foreach (string s in ToRemove2) { Unknown.Remove(s); } //For each category, if the solution hasn't been found, and there is only 1 unknown left in that category, add it to the solution. for (int i = 0; i < 3; ++i) { if (Solution [i] == "") { int NumberOfUnknowns = 0; string PossibleSolution = ""; foreach (string s in Unknown) { if (CategoryIndex(s) == i) { NumberOfUnknowns += 1; if (NumberOfUnknowns > 1) { break; } else { PossibleSolution = s; } } } if (NumberOfUnknowns == 1) { Solution [i] = PossibleSolution; } } } Phase = CPhases.Guess; CurrentPlayer = (CurrentPlayer + 1) % Players.Count; Turn.text = "Enter " + Players [CurrentPlayer].Name + "'s guess then press Submit, or press No Guess"; if (CurrentPlayer == 0) { Turn.text = "Enter your guess then press Submit, or press No Guess"; } Submit.interactable = true; NoGuess.interactable = true; UpdateGrid(); }
public void CardPressed(int Category) { if (Phase == CPhases.StartingCards) { if (Players [0].DoesHave.Count == Players [0].NumberOfCards) { DisableAllCards(); foreach (string s in All) { if (!Players [0].DoesHave.Contains(s)) { Players [0].NotHave.Add(s); } } DiscoveredCardsToNotHave(); UpdateKnown(); GameObject TM = Resources.Load <GameObject> ("Prefabs/Cluedo/CluedoMessage"); ScrollView.GetComponent <RectTransform> ().sizeDelta += new Vector2(60 * Players.Count - 90, 0); //Cards GameObject GO = Instantiate(TM, ScrollView.transform); GO.transform.localPosition = new Vector3(); GO.transform.Translate(210, -300, 0); GO.GetComponent <Text> ().fontSize = 20; string AllItems = ""; foreach (string s in All) { AllItems += s + " - \n"; } GO.GetComponent <TemporaryMessage> ().SetText(AllItems); GO.GetComponent <TemporaryMessage> ().Delay = -1; for (int P = 0; P < Players.Count; ++P) { CreatePlayerVisuals(P); } //Solution GO = Instantiate(TM, ScrollView.transform); GO.transform.localPosition = new Vector3(); GO.transform.Translate(350 + (Players.Count * 80), -80, 0); GO.transform.Rotate(0, 0, -20); GO.GetComponent <TemporaryMessage> ().SetText("Solution"); GO.GetComponent <TemporaryMessage> ().Delay = -1; //Solution Grid GO = Instantiate(TM, ScrollView.transform); GO.transform.localPosition = new Vector3(); GO.transform.Translate(380 + (Players.Count * 80), -300, 0); GO.GetComponent <Text> ().fontSize = 20; //Generate grid for Solution string LongString = ""; foreach (string s in All) { if (Solution [0] == s || Solution [1] == s || Solution [2] == s) { LongString += " X \n"; } else if (Known.Contains(s)) { LongString += " <> \n"; //Know where it is } else { LongString += " \n"; //DON'T know } } GO.GetComponent <TemporaryMessage> ().SetText(LongString); GO.GetComponent <TemporaryMessage> ().Delay = -1; SolutionGrid = GO.GetComponent <TemporaryMessage> (); Phase = CPhases.Guess; Turn.text = "Enter " + Players [CurrentPlayer].Name + "'s guess then press Submit, or press No Guess"; if (CurrentPlayer == 0) { Turn.text = "Enter your guess then press Submit, or press No Guess"; } Submit.interactable = true; NoGuess.interactable = true; //EnableAllCards (); } } else if (Phase == CPhases.ResultsOfGuess) { string DiscoveredCard = NewGuess.Cards [Category]; Players [ShowingPlayer].DoesHave.Add(DiscoveredCard); Unknown.Remove(DiscoveredCard); Known.Add(DiscoveredCard); DiscoveredCardsToNotHave(); EndShowing(); } }
public void SubmitName(GameObject TextObject) { if (Phase == CPhases.Names) { if (TextObject.GetComponentsInChildren <Text> () [1].text == "") { if (Players.Count >= MinimumPlayers) { Phase = CPhases.FirstPlayer; AskForFirstPlayer(); } else { Turn.text = "You need at least " + MinimumPlayers + "\nplayers."; } } else { Players.Add(new Player(TextObject.GetComponentsInChildren <Text> () [1].text, MultiCounter)); MultiCounter += 1; Debug.Log("Added: " + TextObject.GetComponentsInChildren <Text> () [1].text + " as player " + (Players.Count)); TextObject.GetComponent <InputField> ().text = ""; //Clear text in input field. if (Players.Count >= MinimumPlayers) { Turn.text = "Enter player " + (Players.Count + 1) + "'s name:\nOr submit nothing if last player."; } else { Turn.text = "Enter player " + (Players.Count + 1) + "'s name:"; } } } else if (Phase == CPhases.FirstPlayer) { int i = 0; foreach (Player P in Players) { if (P.Name == TextObject.GetComponentsInChildren <Text> () [1].text) { CurrentPlayer = i; } i += 1; } Phase = CPhases.NumCards; //Calculate the number of cards for each player here. int RemainingCards = AllCardsCount - 3; int Counter = 0; for (int C = 0; C < Players.Count; ++C) { Players[((C + CurrentPlayer) % Players.Count)].NumberOfCards = Mathf.FloorToInt(RemainingCards / (Players.Count - Counter)); RemainingCards -= Mathf.FloorToInt(RemainingCards / (Players.Count - Counter)); Debug.Log(Players[((C + CurrentPlayer) % Players.Count)].NumberOfCards + " cards for " + Players[((C + CurrentPlayer) % Players.Count)].Name); Counter += 1; } /* * foreach (Player P in Players) { * P.NumberOfCards = Mathf.FloorToInt (RemainingCards / (Players.Count - Counter)); * RemainingCards -= Mathf.FloorToInt (RemainingCards / (Players.Count - Counter)); * Counter += 1; * Debug.Log (P.NumberOfCards); * } */ Destroy(TextObject); Turn.text = "Select the cards in your hand.\n(Click a card to submit it)"; WeaponCard.Text = "Press Arrows"; RoomCard.Text = "Press Arrows"; SuspectCard.Text = "Press Arrows"; WeaponCard.Current = "ZZZZZ"; RoomCard.Current = "ZZZZZ"; SuspectCard.Current = "ZZZZZ"; WeaponCard.GetComponent <Button> ().interactable = true; RoomCard.GetComponent <Button> ().interactable = true; SuspectCard.GetComponent <Button> ().interactable = true; Phase = CPhases.StartingCards; } }