private Card ShowTopCard() { var card = CardsInHand.FirstOrDefault(); Console.Write($"{card.Rank} of {card.Suit}"); return(card); }
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 TakeCards(IEnumerable <Card> gameSet) { foreach (var card in gameSet) { CardsInHand.Add(card); } }
public void UpdateCardsInHand(CardsInHand handCards, GameObject[] cardUIs) //Update UI for displaying hand cards { List <Card> mCards = new List <Card>(); mCards = handCards.GetCards(); int playerScoreInt = handCards.score; //Setting the player score int playerScore = playerScoreInt.ToString(); //Converting the int to string so we can change the Score in TMPGUI 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(); } }
public static bool CheckVictory(CardsInHand mCardsInHand) //Check if there are 3 completed meld { int numOfCurrentMeldType = 0; int completeSetCount = 0; for (int i = 0; i < 12; i++) { numOfCurrentMeldType = mCardsInHand.NumOfCardsOfType((MeldType)i); if (numOfCurrentMeldType == 3) { completeSetCount += 1; } else if (numOfCurrentMeldType > 3) { completeSetCount += (numOfCurrentMeldType - (numOfCurrentMeldType % 3)) / 3; } if (numOfCurrentMeldType == 8 && completeSetCount == 2) //2 completeSetCount + 2numOfCurrentMeldType = 0 { Debug.Log("CHERKI"); } } if (completeSetCount == 3) { return(true); } return(false); }
// 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 void ChangeCard(int cardNumber, int placeNumber) { Card card = CardsInHand[cardNumber]; ActiveCards[placeNumber] = card; CardsInHand.Remove(card); }
private void AddCardToHand(CardRoot cardRootScript) { CardsInHand.Add(cardRootScript); //disable interaction cardRootScript.InteractionDisable(); cardsN++; }
void Start() { cardsInHand = transform.parent.GetComponent <CardsInHand>(); cardController = GetComponent <CardController>(); canvasGroup = GetComponent <CanvasGroup>(); rect = GetComponent <RectTransform>(); IsCardGetForDrag = false; }
void Start() { manaAmount = FindObjectOfType <ManaAmount>(); cardsHand = FindObjectOfType <CardsInHand>(); cardMask = LayerMask.GetMask("Cards"); playfieldMask = LayerMask.GetMask("Playfield"); defaultMask = ~cardMask; }
/// <summary> /// Adds each card to the master card list. Updates HandValue. /// </summary> /// <param name="card1">First card dealt</param> /// <param name="card2">Second card dealt</param> public Hand(Card card1, Card card2) { cardsInHand = new List <Card>(); CardsInHand.Add(card1); CardsInHand.Add(card2); HandValue += card1.Number; HandValue += card2.Number; }
public TurnState(string name, Main.Turn mTurn, Main.Turn nextTurn, CardsInHand mCards, Deck drawDeck, Deck discardDeck) { this.name = name; this.mTurn = mTurn; this.nextTurn = nextTurn; this.mCards = mCards; this.drawDeck = drawDeck; this.discardDeck = discardDeck; }
public void DealStartCards() { for (int i = 0; i < 4; i++) { var card = CardsInDeck.Pop(); card.RenderComponent = new Components.CardComponent(card, new RenderLocation(Console.WindowWidth / 2 - (i * 5), Console.WindowHeight - 28)); CardsInHand.Add(card); } }
private void RemoveOneCardFromHand() { cardsN--; if (CardsInHand.Count > 0) { var card = CardsInHand[0]; CardsInHand.Remove(card); Destroy(card.gameObject); } }
public void PreparePresidentToDiscard(List <Card> cards) { try { RoundState = RoundState.PresidentDiscard; CardsInHand.AddRange(cards); } catch (Exception ex) { Console.WriteLine("PreparePresidentToDiscard.ex: " + ex.Message); } }
public MeldType MostUselessType(CardsInHand handCards) //This function is used to find the most useless meld type from a group of cards(hand cards) { for (int i = 0; i < (int)MeldType.Count; i++) { int numOfCurrentTypeInHand = handCards.NumOfCardsOfType((MeldType)i); int numOfCurrentTypeInDiscard = state.discardDeck.NumOfCardsOfType((MeldType)i); int numOfCardsRevealed = numOfCurrentTypeInHand + numOfCurrentTypeInDiscard; int numOfCardsUnRevealed = 0; if (numOfCurrentTypeInHand % 3 != 0) //If cards of current type is not times of 3(cannot form a meld) { if (i < 3) //For the three special card type(each type only has 4 cards in total) { numOfCardsUnRevealed = 4 - numOfCardsRevealed; if (numOfCurrentTypeInDiscard > 1) //If you can never form a meld with the remainning card { return((MeldType)i); } } else if (i > 3) //For other value card types(12 cards for each type in total) { numOfCardsUnRevealed = 12 - numOfCardsRevealed; if (numOfCurrentTypeInDiscard > 9) //If it can never form a meld with the remainning card { return((MeldType)i); } } } } //If none of the cards fit the above condition for (int i = 0; i < (int)MeldType.Count; i++) //find the type which u have only 1 card of, loop from low value to high value { int numOfCurrentTypeInHand = handCards.NumOfCardsOfType((MeldType)i); if (numOfCurrentTypeInHand % 3 == 1) { return((MeldType)i); } } //If none of the cards fit the above condition for (int i = 0; i < (int)MeldType.Count; i++) //find any type that has not formed a meld yet, loop from low value to high value { int numOfCurrentTypeInHand = handCards.NumOfCardsOfType((MeldType)i); if (numOfCurrentTypeInHand % 3 > 0) { return((MeldType)i); } } Debug.Log("Error, No useless type found"); return(MeldType.WhiteFlower); }
public void ForceCard(Card card) { try { RoundState = RoundState.ForcedCard; CardsInHand.Add(card); NbreOfFailedVotes = 0; } catch (Exception ex) { Console.WriteLine("ForceCard.ex: " + ex.Message); } }
public void MoveToNextRound() { LastPresidentId = PresidentId; PresidentId = -1; LastChancellorId = ChancellorId; ChancellorId = -1; NominatedChancellorId = -1; RoundState = RoundState.PickChancellor; _votes.Clear(); CardsInHand.Clear(); }
public Card PlaceCardOnTable(int count) { try { var cardForReturn = CardsInHand[count]; CardsInHand.Remove(cardForReturn); return(cardForReturn); } catch (ArgumentOutOfRangeException) { throw new InvaliidCardException("This user has played an incorrect card"); } }
private void GenerateRandomCards() { for (int i = 0; i < 10; i++) { CardsInHand.Add(new Card() { Name = i.ToString(), AttackValue = 10, Type = CardType.Attack }); } for (int i = 0; i < 5; i++) { ActiveCards.Add(new EmptyCard()); } }
public override void OnPlay(AbstractBattleUnit target, EnergyPaidInformation energyPaid) { var randomAttackCardInHand = CardsInHand.Shuffle().FirstOrDefault(item => item != this && item.CardType == CardType.AttackCard); if (randomAttackCardInHand != null) { randomAttackCardInHand.AddSticker(new GildedCardSticker(2)); } foreach (var attack in state().Deck.TotalDeckList.Where(item => item.CardType == CardType.AttackCard && item.HasSticker <GildedCardSticker>())) { } }
public void SetCardsNumberInHand(int cardsN) { this.cardsN = cardsN; //TODO красивое отображение карт с анимациями Util.DestroyAllChildren(HandContainer); for (int i = 0; i < cardsN; i++) { //Spawn card var cardGo = Instantiate(CardBackPrefab, HandContainer); var cardRootScript = cardGo.GetComponent <CardRoot>(); cardRootScript.InitGraphics("BACK"); //Add to list CardsInHand.Add(cardRootScript); } }
void Update() { if (Main.isInitialised) { if (Main.Instance.mMachine.CurrentState.MyTurn == myTurn && !Main.isComplete) { if (!Main.Instance.mMachine.CurrentState.hasDrawn) //if has not drawn { StartCoroutine(DrawingDelay()); if (draw == false) { AiAnim.SetTrigger("Drawing"); MCTSIterate(); //Get state that matches the current game state, then expand and simulate treeNode = treeNode.select(); //Based on calculation, select the best node to proceed Main.Instance.AIDraw(treeNode.state.lastDrawDeck); //Draw from a deck according to the node we just selected Main.Instance.lastDrawDeck = treeNode.state.lastDrawDeck; //Update game/board information if (CardsInHand.CheckVictory(Main.Instance.computerCardsInHand)) { treeNode.state.stateResult = MCTSState.Result.AIWin; } } } else if (Main.Instance.mMachine.CurrentState.hasDrawn) //If has drawn { //AiAnim.SetBool("Thinking", true); StartCoroutine(DiscardingDelay()); if (draw == true) { AiAnim.SetTrigger("Discarded"); //AiAnim.SetTrigger("Discarding"); //AiAnim.SetBool("Thinking", false); //AiAnim.SetTrigger("AIDiscard"); MCTSIterate(); //Get state that matches the current game state, then expand and simulate treeNode = treeNode.select(); //Based on calculation, select the best node to proceed Main.turnCounter += 1; Main.Instance.AIDiscard(treeNode.state.lastDiscard); //Draw a card according to the node selected Main.Instance.lastDiscardCard = treeNode.state.lastDiscard; //Update game/board information MCTSIterate(); //Now the children number has became zero, we need to iterate to get children } } } } }
public void EmptyHand() { bool handWasTooFull = CardsInHand.Count > MaxHandSize; for (int ii = CardsInHand.Count - 1; ii >= 0; ii--) { Destroy(CardsInHand[ii].gameObject); } CardsInHand.Clear(); if (handWasTooFull) { HandIsNoLongerTooFullCallback(); } AdjustCardsInHandPosition(); }
// Use this constructor when generating a player for the first time. public Player(Deck deck, string name) { this.CardsInPlay = new List <List <Card> >(); // Instantiate the CardsInPlay with an empty list as the first element, to be used for money only. this.CardsInPlay.Add(new List <Card>()); this.CardsInHand = new List <Card>(); // Initialize the player's hand for (int i = 0; i < INITIAL_SIZE_OF_HAND; ++i) { CardsInHand.Add(deck.CardList[0]); deck.CardList.Remove(deck.CardList[0]); } this.Name = name; this.MoneyList = new MoneyList(); }
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(); } }
void PlayCard(GameResource resource) { ResourceCard newCard = Instantiate(ResourceCardPF, HandLocation); newCard.transform.position = HandLocation.position + Vector3.right * 12f; newCard.SetResource(resource); CardsInHand.Add(newCard); if (CardsInHand.Count() == MaxHandSize + 1) // we just drew the first overflowing card { HandIsTooFullCallback(); } else if (CardsInHand.Count() == 1) // this is our first card { MyAudioSource.clip = resource.ActiveCardSound; MyAudioSource.Play(); } AdjustCardsInHandPosition(); }
public Card PlayCard() { Console.WriteLine("Which card do you want to play?"); //TODO: Lite otydligt vilken siffra som motsvarar vilket kort, samma sak när man ska välja var kortet ska placeras ConsoleKey playCardChoice = Console.ReadKey().Key; int chosenCardIndex = (int)playCardChoice - (int)ConsoleKey.D1; //TODO: Lägga till int.TryParse för att fånga upp elaka/klantiga användare som inte skriver in siffror, samt om man skriver in en siffra out of range Card chosenCard = CardsInHand[chosenCardIndex]; if (chosenCard.Type == CardType.Creature) { Console.WriteLine("Where do you want to place your creature?"); ConsoleKey creaturePlacement = Console.ReadKey().Key; int chosenPlacementIndex = (int)creaturePlacement - (int)ConsoleKey.D1; CardsOnBoard[chosenPlacementIndex] = chosenCard; } CardsInHand.Remove(chosenCard); return(chosenCard); }
//Sorting method // // public void SortCardInHand() { List <string> tempCardOnHand = new List <string>(); for (actualCardValue = 0; actualCardValue < deck.Length; actualCardValue++) { foreach (string card in CardsInHand) { if (card == deck[actualCardValue]) { tempCardOnHand.Add(card); } } } CardsInHand.Clear(); //Clear list for adding temporary cards foreach (string karta in tempCardOnHand) { CardsInHand.Add(karta); } }
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; }