public int Compare(Card?x, Card?y) { if (x is null && y is null) { return(0); } if (y is null) { return(1); } if (x is null) { return(-1); } if (x.Suit == y.Suit) { return(x.Rank.CompareTo(y.Rank)); } if (IsTrumpCard(x)) { return(1); } if (IsTrumpCard(y)) { return(-1); } return(0); }
public void SecondMarriagePart_GivenOtherCard_ReturnNull() { var card = new Card(Rank.Jack, Color.Clubs); Card?expected = null; Assert.Equal(expected, card.SecondMarriagePart); }
public override string ToString() { if (Count == 0) { return(string.Empty); } var sortedCards = this.OrderBy(card => card.Suit).ThenBy(card => card.Rank); var firstCard = sortedCards.First(); var builder = new StringBuilder(); Card?previousCard = null; foreach (var card in sortedCards) { if (!card.Equals(firstCard)) { string space = (previousCard.HasValue) && (previousCard.Value.Suit != card.Suit) ? " " : " "; builder.Append(space); } builder.Append(card); previousCard = card; } return(builder.ToString()); }
public bool Equals(Card?other) { return(other != null && DeckNo.Equals(other.DeckNo) && Suit.Equals(other.Suit) && Rank.Equals(other.Rank)); }
public async Task <Game> PlayGame(Card?card) { try { var player = (IHumanPlayer)CurrentPlayer; player.TakeTurn(card, _state); var response = new Game { BoardState = _board.GetGameBoardState(), History = await _state.GetHistory(), GameOver = await _state.IsGameOver(), PlayerHand = _humanPlayer.ShowHand(), NextPlayer = await GetNextPlayerAsync() }; CurrentPlayer = response.NextPlayer; return(response); } catch (Exception e) { throw; } }
public void Activate(Card?target, int positionInLink) { PositionInLink = positionInLink; Target = target; Card.State = Card.States.CanBeActivated; CanBeUsed = false; History.Add(new Activate(Controller, (Support)Card, this, target)); }
public void VoteCard(int card) { Card = new Card { Value = card, Hidden = true }; }
public void NewGame_CannotRepeatAddedCard() { Poker.NewGame(resetWildCard: true); card1 = new Card(CardSuit.Clubs, CardKind.Eight); card2 = new Card(CardSuit.Diamonds, CardKind.Eight); card3 = new Card(CardSuit.Clubs, CardKind.Eight); card4 = new Card(CardSuit.Spades, CardKind.Eight); card5 = new Card(CardSuit.Hearts, CardKind.Five); Assert.Throws <InvalidOperationException>(() => hand = new Hand(card1, card2, card3, card4, card5)); }
public Activate(ISource source, Support card, Manual skill, Card?target = null) { Player = (Player)source; Identity = GameEvents.Activate; Source = source; Card = card; Skill = skill; Target = target; PositionInLink = skill.PositionInLink; }
public void GetHighestInColor_ColorEmpty_ReturnHighestCard() { var cardsSetA = new CardsSet(new[] { new Card(Rank.Jack, Color.Diamonds), new Card(Rank.Ace, Color.Diamonds) }); Card?expected = null; var result = cardsSetA.GetHighestInColor(Color.Clubs); Assert.Equal(expected, result); }
IMakeABookingPaymentDetailsAuto IMakeABookingPaymentDetails.AutoFill() { this.paymentCardType = PaymentPageRnd.PickRandomPaymentCardType(); this.paymentCardNumber = PaymentPageRnd.PickRandomPaymentCardNumber(); this.paymentExpiryDate = PaymentPageRnd.PickRandomPaymentExpiryDate(); this.paymentSecurityCode = PaymentPageRnd.PickRandomPaymentSecurityCode(); this.paymentCardHolderName = PaymentPageRnd.PickRandomPaymentCardHolderName(); this.paymentPostCode = PaymentPageRnd.PickRandomPaymentPostCode(); return(this); }
public void Hand_ImpossibleFiveCards() { // 5 equal cards Poker.NewGame(resetWildCard: true); card1 = new Card(CardSuit.Spades, CardKind.Ace); card2 = new Card(CardSuit.Clubs, CardKind.Ace); card3 = new Card(CardSuit.Diamonds, CardKind.Ace); card4 = new Card(CardSuit.Spades, CardKind.Ace); card5 = new Card(CardSuit.Clubs, CardKind.Ace); Assert.Throws <InvalidOperationException>(() => hand = new Hand(card1, card2, card3, card4, card5)); }
public bool TryDraw(out Card?card) { if (!HasCards) { card = null; DeckIsEmpty?.Invoke(this, new EventArgs()); return(false); } card = Cards.Pop(); return(true); }
private void CardPanelMouseDown(object sender, MouseEventArgs e) { CardPanel clickedCardPanel = (CardPanel)sender; Spot cardSpot = clickedCardPanel.GetCard().GetSpot(); _followerCardPanels.Clear(); //markers cannot move if (!clickedCardPanel.GetCard().IsMarker) { if (cardSpot.GetPile() == Card.Pile.Stock) { clickedCardPanel.GetCard().SetSpot(new Spot(Card.Pile.Waste, FindTopCardInPile(new Spot(Card.Pile.Waste)).GetSpot().GetHeight() + 1)); clickedCardPanel.GetCard().SetFaceUp(); } //if (clickedCardPanel.GetCard() == FindTopCardInPile(cardSpot)) if (!clickedCardPanel.GetCard().GetFaceDown()) { _heldCardPanel = clickedCardPanel; _mouseOffset = e.Location; //finds all follower cards, revealed cards on top of the held card for (int i = cardSpot.GetHeight() + 1; i <= FindTopCardInPile( cardSpot).GetSpot().GetHeight(); i++) { Card?c = FindCardInSpot(new Spot(cardSpot.GetPile(), i, cardSpot.GetColumn())); if (c != null) { CardPanel?cPanel = FindCardPanelByCard(c); if (cPanel != null) { _followerCardPanels.Add(cPanel); } } } } } else { //when stock marker is clicked return waste cards to stock int j = FindTopCardInPile(new Spot(Card.Pile.Waste)).GetSpot().GetHeight(); for (int i = j; i > 0; i--) { Card?c = FindCardInSpot(new Spot(Card.Pile.Waste, i)); c?.SetSpot(new Spot(Card.Pile.Stock, j - i + 1)); c?.SetFaceDown(); } Score -= 100; } }
public static CardResponse?ToResponse(this Card?entity) => entity is null ? null : new CardResponse() { Id = entity.Id, Number = entity.Number, Type = (int)entity.Type, Created = entity.Created, ValidThru = entity.ValidThru, Cvc = entity.Cvc, Owner = entity.Owner, };
void RefreshKnowledge() { if (!stale_knowledge_) { return; } int colour = -1; int number = -1; bool multiple_colour = false; bool multiple_number = false; for (int i = 0; i < 5; i++) { for (int j = 0; j < 5; j++) { if (possible_[i][j]) { if (colour == -1) { colour = i; } else if (colour != i) { multiple_colour = true; } if (number == -1) { number = j; } else if (number != j) { multiple_number = true; } } } } Debug.Assert(colour != -1 && number != -1); // We shouldn't have elminated everything! if (!multiple_colour) { known_colour_ = colour; } if (!multiple_number) { known_number_ = number + 1; } if (!multiple_number && !multiple_colour) { known_card_ = new Card(colour, number + 1); } stale_knowledge_ = false; }
private WeightedSelection DoLevelSelection(GameState state) { WeightedSelection selection = new WeightedSelection(); if (state.Hand.Count == 1) { selection = DoLevelTrickSelection(state, state.Hand[0]); return(selection); } List <Card> playable = state.Hand.FindAll(a => !state.PossibleActions[a].IsThrowable); if (playable.Count > 0) { // Always take the Sette Bello if (playable.Contains <Card>(Card.SetteBello)) { selection = DoLevelTrickSelection(state, Card.SetteBello); return(selection); } List <WeightedSelection> possibles = new List <WeightedSelection>(); foreach (Card card in playable) { possibles.Add(DoLevelTrickSelection(state, card)); } List <WeightedSelection> actuals = Utilities.MaximumElements <WeightedSelection>(possibles, a => a.Weight); selection = actuals[0]; return(selection); } // All cards in hand are throwable Card?bestThrow = null; int maxWeight = Int32.MinValue; foreach (Card card in state.Hand) { // TODO: This does not take into account that throwing a card can enable a trick, // which should be given more weight than throwing a card that does not do so. int weight = -CalculateWeight(state.Tracker, card, new List <Card>(), false); if (weight > maxWeight) { bestThrow = card; maxWeight = weight; } } selection.SelectedCard = bestThrow; selection.SelectedTrick = new List <Card>(); selection.Weight = maxWeight; return(selection); }
public void InUseTest() { Deck deck = new(1); while (deck.GetPercentageLeft() > 0) { Card?card = deck.DrawNextCard(); if (card == null) { Assert.Fail("GetPercentageLeft() returned non-zero value, but there are no cards left"); } } Assert.Pass(); }
public static bool TryParse(string s, out Card?result) { var suit = s.Last(); var rank = new string(s.Take(s.Length - 1).ToArray()); if (CardService.Suits().Contains(suit) && CardService.Ranks().Contains <string>(rank)) { result = new Card(rank, suit); return(true); } result = null; return(false); }
public static CardComposite?FromCard(Card?card) { if (card == null) { return(null); } return(new CardComposite { deckno = card.DeckNo, rank = card.Rank, suit = card.Suit, }); }
public void Hand_Remove_Card_Removes_Card_From_Hand() { //Arrange/Act Card fiveClub = new Card(Rank.Five, Suit.Club); Card fourHeart = new Card(Rank.Four, Suit.Heart); Card threeSpade = new Card(Rank.Three, Suit.Spade); Hand hand = new Hand(new[] { fiveClub, fourHeart, threeSpade }); hand.RemoveCard(fourHeart); Card?fourHeartInHand = hand.FirstOrDefault(a => a.Rank == Rank.Four && a.Suit == Suit.Heart); Assert.That(fourHeartInHand, Is.Null); }
public override Card ChooseCard(IPlayer myself, GameState state) { Card?choosed = null; if (state.Dish.Count == 0) { choosed = TakeLiscio(myself.HandCards, state.Briscola); //choosed = choosed ?? TakePunti(myself.HandCards, state.Briscola); return(choosed.Value); } else { return(base.ChooseCard(myself, state)); } }
private void CardDroppedByPlayer(ref CardPanel cardPanelMoved, bool isFollower) { List <Spot> possibleSpots = GeneratePossibleSpots(cardPanelMoved.GetCard()); bool invalidDrop = true; foreach (Spot s in possibleSpots) { //other card is one below where the new card will be if checks complete successfully Card?otherCard = FindCardInSpot(new Spot(s.GetPile(), s.GetHeight() - 1, s.GetColumn())); if (otherCard != null) { CardPanel?otherCardPanel = FindCardPanelByCard(otherCard); if (otherCardPanel != null) { if (CheckForCardPanelOverlap(cardPanelMoved, otherCardPanel)) { //valid move Spot oldSpot = cardPanelMoved.GetCard().GetSpot(); cardPanelMoved.GetCard().SetSpot(s); invalidDrop = false; //adds one move if top of cards being moved if (!isFollower) { Moves += 1; } Card topOfOldSpot = FindTopCardInPile(oldSpot); if (topOfOldSpot.GetSpot().GetPile() == Card.Pile.Tableau && !topOfOldSpot.IsMarker) { //reveals card under card moved topOfOldSpot.SetFaceUp(); } MoveMade(oldSpot, s); break; } } } } if (invalidDrop) { cardPanelMoved.UpdateLocation(cardPanelMoved, null); } }
protected override Card OnHandle(IPlayer myself, GameState state, Watcher watcher) { Card?choice = null; if (state.IsBriscolaPlayed()) { choice = myself.StaiFuori(state); } else { bool ilCompagnoHaBriscola = true; // Rand.Next(1, 3) == 1; choice = myself.Supera(state, ilCompagnoHaBriscola); } return(choice ?? myself.HandCards.First()); }
public Card RequestPlay() { Card? card = null; if (status.LeadingPlayer > 0) { Suit s = status.CurrentPlay[(int)status.LeadingPlayer].Value.Suit; card = (from cr in cards where cr.Suit == s select cr).FirstOrDefault(); } if (card == null || card.Value.Value == 0) { card = cards[0]; } // cards.Remove(card.Value); cardToThrow = card; return card.Value; }
// DrawCard // // Copies the card at index 0 (the "top" of the deck), and returns it. // param out card: Card to draw if the deck has remaining cards // returns: true if card was successfully drawn // false if the deck is empty public bool DrawCard(out Card?card) { bool cardsRemaining = false; // We can't draw from an empty deck if (m_cards.Count > 0) { // Drawn cards are removed from the deck itself card = m_cards[0]; m_cards.RemoveAt(0); cardsRemaining = true; } else { card = null; } return(cardsRemaining); }
private bool CheckForWinStateChange(Card?p1, Card?p2) { if (p1 != null && p2 != null) { return(false); } else if (p1 != null && p2 == null) { winState = WinState.Player1; } else if (p1 == null && p2 != null) { winState = WinState.Player2; } else { winState = WinState.Draw; } return(true); }
public void TakeTurn(Card?card, IGameState state) { if (state == null) { throw new ArgumentNullException("state"); } var move = new MoveHistory { Player = this }; if (card != null) { _board.SetGameBoardState(card); UpdateHand(card, true); move.move = card; } state.AddMove(move); }
/// <summary> /// CheckPlayerStatus for commands. /// </summary> /// <param name="currentPlayerId">current player ID.</param> /// <param name="step">check the game step, null no check.</param> /// <param name="onlyAlivePlayer">true: only alive player, false: only dead player, null no check.</param> /// <param name="onlyCard">check if the player has this card, null no check.</param> /// <param name="commandName">command name.</param> /// <exception cref="CommandContextException">throws CommandContextException if check fails.</exception> internal void CheckPlayerStatus(string currentPlayerId, GameStep?step, PlayerState?onlyAlivePlayer, Card?onlyCard, string commandName) { var prefix = $":no_entry: The command {commandPrefix}{commandName} must be use "; if (CurrentGame == null) { throw new CommandContextException(prefix + "during the game. (No game started)"); } if (step != null && CurrentGame.Step != step) { throw new CommandContextException( prefix + $"during the {step.Value.ToDescription()}. (It's now the {CurrentGame.Step.ToDescription()})"); } var currentPlayer = GetCurrentPlayer(currentPlayerId); if (currentPlayer == null) { throw new CommandContextException(prefix + "when you are part of the game."); } if (onlyAlivePlayer != null && currentPlayer.State != onlyAlivePlayer) { throw new CommandContextException( prefix + $"when you are {onlyAlivePlayer.Value.ToDescription()}. (Now you are {currentPlayer.State.ToDescription()})"); } if (onlyCard != null && currentPlayer.Card != onlyCard) { throw new CommandContextException( prefix + $"when you are a {onlyCard.Value.ToDescription()}. (Now you are {currentPlayer.Card.ToDescription()})"); } }
public void SimulateGame() { List <Card> warPrizeCards = new List <Card>(); Card? p1Card = player1.getCard(); Card? p2Card = player2.getCard(); WinState warWinner; while (winState == WinState.Undecided) { warWinner = CompareCards((Card)p1Card, (Card)p2Card); warPrizeCards.AddRange(new List <Card> { (Card)p1Card, (Card)p2Card }); switch (warWinner) { case WinState.Player1: AddCardsToPlayer(warPrizeCards, player1); warPrizeCards = new List <Card>(); break; case WinState.Player2: AddCardsToPlayer(warPrizeCards, player2); warPrizeCards = new List <Card>(); break; case WinState.Draw: warPrizeCards.AddRange(CardsForWar()); break; } RoundsPlayed++; p1Card = player1.getCard(); p2Card = player2.getCard(); CheckForWinStateChange(p1Card, p2Card); } }
static void ParseDealtHand(string[] handLines, int currentLine, Player player) { const int maxCards = 4; for (int i = 1; i <= maxCards; i++) { string Line = handLines[currentLine + i]; if (Line[1] != 'C') { break; } Card?parsedCard = ParseCard(Line); if (parsedCard.HasValue) { if (player.HoleCards == null) { player.HoleCards = HoleCards.NoHolecards(); } player.HoleCards.AddCard(parsedCard.Value); } } }
public void RegisterCard(Card card) { ValidateCard(card); if (!mLeadingCard.HasValue) { mLeadingCard = card; } else { var initialSuit = mLeadingCard.Value.Suit; if ((card.Suit != initialSuit) && (!mGame.ActiveHand.VoidSuits.Contains(initialSuit))) mGame.ActiveHand.VoidSuits.Add(initialSuit); } mGame.ActiveHand.Cards.Remove(card); mPlayedCards.Add(card); mGame.ActiveHand.PlayedCard = card; mCardsUsed++; }
private void btn_ThrowCard_Click(object sender, RoutedEventArgs e) { if ((string)btn_ThrowCard.Content == "Pass") { if (lst_MyCards.SelectedItems.Count != 3) { MessageDialogClass dialog; dialog = new MessageDialogClass("3 cards, idiot!"); dialog.Show(DialogStyle.Modal); } else { System.Collections.ObjectModel.ObservableCollection<Card> lst = new System.Collections.ObjectModel.ObservableCollection<Card>(); lst.Add(((CardThumbnail)lst_MyCards.SelectedItems[0]).card); lst.Add(((CardThumbnail)lst_MyCards.SelectedItems[1]).card); lst.Add(((CardThumbnail)lst_MyCards.SelectedItems[2]).card); MainApp.client.SwitchCardsAsync(lst); btn_ThrowCard.IsEnabled = false; cards.Remove(((CardThumbnail)lst_MyCards.SelectedItems[0]).card); cards.Remove(((CardThumbnail)lst_MyCards.SelectedItems[1]).card); cards.Remove(((CardThumbnail)lst_MyCards.SelectedItems[2]).card); RecieveCards(); } } else { if ((string)btn_ThrowCard.Content == "Play") { Card c = ((CardThumbnail)lst_MyCards.SelectedItem).card; cardToThrow = c; MainApp.client.PlayCardAsync(c); btn_ThrowCard.IsEnabled = false; } } }
public void UpdateRoundStatus(RoundStatus status) { // check if the state has changed if (status.Statek__BackingField != currentStatus.Statek__BackingField) { StartNewState(status.Statek__BackingField, status); } // if waiting for approval for card to throw if (cardToThrow != null && status.Statek__BackingField == RoundState.Playing) { cards.Remove(cardToThrow.Value); RecieveCards(); cardToThrow = null; } lbl_state.Content = status.Statek__BackingField.ToString(); // highlight current player currentStatus = status; Brush red = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0)); Brush black = new SolidColorBrush(Color.FromArgb(255, 0, 0, 0)); lbl_Name0.Foreground = black; lbl_Name1.Foreground = black; lbl_Name2.Foreground = black; lbl_Name3.Foreground = black; switch (status.PlayerTurnk__BackingField) { case PlayerSeat.Self: lbl_Name0.Foreground = red; break; case PlayerSeat.West: lbl_Name1.Foreground = red; break; case PlayerSeat.North: lbl_Name2.Foreground = red; break; case PlayerSeat.East: lbl_Name3.Foreground = red; break; } // update bids var bids = (from b in status.Biddingsk__BackingField select b.HasValue ? String.Format("{0} {1}", b.Value.Amountk__BackingField, b.Value.Suitk__BackingField.ToString()) : "").ToArray(); UpdateBids(bids); // update cards ShowCards(status.CurrentPlayk__BackingField.ToArray()); UpdateTakes(status.TricksTakenk__BackingField.ToArray()); }
public void UpdateRoundStatus(RoundStatus status) { this.status = status; if (cardToThrow != null) { cards.Remove(cardToThrow.Value); cardToThrow = null; } }
public void ResetRound() { mPlayedCards.MoveTo(mDiscards); foreach (var hand in mGame.Hands) hand.PlayedCard = null; mLeadingCard = null; }