public void DetectSelection() //Allow the player to select interactable game objects in the scene { if (mEventSystem.currentSelectedGameObject != null) { if (mEventSystem.currentSelectedGameObject.layer != 5) { currentSelect = mEventSystem.currentSelectedGameObject; } if (mEventSystem.currentSelectedGameObject.CompareTag("HeldCard")) { deckToDraw = CherkiMachineState.SourceDeck.None; for (int i = 0; i < displayCards.Count(); i++) { if (displayCards[i] == mEventSystem.currentSelectedGameObject) { cardToDiscard = playerCardsInHand.GetCards()[i]; } } } if (mEventSystem.currentSelectedGameObject.CompareTag("LastDiscard")) { cardToDiscard = null; deckToDraw = CherkiMachineState.SourceDeck.DiscardDeck; } if (mEventSystem.currentSelectedGameObject.CompareTag("DrawDeck")) { cardToDiscard = null; deckToDraw = CherkiMachineState.SourceDeck.DrawDeck; } } }
// Start is called before the first frame update void Start() { currentSelect = null; drawDeck = new Deck(); drawDeck.Initialise(); //Generate all the cards discardDeck = new Deck(); playerCardsInHand = new CardsInHand(); computerCardsInHand = new CardsInHand(); mMachine = new CherkiStateMachine(); UpdateCurrentState(); ShuffleDrawDeck(); //Shuffle the draw deck InitialDistribution(); //Distribute 8 cards to each player playerCardsInHand.Sort(); //Rearrange the hand cards computerCardsInHand.Sort(); UpdateCardsInHand(playerCardsInHand, displayCards); //Display cards of both players UpdateCardsInHand(computerCardsInHand, displayCards_AI); deckToDraw = CherkiMachineState.SourceDeck.None; cardToDiscard = null; mAI.enabled = true; //Enable the AI script isInitialised = true; }
public bool ExecuteAI(CherkiMachineState.SourceDeck source) //Execute draw action, source means to which deck to draw { if (currentState.DrawCard(source)) { currentState.hasDrawn = true; return(true); } return(false); }
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(); } }
public void AIDraw(CherkiMachineState.SourceDeck sourceDeck) //AI Drawing function but called inside MCTSAI script { mMachine.Execute(sourceDeck); //Use FSM to do the action if (mMachine.CheckVictory()) //If victory goal met { UpdateEverything(); endCanvas.SetActive(true); //show end game canvas endText.text = "Computer Win!"; isComplete = true; //mark the game as completed playerWin = false; AiScore.text = aiScore;; //Setting AI score for (int i = 0; i < displayCards_AI.Length; i++) { displayCards_AI[i].GetComponentInChildren <CardImage>().enabled = true; } } AIUpdateEverything(); }
public MCTSState(Main.Turn currentTurn, Deck drawDeck, Deck discardDeck, CardsInHand humanCards, CardsInHand AICards, bool hasDrawn, Card lastDiscard, CherkiMachineState.SourceDeck lastDrawDeck) { this.drawDeck = new Deck(drawDeck.ShallowClone()); this.discardDeck = new Deck(discardDeck.ShallowClone()); this.humanCards = new CardsInHand(humanCards.ShallowClone()); this.AICards = new CardsInHand(AICards.ShallowClone()); if (lastDiscard == null) { this.lastDiscard = null; } else { this.lastDiscard = lastDiscard; } this.currentTurn = currentTurn; this.hasDrawn = hasDrawn; this.stateResult = Result.None; this.lastDrawDeck = lastDrawDeck; }
public void ResetExecuteTarget() //Reset the deck to draw and card to discard { deckToDraw = CherkiMachineState.SourceDeck.None; cardToDiscard = null; }