public void UpdateAICardsInHand(CardsInHand handCards, GameObject[] cardUIs) //Update UI for displaying AI hand cards { List <Card> mCards = new List <Card>(); mCards = handCards.GetCards(); int aiScoreInt = handCards.score; aiScore = aiScoreInt.ToString(); if (mCards.Count == 9) { cardUIs[8].gameObject.SetActive(true); } else { cardUIs[8].gameObject.SetActive(false); } for (int i = 0; i < mCards.Count(); i++) { TextMeshProUGUI valueText = cardUIs[i].transform.GetChild(0).GetComponent <TextMeshProUGUI>(); TextMeshProUGUI suitText = cardUIs[i].transform.GetChild(1).GetComponent <TextMeshProUGUI>(); suitText.text = mCards[i].Suit.ToString(); valueText.text = mCards[i].Value.ToString(); } handCards.AnalyseHand(computerCardsInHand); int.TryParse(aiScore, out handCards.score); }
public void HumanExecute() //This function is used to draw or discard when the button clicked { if (!CardsInHand.CheckVictory(playerCardsInHand) && mMachine.CurrentState.GetName == "Player Turn State" && move == true) { DetectSelection(); playerCardsInHand.ResetScore();//to show the potential score in the current hand right now (resets and displays at the start of every turn) playerCardsInHand.AnalyseHand(playerCardsInHand); if (!mMachine.CurrentState.hasDrawn) //if has not drawn, then it will execute draw action { DeckAnimator.SetTrigger("Draw"); mMachine.Execute(deckToDraw); lastDrawDeck = deckToDraw; mAI.MatchAndIterate(); //The AI will do its calculation even it's in player's turn, keeping track of the current state is necessary or the AI will be very dumb if (CardsInHand.CheckVictory(playerCardsInHand)) { UpdateEverything(); endCanvas.SetActive(true); endText.text = "Player Win!"; isComplete = true; playerWin = true; PlayerScore.text = playerScore; //Setting player score for (int i = 0; i < displayCards_AI.Length; i++) { displayCards_AI[i].GetComponentInChildren <CardImage>().enabled = true; } } } else //if has drawn, then it will execute discard action { if (mMachine.Execute(cardToDiscard)) { lastDiscardCard = cardToDiscard; turnCounter += 1; mAI.MatchAndIterate(); move = false; } } UpdateEverything(); } }