//manages if a card is dealt to the player OR if the tabletop device recalls cards public void HandleDidChangeRecord(string arg1, DatabaseEntry arg2, IDictionary arg3, string[] arg4) { Debug.Log ("GameObject Record Change Detected"); //if the card is dealt to us if (arg2.location == clientInit.playerName) { GameObject newCard = Instantiate (card1, new Vector3 (0f, 4.2f, -11.0f), card1.transform.rotation) as GameObject; newCard.name = "PlayingCard"; newCard.transform.Rotate (new Vector3 (0, 0, 180)); //keep the card face down GameObject.Find("Hand").GetComponent<HandManager>().resetShowingCards(); //reset the hand so that cards are facing down by default playingCard1 = newCard.GetComponent<PlayingCard> (); //set the PlayingCard component //sets the variables to a local copy of the card playingCard1.dbEntry.location = arg2.location; playingCard1.dbEntry.back = arg2.back; playingCard1.dbEntry.number = arg2.number; playingCard1.dbEntry.suit = arg2.suit; playingCard1.dbEntry._id = arg2._id; //keep track of this card and enable us to manipulate it playingCard1.AddToRecordGroup (); //pick the right face of a card to show string cardName = arg2.back + "" + arg2.number + "" + arg2.suit; foreach (Transform child in newCard.transform) { child.gameObject.GetComponent<MeshRenderer> ().enabled = false; child.gameObject.SetActive (false); if (child.gameObject.name == cardName) { child.gameObject.GetComponent<MeshRenderer> ().enabled = true; child.gameObject.SetActive (true); } } //move the card to the appropriate location if (cardInPosition1) { newCard.GetComponent<physicalCard> ().moveToTarget (GameObject.Find ("Hand/CardLocation1")); cardInPosition1 = false; } else { newCard.GetComponent<physicalCard> ().moveToTarget (GameObject.Find ("Hand/CardLocation2")); cardInPosition1 = true; } //set the parent to "Hand" so that "Hand can easily control the cards newCard.transform.parent = GameObject.Find ("Hand").gameObject.transform; //if the tabletop device is recalling the cards (to reshuffle) } else if (arg2.location == "deck") { //moves the cards to the discard pile on mobile screen //and re-syncs the database that the cards are at location 'deck' hand.GetComponent<HandManager>().Recall(); } //the card is neither being passed to us nor being recalled by the tabletop else { Debug.LogError ("this card does not belong to us, it belongs to: " + arg2.location); if (!production) { debugList.Add(arg2.location + arg2.number + arg2.suit); //Debug.Log ("added to list: " + arg2.location + arg2.number + arg2.suit); //clientInit.createMsgLog(arg2.location + "\n" + arg2.number + "\n" + arg2.suit, 1f); } } }
/// <summary> /// Stack the deck. /// </summary> /// <returns>The deck stacked.</returns> public PlayingDeck GetDeck() { PlayingDeck returnValue = new PlayingDeck(); returnValue.BackImage = String.Empty; returnValue.Name = String.Empty; returnValue.UndealtCards = new List<PlayingCard>(); PlayingCard card = new PlayingCard(); card.ImagePath = String.Empty; card.Name = "Ace of Spades"; card.Value = 14; returnValue.UndealtCards.Add(card); card = new PlayingCard(); card.ImagePath = String.Empty; card.Name = "Ace of Diamonds"; card.Value = 14; returnValue.UndealtCards.Add(card); card = new PlayingCard(); card.ImagePath = String.Empty; card.Name = "King of Hearts"; card.Value = 13; returnValue.UndealtCards.Add(card); return returnValue; }
public void Move(PlayingCard card, Point position) { var t = new Transition(new TransitionType_EaseInEaseOut(500)); t.add(card, "Left", position.X); t.add(card, "Top", position.Y); t.run(); }
/// <summary>Overload PlayingCard comparison.</summary> /// <param name="card"> the other card. </param> public override int CompareTo(PlayingCard card) { if (card is SuitPrecedencePlayingCard) { return this.CompareTo((SuitPrecedencePlayingCard)card); } return base.CompareTo(card); }
public void TestTopValue() { var card = new PlayingCard(PlayingCard.CardFace.Eight, PlayingCard.CardSuit.Hearts); var stack = new CardStack(); stack.Push(card); Assert.AreEqual(8, stack.TopValue); }
//four cards private bool CheckCorectnessInStopsMode(PlayingCard card, PlayingCard topCard) { if (topCard.Rank == CardRanks.Four && card.Rank == CardRanks.Four) { return(true); } else { return(false); } }
/// <summary> /// 抽牌比大小按鈕Click事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void DrawAndSpecificSize_Button_Click(object sender, EventArgs e) { //抽牌 PlayingCard Card1 = NotGhostCards.PumpingUnflop(0); PlayingCard Card2 = NotGhostCards.PumpingUnflop(0); PresentCards(Card1, Card2); Comparison(Card1, Card2); PresentingCardsCount(); Session["PlayingCardGroup"] = NotGhostCards; }
public void ChangeCardFromJockerCorrectly() { PlayingCard card = CreateCard(); card.ChangeCardFromJocker(CardSuits.Spade, CardRanks.Ace); Assert.AreEqual(CardSuits.Spade, card.Suit); Assert.AreEqual(CardRanks.Ace, card.Rank); Assert.AreEqual(true, card.CreatedByJocker); Assert.AreEqual(DemandOptions.Suits, card.Demands); }
public bool IsEqual(PlayingCard card2) { if (this.suit == card2.suit && this.type == card2.type) { return(true); } else { return(false); } }
//Stadard mode private static bool CheckCorectnessInStandardMode(PlayingCard newCard, PlayingCard topCard) { if (newCard.Rank == topCard.Rank || newCard.Suit == topCard.Suit) { return(true); } else { return(false); } }
private void writeCard(Label label, PlayingCard card) { if (card == null) { label.Content = "Hidden"; } else { label.Content = nameOfCard(card); } }
//TODO change to bool with "OUT" value public PlayingCard DealTopCard() { PlayingCard Card = new PlayingCard(); if (Cards.Count > 0) { Card = Cards[0]; Cards.RemoveAt(0); } return(Card); }
public void PlayingCardFactoryTest() { PlayingCard c1 = PlayingCard.Parse("AS"); Assert.AreEqual(PlayingCard.Ace, c1.Rank); Assert.AreEqual(CardSuit.Spades, c1.Suit); PlayingCard c2 = PlayingCard.Parse("4D"); Assert.AreEqual(4, c2.Rank); Assert.AreEqual(CardSuit.Diamonds, c2.Suit); }
public Texture2D GetCardTexture2D(PlayingCard card) { if (card == null) { return(null); } var cardIndex = (int)(card.NominalValue) + (int)card.Suit * 13; Debug.Log("CardIndex " + cardIndex); return(Cards[cardIndex]); }
private PlayingCard GiveCard(PlayerManager player) { PlayingCard cardToGive = cardsInStack[UnityEngine.Random.Range(0, cardsInStack.Count)]; photonView.RPC("RPC_AddCardToHandList", RpcTarget.All, cardToGive.photonView.ViewID); cardToGive.photonView.RequestOwnership(); cardToGive.AddToHand(player); return(cardToGive); }
public void NewRound() { playerCardAnim.SetTrigger("New Round"); kittyCardAnim.SetTrigger("BringIn"); Color newTrumpImage = new Color(255, 255, 255, 0); trumpImage.color = newTrumpImage; playerTricksScore = 0; opposingTricksScore = 0; trickCards = new PlayingCard[4]; if (dealer == 3) { turn = 0; leader = 0; } else { turn = dealer + 1; leader = dealer + 1; } Debug.Log(players[0].hand.Count); foreach (Transform child in playerHand.transform) { Destroy(child.gameObject); } for (int i = 0; i < 4; i++) { players[i].hand.Clear(); trickCards[i] = new PlayingCard((PlayingCard.cardtypes) 0, (PlayingCard.suits) 0, false); } for (int i = 0; i < 4; i++) { trickCardImages [i].enabled = false; } Shuffle(); Deal(); for (int i = 0; i < 5; i++) { AddCardToPlayer(players[0].hand[i]); } playerCardAnim.SetTrigger("RaiseHand"); DisplayKitty(true); curStage = gameStages.kittyRound; if (turn == 0) { layout = screenLayouts.kittyYourChoice; } else { layout = screenLayouts.kittyOthersChoice; StartCoroutine("AITurn"); } UpdateView(); }
public void YatesShuffleTest() { Deck deck = new Deck(true); deck.YatesShuffle(); PlayingCard notShuffled = deck.Cards.First(); PlayingCard shuffled = deck.ShuffledDeck.First(); Assert.AreNotEqual(notShuffled, shuffled); }
public void AddCardToPlayer(PlayingCard cardToAdd) { int suitIndex = (int)cardToAdd.suit; int typeIndex = (int)cardToAdd.type; GameObject pCard = (GameObject)Instantiate(cardObject, transform.position, Quaternion.identity); pCard.GetComponent <CardObject>().card = cardToAdd; pCard.transform.SetParent(playerHand.transform); pCard.GetComponent <Button>().onClick.AddListener(delegate() { this.ClickedCard(cardToAdd); }); pCard.GetComponent <Image>().sprite = cardSprites[suitIndex][typeIndex]; }
public void OnClick_TakeInsideCard(bool inside) { ActivePlayer = players[activePlayerIndex]; if (ActivePlayer.Player == PhotonNetwork.LocalPlayer) { PlayingCard cardToGive = GiveCard(ActivePlayer); //Check if the card value is the same as one in the hand if (cardToGive.value == activePlayer.hand[0].value || cardToGive.value == activePlayer.hand[1].value) { WrongAnswer(2); } else { //Find the highest and lowest card in hand int min, max; if (activePlayer.hand[0].value > activePlayer.hand[1].value) { min = activePlayer.hand[1].value; max = activePlayer.hand[0].value; } else { min = activePlayer.hand[0].value; max = activePlayer.hand[1].value; } if (inside) { if (!(cardToGive.value > min && cardToGive.value < max)) { WrongAnswer(1); } else { CorrectAnswer(); } } else { if (cardToGive.value > min && cardToGive.value < max) { WrongAnswer(1); } else { CorrectAnswer(); } } } NextMove(); } }
public void DisplayKitty(bool doDisplay) { kittyImage.enabled = doDisplay; if (doDisplay) { kittyCard = cardQ.Dequeue(); int suitIndex = (int)kittyCard.suit; int typeIndex = (int)kittyCard.type; kittyImage.sprite = cardSprites[suitIndex][typeIndex]; } }
PlayingCard GetHoveredCard() { RaycastHit2D hit = Physics2D.Raycast(GetMouseLocation(), Vector2.zero, float.MaxValue, PlayingCardLayer); if (hit.collider != null) { PlayingCard hitCard = hit.collider.gameObject.GetComponent <PlayingCard>(); return(hitCard); } return(null); }
void PlayCard(Unit target, PlayingCard card) { Attribute[] arr = new Attribute[target.attrs.Count]; target.attrs.Values.CopyTo(arr, 0); if (card.isNotOverflowing(arr)) { target.Buff(card.attributes); } //else{ //} }
//corectness of the card when there is Suit demanding private bool CheckCorectnessInSuitDemandingMode(PlayingCard card, PlayingCard topCard) { if ((topCard.Rank == CardRanks.Ace && card.Rank == CardRanks.Ace) || (card.Suit == demandedSuit)) { return(true); } else { return(false); } }
//corectness of the card when there is Rank demanding private bool CheckCorectnessInRankDemandingMode(PlayingCard card, PlayingCard topCard) { if ((topCard.Rank == CardRanks.Jack && card.Rank == CardRanks.Jack) || (card.Rank == demandedRank)) { return(true); } else { return(false); } }
//check the direction of the move private int ChangeDirectionOfMove(PlayingCard card) { if (card.NextMove == CardMoveDirections.Backward) { return(1); } else { return(0); } //0 - forward, 1 - backward }
public void Deck_Test_Deal_Five() { CardDeck testDeck = new CardDeck(); for (int i = 0; i < 5; i++) { PlayingCard expectedCard = testDeck.Cards[0]; PlayingCard testCard = testDeck.Deal(); Assert.That(testDeck.DeckCount, Is.EqualTo(51 - i)); Assert.That(expectedCard, Is.EqualTo(testCard)); } }
/// <summary> /// Requests for a move to be made by this client /// </summary> /// <param name="card">The card to play</param> public void RequestMove(PlayingCard card) { if (IsConnected) { GameMove move = new GameMove(myKnownPlayers[myPlayerId], card); NetOutgoingMessage msg = myPeer.CreateMessage(); msg.Write((byte)MessageType.SendMove); move.Encode(msg); Send(msg); } }
public void CanConvertFromString( Suit suit, FaceValue faceValue, string str) { // arrange var expectedCard = new PlayingCard(suit, faceValue); // act var actualCard = converter.FromString(str); // assert Assert.Equal(expectedCard, actualCard); }
public void DeckCtor2Test() { // with param Deck deck = new Deck(true); PlayingCard aceHigh = deck.Cards.Find(t => t.Face == CardFace.AceHigh); PlayingCard aceLow = deck.Cards.Find(t => t.Face == CardFace.AceLow); Assert.IsTrue(deck.Cards.Count == 52); Assert.IsNotNull(aceHigh); Assert.IsNull(aceLow); }
/// <summary> /// Creates a new CardBox and deals it to the specified panel /// </summary> /// <param name="panel"></param> public void DealCardToPanel(Panel panel, PlayingCard card) { CardBox pbCard = new CardBox(card); pbCard.FaceDown(); if (panel == pnlPlayerBottom || aiCardsVisible) { pbCard.FaceUp(); } panel.Controls.Add(pbCard); AlignCards(panel); }
public void CanConvertToString( Suit suit, FaceValue faceValue, string expected) { // arrange var card = new PlayingCard(suit, faceValue); // act string cardAsString = converter.ToString(card); // assert Assert.Equal(expected, cardAsString); }
/// <summary> /// Returns a card to the deck /// </summary> /// <param name="card">The card to put back in the deck</param> /// <param name="AllowDuplicates">Whether or not to allow two of the same card to exist in the group</param> /// <returns>False if the card was not added/returns> public bool Add(PlayingCard card, bool AllowDuplicates = false) { if (!(cards.Contains(card)) | AllowDuplicates) { cards.Add(card); return true; } else { return false; } }
/// <summary> /// Remove a single card from the deck. /// Will reshuffle if the deck currently contained it. /// </summary> /// <param name="card">Card to remove</param> public void Remove(PlayingCard card) { cards.Remove(card); if (inDeck.Contains(card)) { List <PlayingCard> remaining = new List <PlayingCard>(); remaining.AddRange(inDeck.ToArray()); remaining.Remove(card); ShuffleWith(remaining); } }
static void Main(string[] args) { Deck mtg = new Deck(); PlayingCard topCard = mtg.DealTopCard(); while (topCard != null) { Console.WriteLine(topCard); topCard = mtg.DealTopCard(); } Console.ReadLine(); }
public void PlayCard(PlayingCard cardToPlay) { trickCards[turn] = cardToPlay; trickAnim.SetTrigger("Out " + turn); trickCardImages[turn].enabled = true; int suitIndex = (int)trickCards[turn].suit; int typeIndex = (int)trickCards[turn].type; trickCardImages[turn].sprite = cardSprites[suitIndex][typeIndex]; trickAnim.SetTrigger("In " + turn); StartCoroutine("WaitAfterPlay"); }
public void RemoveCard(PlayingCard card) { // Update the card to show it's just been played. card.PreviousCard = true; hand.Remove(card); playedCards.Add(card); SortPlayedCardsOrder(); controller.StartCoroutine(controller.lerp.LerpMove2D(card.CardGO, handPosition, controller.turnCardPosition, handRotation, Quaternion.Euler(Vector3.zero), 0.3f, false)); timeOffset = Time.time + 0.3f; delay = true; endTurn = true; }
private void BtnHitMe_Click(object sender, RoutedEventArgs e) { PlayingCard p = game.Hit(currentPlayer); if (p != null) { DisplayCards(currentPlayer); } if (game.GetHandValue(currentPlayer) >= BlackJack.maxHandValue) { NextPlayer(); } }
//4. Check corectness private bool CorectnessOfPutedCard(PlayingCard card) { bool OK = CanTheCardBePlacedOnTheTable(card); if (!OK) { var logger = NLog.LogManager.GetCurrentClassLogger(); string text = "The cars passed as first to put on the table cannot be placed on the table in this circumstantions"; logger.Error(text); throw new ArgumentException(text); } return(OK); }
private static void PrintCardColored(PlayingCard card) { var foreground = Console.ForegroundColor; var background = Console.BackgroundColor; Console.BackgroundColor = ConsoleColor.White; Console.ForegroundColor = card.Suit == Suit.Clubs || card.Suit == Suit.Spades ? ConsoleColor.Black : ConsoleColor.Red; Console.Write(_cardConverter.ToString(card)); Console.ForegroundColor = foreground; Console.BackgroundColor = background; }
//public event EventHandler<GenericArgs<Control>> RemoveControlFromView; public void NewGame() { if (_table != null) { RemoveControl(_table); } if (_scoreBoard != null) RemoveControl(_scoreBoard); _table = new Table(); _table = new TableFactory().SetTable(_table); _scoreBoard = new ScoreBoardFactory().SetScoreBoard(); DisplayControlOnView(null, new GenericArgs<Control> { Value = _table }); DisplayControlOnView(null, new GenericArgs<Control> { Value = _scoreBoard }); foreach (var card in _table.Players[(int)Players.Player1].Hand.PlayersHand) { card.Click += delegate(object sender, EventArgs e) { _card = sender as PlayingCard; _waitObject.Set(); }; } }
static void Main() { Array suits = Enum.GetValues(typeof(Suit)); int [] nums = { 1,2,3,4,5,6,7,8,9,10,11,12,13 }; PlayingCard [] deck = new PlayingCard [ suits.Length * nums.Length + 2 ]; int i = 0; // index for deck AFs<PlayingCard> afs = new AFs<PlayingCard>(); // deck の中身を詰める。 foreach(Suit s in suits) { foreach(int n in nums) { deck[i] = new NormalCard(s,n); i++; } } deck[i ] = new JokerCard("!"); deck[i+1] = new JokerCard("?"); // 遊ぶ。 Console.WriteLine( afs.to_s(deck) ); afs.shuffle(deck); Console.WriteLine( afs.to_s(deck) ); }
public List<PlayingCard> NewDeck() { var deck = new List<PlayingCard>(); for (int i = 0; i < 52; i++) { var card = new PlayingCard { Suit = (i - i%13)/13, Id = i, CardNumber = i%13, CardName = ((CardNames)(i%13)) + "Of" + ((SuitNames)((i - i%13)/13)), BackgroundImageLayout = ImageLayout.Center, ImagePath = "c:/img/" + i + ".png", Image = Image.FromFile("c:/img/" + i + ".png"), BackImageVertical = Image.FromFile("c:/img/52.png"), BackImageHorizontal = Image.FromFile("c:/img/53.png"), Size = new Size(71, 96), }; deck.Add(card); } return deck; }
/// <summary> /// Add a card to the bottom of the queue. /// </summary> /// <param name="card">The card to add.</param> /// <remarks>It will not be added if the card is already in the queue.</remarks> public void StoreCard(PlayingCard card) { #region Param Checking if (card == null) { throw new ArgumentNullException("card"); } #endregion if (!this.Cards.Contains(card)) { this.Cards.Enqueue(card); } }
/// <summary> /// Retrieve the next card from the queue. /// </summary> /// <returns>The next card, or the "last card" if the player has none left.</returns> public PlayingCard GetNextCard() { switch (this.Cards.Count) { case 0: return _lastCard; case 1: _lastCard = this.Cards.Dequeue(); return _lastCard; default: return this.Cards.Dequeue(); } }
protected override void DoDealNewGame(object parameter) { // Call the base, which stops the timer, clears // the score etc. base.DoDealNewGame(parameter); // Spider solitaire starts with a score of 500. Score = 500; // Clear everything. stock.Clear(); foundation.Clear(); foreach (var tableau in tableaus) tableau.Clear(); // Create a list of card types. List<CardType> eachCardType = new List<CardType>(); for (int i = 0; i < 8; i++) { foreach (CardType cardType in Enum.GetValues(typeof(CardType))) { eachCardType.Add(cardType); } } // Create a playing card from each card type. // We just keep on adding cards of suits that depend on the // difficulty setting until we have the required 104. List<PlayingCard> playingCards = new List<PlayingCard>(); foreach (var cardType in eachCardType) { PlayingCard card = new PlayingCard() { CardType = cardType, IsFaceDown = true }; switch (Difficulty) { case Difficulty.Easy: // In easy mode, we have hearts only. if (card.Suit != CardSuit.Hearts) continue; break; case Difficulty.Medium: // In easy mode, we have hearts and spades. if (card.Suit == CardSuit.Diamonds || card.Suit == CardSuit.Clubs) continue; break; case Difficulty.Hard: // In hard mode we have every card. break; } // Add the card. playingCards.Add(card); // If we've got 104 we're done. if (playingCards.Count >= 104) break; } // Shuffle the playing cards. playingCards.Shuffle(); // Now distribute them - do the tableaus first. for (int i = 0; i < 54; i++) { PlayingCard card = playingCards.First(); playingCards.Remove(card); card.IsFaceDown = true; tableaus[i % 10].Add(card); } for (int i = 0; i < 10; i++) { tableaus[i].Last().IsFaceDown = false; tableaus[i].Last().IsPlayable = true; } // Finally we add every card that's left over to the stock. foreach (var playingCard in playingCards) { stock.Add(playingCard); } playingCards.Clear(); // And we're done. StartTimer(); }
private void DoMoveCard(ObservableCollection<PlayingCard> from, ObservableCollection<PlayingCard> to, PlayingCard card) { // Indentify the run of cards we're moving. List<PlayingCard> run = new List<PlayingCard>(); for (int i = from.IndexOf(card); i < from.Count; i++) run.Add(from[i]); // This function will move the card, as well as setting the // playable properties of the cards revealed. foreach(var runCard in run) from.Remove(runCard); foreach(var runCard in run) to.Add(runCard); // Are there any cards left in the from pile? if (from.Count > 0) { // Reveal the top card and make it playable. PlayingCard topCard = from.Last(); topCard.IsFaceDown = false; topCard.IsPlayable = true; } }
public IList<PlayingCard> GetCardCollection(PlayingCard card) { if (stock.Contains(card)) return stock; foreach (var tableau in tableaus) if (tableau.Contains(card)) return tableau; return null; }
public bool MoveCard(ObservableCollection<PlayingCard> from, ObservableCollection<PlayingCard> to, PlayingCard card, bool checkOnly) { // The trivial case is where from and to are the same. if (from == to) return false; // This is the complicated operation. int scoreModifier = 0; // We can move to a tableau only if: // 1. It is empty // 2. It is card suit S and we are suit S and Number N-1 if ((to.Count == 0) || (to.Count > 0 && //to.Last().Suit != card.Suit && (to.Last()).Value == (card.Value + 1))) { // Move from tableau to tableau, we always lose a point for this. scoreModifier = -1; } else return false; // If we were just checking, we're done. if (checkOnly) return true; // If we've got here we've passed all tests // and move the card and update the score. DoMoveCard(from, to, card); Score += scoreModifier; Moves++; // Check each tableau for sequences - then check for victory. CheckEachTableau(); CheckForVictory(); return true; }
/// <summary>Finds the best scoring PokerHand possible from the cards specified.</summary> /// <remarks> /// Uses a recursive algorithm where every run of the function generates the best possible hand /// containing the PlayingCard at the array position and the best possible hand that does not /// contain the PlayingCard at the array position. /// </remarks> /// <param name="cards">Array of cards from which to find the best scoring hand.</param> /// <param name="arrayPosition">Position indexing into the card's array, specifying the card to include and exclude.</param> /// <param name="cardsToSelect">Maximum number of cards out of which to create a PokerHand for scoring.</param> /// <param name="bestHand">The best scoring PokerHand found so far.</param> /// <param name="handInProgress">Array of cards being built up over recursive calls to this function.</param> /// <returns> /// The best scoring PokerHand formed from the cards passed into this arry starting /// at the index specified. /// </returns> private PokerHand GetBestHandPossible( PlayingCard[] cards, int arrayPosition, int cardsToSelect, PokerHand bestHand, PlayingCard[] handInProgress ) { // we have the necessary quantity of cards to select for a PokerHand // so create and compare the PokerHands if (handInProgress.Length == cardsToSelect) { return GetBestHand(bestHand, new PokerHand(handInProgress)); } // we have too few cards and have run out of cards to select if (arrayPosition == cards.Length) { return bestHand; } // catch whether we could not possibly get enough cards to form a hand from this // position of the array and on, we'd rather not waste the cycles on calls that // will not produce anything but bestHand as a result if (handInProgress.Length + (cards.Length - arrayPosition) < cardsToSelect) { return bestHand; } // choose to not select this card and move on PokerHand resultNoAdd = GetBestHandPossible( cards, arrayPosition + 1, cardsToSelect, bestHand, handInProgress); // choose to select this card and move on PlayingCard[] handInProgress2 = new PlayingCard[handInProgress.Length + 1]; handInProgress.CopyTo(handInProgress2, 0); handInProgress2[handInProgress.Length] = cards[arrayPosition]; PokerHand resultAdd = GetBestHandPossible( cards, arrayPosition + 1, cardsToSelect, bestHand, handInProgress2); // compare the result and return the best one if (resultNoAdd.HandSize() == PokerHand.StandardHandSize && resultAdd.HandSize() == PokerHand.StandardHandSize) { return GetBestHand(resultNoAdd, resultAdd); } return bestHand; }
/// <summary>Convert a Card to the URI for its Image</summary> /// <param name="card">A valid PlayingCard</param> /// <returns>URI for the Card's image</returns> public Uri CardToUri(PlayingCard card) { int suitIdentifier = 0; switch (card.Suit) { case PlayingCard.Suits.Club: suitIdentifier = 1; break; case PlayingCard.Suits.Spade: suitIdentifier = 2; break; case PlayingCard.Suits.Heart: suitIdentifier = 3; break; case PlayingCard.Suits.Diamond: suitIdentifier = 4; break; } int rankIdentifier = 14 - ((int)card.Rank); // 14 = Ace int cardIdentifier = (4 * (rankIdentifier)) + suitIdentifier; string uri = PlayingCardURIPrefix + cardIdentifier.ToString() + PlayingCardURISuffix; return new Uri(uri); }
/// <summary> /// Tries the move the card to its appropriate foundation. /// </summary> /// <param name="card">The card.</param> /// <returns>True if card moved.</returns> public bool TryMoveCardToAppropriateFoundation(PlayingCard card) { // Try the top of the waste first. if (waste.LastOrDefault() == card) foreach (var foundation in foundations) if (MoveCard(waste, foundation, card, false)) return true; // Is the card in a tableau? bool inTableau = false; int i = 0; for (; i < tableaus.Count && inTableau == false; i++) inTableau = tableaus[i].Contains(card); // It's if its not in a tablea and it's not the top // of the waste, we cannot move it. if (inTableau == false) return false; // Try and move to each foundation. foreach (var foundation in foundations) if (MoveCard(tableaus[i - 1], foundation, card, false)) return true; // We couldn't move the card. return false; }
//if you call this, you need to remove the record from PrizmRecordGroup.associates list as well public IEnumerator RemoveRecord(PlayingCard record) { Debug.LogError ("Removing from database: " + record.name + "with UID: " + record.dbEntry._id); var methodCall = Meteor.Method<ChannelResponse>.Call ("removeGameObject", record.dbEntry._id); yield return (Coroutine)methodCall; if (methodCall.Response.success) { Debug.LogError("Successfully removed from database, message: " + methodCall.Response.message); } else { Debug.LogError("Error removing " + record.dbEntry._id + " from database"); } }
/// <summary> /// Moves the card. /// </summary> /// <param name="from">The set we're moving from.</param> /// <param name="to">The set we're moving to.</param> /// <param name="card">The card we're moving.</param> /// <param name="checkOnly">if set to <c>true</c> we only check if we CAN move, but don't actually move.</param> /// <returns>True if a card was moved.</returns> public bool MoveCard(ObservableCollection<PlayingCard> from, ObservableCollection<PlayingCard> to, PlayingCard card, bool checkOnly) { // The trivial case is where from and to are the same. if (from == to) return false; // This is the complicated operation. int scoreModifier = 0; // Are we moving from the waste? if (from == Waste) { // Are we moving to a foundation? if (foundations.Contains(to)) { // We can move to a foundation only if: // 1. It is empty and we are an ace. // 2. It is card SN and we are suit S and Number N+1 if ((to.Count == 0 && card.Value == 0) || (to.Count > 0 && to.Last().Suit == card.Suit && (to.Last()).Value == (card.Value - 1))) { // Move from waste to foundation. scoreModifier = 10; } else return false; } // Are we moving to a tableau? else if (tableaus.Contains(to)) { // We can move to a tableau only if: // 1. It is empty and we are a king. // 2. It is card CN and we are color !C and Number N-1 if ((to.Count == 0 && card.Value == 12) || (to.Count > 0 && to.Last().Colour != card.Colour && (to.Last()).Value == (card.Value + 1))) { // Move from waste to tableau. scoreModifier = 5; } else return false; } // Any other move from the waste is wrong. else return false; } // Are we moving from a tableau? else if (tableaus.Contains(from)) { // Are we moving to a foundation? if (foundations.Contains(to)) { // We can move to a foundation only if: // 1. It is empty and we are an ace. // 2. It is card SN and we are suit S and Number N+1 if ((to.Count == 0 && card.Value == 0) || (to.Count > 0 && to.Last().Suit == card.Suit && (to.Last()).Value == (card.Value - 1))) { // Move from tableau to foundation. scoreModifier = 10; } else return false; } // Are we moving to another tableau? else if (tableaus.Contains(to)) { // We can move to a tableau only if: // 1. It is empty and we are a king. // 2. It is card CN and we are color !C and Number N-1 if ((to.Count == 0 && card.Value == 12) || (to.Count > 0 && to.Last().Colour != card.Colour && (to.Last()).Value == (card.Value + 1))) { // Move from tableau to tableau. scoreModifier = 0; } else return false; } // Any other move from a tableau is wrong. else return false; } // Are we moving from a foundation? else if (foundations.Contains(from)) { // Are we moving to a tableau? if (tableaus.Contains(to)) { // We can move to a tableau only if: // 1. It is empty and we are a king. // 2. It is card CN and we are color !C and Number N-1 if ((to.Count == 0 && card.Value == 12) || (to.Count > 0 && to.Last().Colour != card.Colour && (to.Last()).Value == (card.Value + 1))) { // Move from foundation to tableau. scoreModifier = -15; } else return false; } // Are we moving to another foundation? else if (foundations.Contains(to)) { // We can move from a foundation to a foundation only // if the source foundation has one card (the ace) and the // destination foundation has no cards). if (from.Count == 1 && to.Count == 0) { // The move is valid, but has no impact on the score. scoreModifier = 0; } else return false; } // Any other move from a foundation is wrong. else return false; } else return false; // If we were just checking, we're done. if (checkOnly) return true; // If we've got here we've passed all tests // and move the card and update the score. DoMoveCard(from, to, card); Score += scoreModifier; Moves++; // If we have moved from the waste, we must // make sure that the top of the waste is playable. if (from == Waste && Waste.Count > 0) Waste.Last().IsPlayable = true; // Check for victory. CheckForVictory(); return true; }
/// <summary> /// Whether the given card exists in this group /// </summary> /// <param name="card">The card to check for</param> /// <returns>Boolean</returns> public bool Contains(PlayingCard card) { return cards.Contains(card); }
private void Laydown() { if (IsEndOfRound()) return; _card = _table.Turn == (int)Players.Player1 ? _card : _gameBiz.Play(_table); if (_table.Laydown.IsEmpty()) _table.LaydownSuit = _card.Suit; //Ertu að gera fyrstur? set fyrsta spilið sem borðsort if (_table.Turn == (int)Players.Player1) { //Átt þú spilið sem er beðið um? if (_table.HasRequestedCard() && _card.Id != _table.RequestedCard.Id) return; //Þú átt ekki spilið sem er beðið um //Ert ekki fyrstur að setja niður, er liturinn sá sami og er í borðinu if (_card.Suit != _table.LaydownSuit && _table.Players[_table.Turn].Hand.PlayersHand.HasLaydownSuit(_table.LaydownSuit)) return; //liturinn er sá sami og er í borðinu eða þú átt ekki spil í borðsortinni, mátt leggja spilið niður } if (_card.Id == _table.RequestedCard.Id) RemoveControl(_table.RequestedCard); ProcessLaydown(); _waitObject.Reset(); }
public void LayDown(PlayingCard card, Point position) { Move(card, position); card.BackgroundImage = card.Image; card.Size = card.Image.Size; }
public void TestHighestCardStack() { var highestCard = new PlayingCard(PlayingCard.CardFace.Eight, PlayingCard.CardSuit.Hearts); var mDeck = new Mock<IDeck<PlayingCard>>(); mDeck.Setup(m => m.CardsLeft()).Returns(4); mDeck.SetupSequence(m => m.Deal()) .Returns(new PlayingCard(PlayingCard.CardFace.Three, PlayingCard.CardSuit.Spades)) .Returns(new PlayingCard(PlayingCard.CardFace.Five, PlayingCard.CardSuit.Spades)) .Returns(new PlayingCard(PlayingCard.CardFace.Five, PlayingCard.CardSuit.Spades)) .Returns(new PlayingCard(PlayingCard.CardFace.Two, PlayingCard.CardSuit.Spades)) .Returns(new PlayingCard(PlayingCard.CardFace.Three, PlayingCard.CardSuit.Hearts)) .Returns(highestCard) .Returns(new PlayingCard(PlayingCard.CardFace.Five, PlayingCard.CardSuit.Hearts)) .Returns(new PlayingCard(PlayingCard.CardFace.Two, PlayingCard.CardSuit.Hearts)); var board = new GameBoard(mDeck.Object); board.DealRound(); board.DealRound(); Assert.AreEqual(highestCard, board.HighestValueCardStack.Peek()); }
private void Request() { _table.RequestCard = _table.Turn == (int)Players.Player1 ? _card : _gameBiz.GetRequestCard(_table); _table.LaydownSuit = _table.RequestCard.Suit; if (_table.Turn == (int)Players.Player1) { FlashRequestCards(); } else { _card = _table.RequestCard; _table.RequestedCard = _gameBiz.GetRequestedCard(_table); _table.Invoke((MethodInvoker)delegate { _table.Controls.Add(_table.RequestedCard); }); } ProcessLaydown(); _table.IsRequest = false; }
/// <summary> /// Gets the card collection for the specified card. /// </summary> /// <param name="card">The card.</param> /// <returns></returns> public IList<PlayingCard> GetCardCollection(PlayingCard card) { if (stock.Contains(card)) return stock; if (waste.Contains(card)) return waste; foreach (var foundation in foundations) if (foundation.Contains(card)) return foundation; foreach (var tableau in tableaus) if (tableau.Contains(card)) return tableau; return null; }