public static string StartGame(Player player, Dealer dealer, Deck gameDeck) { System.Console.WriteLine("You currently have {0} dollars.", player.money); gameDeck.Reset(); gameDeck.Shuffle(); player.hand.Clear(); dealer.hand.Clear(); player.DrawFrom(ref gameDeck); dealer.DrawFrom(ref gameDeck); player.DrawFrom(ref gameDeck); ShowCards(player, dealer); string returnVal = Gameplay.Action(player, dealer, gameDeck); return(returnVal); }
private static void Main(string[] args) { var deck = new Deck(); bool isStillRunning = true; ICardPrinter cardPrinter = new ConsoleCardPrinter(); do { switch (ShowMenu()) { case 1: { PrintNumberOfCards(deck); break; } case 2: { Shuffle(deck); break; } case 3: { ShowOneHand(deck, cardPrinter); break; } case 4: { deck.Reset(); break; } case 5: { GiveMeTheBestHand(deck, cardPrinter); break; } case 6: { isStillRunning = CheckIfTheUserWantsToCloseTheApplication(); break; } } } while (isStillRunning); }
static void Main(string[] args) { IPrintMethod outputMethod = new PrintConsoleMethod(); IDeck deck = new Deck(outputMethod); PrintDivision("1st print after deck creation."); deck.Print(); PrintDivision("2nd print after deck shuffle."); deck.Shuffle(); deck.Print(); PrintDivision("3rd print after deck reset."); deck.Reset(); deck.Print(); }
// Use this for initialization void Start() { deck = new Deck(52); player1 = new Hand("Player 1", 6); player2 = new Hand("Player 2", 6); deck.Deal(new List <Hand>() { player1, player2 }); player1.Print(); player2.Print(); deck.PrintSize(); deck.Reset(); deck.PrintSize(); }
static void Main(string[] args) { Player me = new Player("Taylor"); Deck newDeck = new Deck(); newDeck.Shuffle(); me.Draw(newDeck); me.Draw(newDeck); me.Draw(newDeck); me.Draw(newDeck); me.Draw(newDeck); me.Discard(1); me.Draw(newDeck); newDeck.Reset(); }
public void Reset() { if (isLocalPlayer) { CmdResetPlayerResources(); } if (deck) { deck.Reset(); } if (hand) { hand.Reset(); } if (arena) { arena.Reset(); } }
public void Cleanup() { foreach (Player p in system.Players) { p.currentBet = 0; p.isFeld = false; p.RemoveCards(); } foreach (CenterCards c in centerCards) { c.card = null; } //here we set the deck by reseting it, mixing it, and form the objets gDeck.Reset(CardsSplitter.toolsSplitter); gDeck.Mix(); SetDeck(); currentPot = 0; }
public void Reset_DeckResetsToFullDeck_CardsReset() { int cardsToDeal = 15; Deck deck = new Deck(); deck.DealCards(cardsToDeal, false); PrivateObject obj = new PrivateObject(deck); int expectedCards = (deck.TOTAL_CARDS * deck.NumberOfDecks) - cardsToDeal; int actualCards = deck.GetCardsRemaining(); Assert.AreEqual(expectedCards, actualCards); deck.Reset(1); int expected = cardsInADeck; int actual = deck.GetCardsRemaining(); Assert.AreEqual(expected, actual); }
private void OnGUI() { if (GUI.Button(new Rect(10, 10, 100, 28), "Shuffle")) { _deck.Shuffle(); } if (GUI.Button(new Rect(10, 40, 100, 28), "Deal")) { _deck.Deal(_playerOne, _playerTwo); } if (GUI.Button(new Rect(10, 70, 100, 28), "Reset")) { _deck.Reset(); } if (GUI.Button(new Rect(10, 100, 100, 28), "Log")) { _deck.Log(); } }
public void TestTakenCardsAreUnique() { Deck deck = Deck.CreateDeck(true); List <Card> takenCards = new List <Card>(); for (int i = 0; i < Deck.CardsInDeck; i++) { Card takenCard = deck.TakeCard(); Assert.DoesNotContain(takenCard, takenCards); takenCards.Add(takenCard); } takenCards.Clear(); deck.Reset(); deck.Shuffle(); for (int i = 0; i < Deck.CardsInDeck; i++) { Card takenCard = deck.TakeCard(); Assert.DoesNotContain(takenCard, takenCards); takenCards.Add(takenCard); } }
public void TestReset() { Deck deck = Deck.CreateDeck(false); // memorize the first taken card Card cardFromDeck = deck.TakeCard(); Assert.NotNull(cardFromDeck); // take the rest cards for (int i = 0; i < Deck.CardsInDeck - 1; i++) { deck.TakeCard(); } Assert.Null(deck.TakeCard()); deck.Reset(); Card cardFromDeckAfterReset = deck.TakeCard(); Assert.NotNull(cardFromDeckAfterReset); // it should match the first card taken before reset Assert.Equal(cardFromDeckAfterReset, cardFromDeck); }
static void Main(string[] args) { System.Console.WriteLine("Welcome to Black Jack!"); var again = "y"; Boolean isGameOver = false; Deck deck = new Deck(); deck.Shuffle(); Player dealer = new Player("dealer"); Player player = new Player("player"); while (again == "y" && !isGameOver) { System.Console.WriteLine("New Round has started..."); var isRoundOver = false; Boolean isWinner; var bet = 0; dealer.Draw(deck); player.Draw(deck); dealer.Draw(deck); player.Draw(deck); Console.WriteLine("Dealers visible card:"); dealer.ShowSecondCard(); Console.WriteLine(""); Console.WriteLine("Your cards are:"); player.ShowCards(); Console.WriteLine(""); //Ask for bet. while (true) { Console.WriteLine($"Bet between 1 and {player.coins}"); string tryint = Console.ReadLine(); if (Int32.TryParse(tryint, out int intBet)) { bet = intBet; } else { bet = 0; } if (bet >= 1 && bet <= player.coins) { player.PlaceBet(bet); Console.WriteLine($"Player has {player.coins} coins remaining."); break; } } // Player draws. while (!isRoundOver && player.getHandScore <= 21) { // Ask if player hits or stays. Console.WriteLine("Hit? y/n"); string input = Console.ReadLine(); // If player hits, draw and show new card. if (input == "y") { Card dealtCard = player.Draw(deck); player.ShowCardA(dealtCard.getStringVal, dealtCard.getSuit); } // If player stays, round ends and dealer may draw. else { isRoundOver = true; } // Change Ace value to 1 if necessary. player.CheckAce(); } // Dealer draws. while (dealer.getHandScore < 15) { dealer.Draw(deck); Console.WriteLine($"Dealer draws card #{dealer.getCardCount}."); // Change Ace value to 1 if necessary. dealer.CheckAce(); } //Round is over, display all cards. Console.WriteLine(""); Console.WriteLine("~~~~~~Dealers cards are:~~~~~~"); dealer.ShowCards(); Console.WriteLine($"Dealer total is {dealer.getHandScore}."); Console.WriteLine(""); Console.WriteLine("~~~~~~Your cards are:~~~~~~"); player.ShowCards(); Console.WriteLine($"Player total is {player.getHandScore}."); // Check win condition. if (player.getHandScore > 21) { isWinner = false; player.PrintLose(); } else if (dealer.getHandScore > 21) { isWinner = true; player.PrintWin(); } else if (dealer.getHandScore == player.getHandScore) { isWinner = false; player.coins += bet; player.PrintPush(); } else if (dealer.getHandScore > player.getHandScore) { isWinner = false; player.PrintLose(); } else { isWinner = true; player.PrintWin(); } // Clear cards and reset deck. player.DiscardAll(); dealer.DiscardAll(); deck.Reset(); deck.Shuffle(); //Update Coins (and reset bet). player.BetResult(isWinner); // Display winnings. Console.WriteLine($"Player has {player.coins} coins."); // Check if player can play again. if (player.coins <= 0) { isGameOver = true; break; } // Play again or end game. Console.WriteLine("Play again? y/n"); again = Console.ReadLine(); } // Display game end condition result. if (player.coins > 0) { Console.WriteLine($"Player ended the game with {player.coins} coins."); } else { Console.WriteLine("You are broke. Goodbye!"); } }
public void Cards_Test() { Deck deck = new Deck("Deck", 2); Assert.AreEqual(54, deck.Cards.Length); Assert.AreEqual(deck.Cards.Length, deck.Count); CardGroup <PlayingCard> hand1 = new CardGroup <PlayingCard>("Hand1"); CardGroup <PlayingCard> hand2 = new CardGroup <PlayingCard>("Hand2"); CardGroup <PlayingCard> hand3 = new CardGroup <PlayingCard>("Hand3"); CardGroup <PlayingCard> spare1 = new CardGroup <PlayingCard>("Spare1"); CardGroup <PlayingCard> spare2 = new CardGroup <PlayingCard>("Spare2"); CardGroup <PlayingCard> spare3 = new CardGroup <PlayingCard>("Spare3"); CardGroup <PlayingCard>[] hands = new CardGroup <PlayingCard>[] { hand1, hand2, hand3 }; List <CardGroup <PlayingCard> > handsList = new List <CardGroup <PlayingCard> > { hand1, hand2, hand3 }; CardGroup <PlayingCard>[] spares = new CardGroup <PlayingCard>[] { spare1, spare2, spare3 }; List <CardGroup <PlayingCard> > sparesList = new List <CardGroup <PlayingCard> > { spare1, spare2, spare3 }; deck.InitialiseGroup(new CardGroup <PlayingCard>[] { hand1, hand2, hand3, spare1, spare2, spare3 }); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(hand1, hand2, hand3); foreach (CardGroup <PlayingCard> hand in hands) { Assert.AreEqual(18, hand.Count); } deck.Reset(); Assert.AreEqual(0, hand1.Count); Assert.AreEqual(0, hand2.Count); Assert.AreEqual(0, hand3.Count); Assert.AreEqual(0, spare1.Count); Assert.AreEqual(0, spare2.Count); Assert.AreEqual(0, spare3.Count); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(hands); foreach (CardGroup <PlayingCard> hand in hands) { Assert.AreEqual(18, hand.Count); } deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(handsList); foreach (CardGroup <PlayingCard> hand in handsList) { Assert.AreEqual(18, hand.Count); } deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(hands, 7); foreach (CardGroup <PlayingCard> hand in hands) { Assert.AreEqual(7, hand.Count); } deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(handsList, 7); foreach (CardGroup <PlayingCard> hand in handsList) { Assert.AreEqual(7, hand.Count); } deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(hands, 7, spare1); foreach (CardGroup <PlayingCard> hand in hands) { Assert.AreEqual(7, hand.Count); } Assert.AreEqual(33, spare1.Count); deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(handsList, 7, spare1); foreach (CardGroup <PlayingCard> hand in handsList) { Assert.AreEqual(7, hand.Count); } Assert.AreEqual(33, spare1.Count); deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(hands, 7, spares); foreach (CardGroup <PlayingCard> hand in hands) { Assert.AreEqual(7, hand.Count); } foreach (CardGroup <PlayingCard> hand in spares) { Assert.AreEqual(11, hand.Count); } deck.Reset(); deck.Shuffle(); deck.Deal <CardGroup <PlayingCard> >(handsList, 7, sparesList); foreach (CardGroup <PlayingCard> hand in handsList) { Assert.AreEqual(7, hand.Count); } foreach (CardGroup <PlayingCard> hand in sparesList) { Assert.AreEqual(11, hand.Count); } deck.Reset(); deck.ReleaseGroup(new CardGroup <PlayingCard>[] { hand1, hand2, hand3, spare1, spare2, spare3 }); Deck newDeck = new Deck("Deck", 0); CardGroup <PlayingCard> gameHand1 = new CardGroup <PlayingCard>("Hand1"); CardGroup <PlayingCard> gameHand2 = new CardGroup <PlayingCard>("Hand2"); CardStack <PlayingCard> drawPile = new CardStack <PlayingCard>("Draw Pile"); newDeck.InitialiseGroup(gameHand1, gameHand2, drawPile); newDeck.Deal <ICardGroup <PlayingCard> >(new CardGroup <PlayingCard>[] { gameHand1, gameHand2 }, 7, drawPile, false); newDeck.ReleaseGroup(gameHand1, gameHand2);// These still have cards newDeck.Reset(); Assert.AreEqual(7, gameHand1.Count); // Hand hasn't returned cards! Assert.AreEqual(7, gameHand2.Count); // Hand hasn't returned cards! Assert.AreEqual(0, drawPile.Count); Assert.AreEqual(52, newDeck.Count);// All cards appear to have been returned but hands still reference some! }
/// <summary> /// Initialises a hand but otherwise leaves all data untouched. /// Assumes that the hand and bonus hand values are already appropriately assigned. /// </summary> protected void InitHand() { // State variables AvailableTile = null; OnReplacement = 0; Heavenly = true; Earthly = true; HandFinished = true; // Resets ResetMoves(); Deck.Reset(); // Deal each player a new hand MahjongPlayer[] mp = new MahjongPlayer[4]; for (int i = 0; i < 4; i++) { mp[i] = players[i] as MahjongPlayer; // Discard old cards while (players[i].CardsInHand.CardsInHand > 0) { players[i].CardsInHand.PlayCard(0); } while (mp[i].BonusTiles.CardsInHand > 0) { mp[i].BonusTiles.PlayCard(0); } mp[i].Melds.Clear(); // Draw the initial thireen tiles players[i].CardsInHand.DrawCards(Deck.Draw(13)); // If a player has bonus tiles, we need to replace them RemoveBonusTiles(players[i], mp[i]); // Set the new seat winds and prevailing wind mp[i].SeatWind = PlayerToWind(i); // We do have that rotate wind function, but we don't know if this is a bonus hand or not, so let's not chance it mp[i].PrevailingWind = PrevailingWind; } // Set the active player to be east for (int i = 0; i < 4; i++) { if (mp[i].SeatWind == SuitIdentifier.EAST_WIND) { ActivePlayer = i; SubActivePlayer = i; break; } } // Give east their first draw, and make sure the draw wasn't a bonus tile DrawFromWall(players[ActivePlayer], mp[ActivePlayer]); return; }
/// <summary> /// Request for the recovery of the previously saved state of the game /// </summary> /// <returns>Returns True is recovered successfully</returns> internal async Task<bool> Recover() { stateObject = await Logger.Recovery.Recover<StateObject>(); deck.Reset(stateObject); // Updating the deck state return stateObject == null ? false : true; }
public override void Reset() { base.Reset(); deck.Reset(); }
public void GameLoopEsp() { bool exit = false; int nIsAbsent; do { do { ShowExitEsp(); for (int i = 0; i < Players.Count - 1; i++) { //1 Check user input MovementsEsp(); // Payment of blinds if (Players[i].bigBlind) { int big = 200; Players[i].Chips -= big; pot += big; } if (Players[i].smallBlind) { int small = 100; Players[i].Chips -= small; pot += small; } if (!isAbsent) { //2 Movements if (Index < Players.Count - 1) { Index++; // Sound to inform about the turn of another player Console.Beep(600, 1000); //Update Pot DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } else { Index = 0; Console.Beep(600, 1000); //Update Pot DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } } else { nIsAbsent = Index; if (Index < Players.Count - 1) { Index++; } else { Index = 0; } } DrawCard.UpdateChipsEsp(Players); } // 3 firsts cards of the middle if (allIsPlay) { Flop(Deck); allIsPlay = false; for (int i = 0; i < Players.Count; i++) { MovementsEsp(); if (!isAbsent) { //2 Movements if (Index < Players.Count - 1) { Index++; // Sound to inform about the turn of another player Console.Beep(600, 1000); //Update Pot DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } else { Index = 0; Console.Beep(600, 1000); //Update Pot DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } } else { nIsAbsent = Index; if (Index < Players.Count - 1) { Index++; } else { Index = 0; } } } } else { allIsPlay = false; } if (allIsPlay) { Turn(Deck); for (int i = 0; i < Players.Count; i++) { MovementsEsp(); if (Index < Players.Count - 1) { Index++; Console.Beep(600, 1000); DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } else { Index = 0; Console.Beep(600, 1000); //Update Pot DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } } } else { allIsPlay = false; } // The last card of the middle if (allIsPlay) { River(Deck); for (int i = 0; i < Players.Count; i++) { MovementsEsp(); if (Index < Players.Count - 1) { Index++; Console.Beep(600, 1000); DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } else { Index = 0; Console.Beep(600, 1000); //Update Pot DrawCard.DrawPot(pot); DrawCard.UpdateChipsEsp(Players); } } } else { allIsPlay = false; } } while (!allIsPlay); for (int timesToShuffle = 0; timesToShuffle < 10; timesToShuffle++) { Deck.Shuffle(); } // Update cards after the turn CheckCardsEsp(Players, Deck); DrawCard.UpdateChipsEsp(Players); DrawCard.DrawTableEsp(Deck); DrawCard.DrawEsp(Players, Deck); //DrawCard.DrawResult(Players); pot = 0; Index = 0; Deck.Reset(); round++; } while (!exit); }
void GameOver() { messagerLogic.GameOver(); deckLogic.Reset(); handLogic.Reset(); }
public void Execute(Deck deck, RoundContext roundContext) { roundContext.MoveToNextRound(); deck.Reset(); }