public void AddDeckCardsToPile(ShitheadGameConfig config, Pile pile, CreateDeckOptions options) { var cards = new List <Card>(); for (var i = 1; i <= 13; i++) { cards.Add(new Card(pile, CardSuit.Clubs, i)); cards.Add(new Card(pile, CardSuit.Diamonds, i)); cards.Add(new Card(pile, CardSuit.Hearts, i)); cards.Add(new Card(pile, CardSuit.Spades, i)); } if (options.IncludeJokers) { for (var i = 0; i < 2; i++) { cards.Add(new Card(pile, CardSuit.Joker, config.Joker)); } } if (options.Shuffled) { _shuffler.Shuffle(cards); } foreach (var card in cards) { pile.Cards.Add(card); } }
public Tuple <IEnumerable <Player>, IEnumerable <Player> > GenerateTeams(List <Player> selectedPlayers) { int halfCount = (int)Math.Ceiling((decimal)selectedPlayers.Count / 2); decimal totalSum = selectedPlayers.Sum(p => (decimal)p.PointsPerGame); decimal target = decimal.Divide(totalSum, 2); List <IEnumerable <Player> > team1combinations = selectedPlayers.Combinations(halfCount).ToList(); List <Tuple <IEnumerable <Player>, IEnumerable <Player> > > solutions = new List <Tuple <IEnumerable <Player>, IEnumerable <Player> > >(); decimal bestDifferential = -1; foreach (var team1 in team1combinations.Select(p => p.ToList())) { var team1Temp = team1; decimal team1Score = team1Temp.Sum(p => (decimal)p.PointsPerGame); var team2Temp = selectedPlayers.Except(team1Temp).ToList(); decimal team2Score = team2Temp.Sum(p => (decimal)p.PointsPerGame); decimal totalDifferential = Math.Abs(team1Score - target) + Math.Abs(team2Score - target); if (bestDifferential == -1 || totalDifferential <= bestDifferential) { if (totalDifferential < bestDifferential) { // Everything found so far is not a solution, so wipe the list solutions = new List <Tuple <IEnumerable <Player>, IEnumerable <Player> > >(); } solutions.Add(new Tuple <IEnumerable <Player>, IEnumerable <Player> >(team1Temp, team2Temp)); bestDifferential = totalDifferential; } } _shuffler.Shuffle(solutions); return(solutions.First()); }
public void ShouldSortShuffledDeck() { var cardsFromInitDeck = _board.Decks[0].Cards; var shuffledCards = _shuffler.Shuffle(cardsFromInitDeck); var sortedCards = _sorter.Sort(shuffledCards); Assert.AreEqual(Rank.Ace, sortedCards[0].Rank); Assert.AreEqual(Color.Heart, sortedCards[0].Color); }
public IActionResult Shuffle(int id) { var deck = _game.Board.Decks.FirstOrDefault(d => d.Id == id); var cards = deck.Cards; deck.Cards = _shuffler.Shuffle(cards); return(Ok(_deckMapper.Map(deck))); }
public async Task ShuffleDeck(Deck deck) { await using var transaction = await dbContext.Database.BeginTransactionAsync(); shuffler.Shuffle(deck); await dbContext.SaveChangesAsync(); await transaction.CommitAsync(); }
public static void TheShufflerShufflesTheDeckXTimes(IShuffler shuffler, Deck before, out Deck after, int numberOfShuffles) { after = (Deck)before.Clone(); while (numberOfShuffles > 0) { after = shuffler.Shuffle(before); numberOfShuffles--; } }
public IPlayCoordinator Create(IEnumerable <IPlayer> players) { var shuffledPlayers = _playerShuffler.Shuffle(players).ToList(); if (!_playerCountConstraint.IsSatisfiedBy(shuffledPlayers)) { return(default(IPlayCoordinator)); } _gameStateConfigurationInitializer.ConfigureGame(shuffledPlayers); return(new PlayCoordinator(_turnFactory, _endConditionDetector, shuffledPlayers)); }
/// <summary> /// Таусем колоду карт. /// </summary> /// <param name="deck">Колода карт.</param> public async Task <IDeck> Shuffle(IDeck deck) { IList <ICard> cards = deck.Cards().ToList(); for (int count = 0; count < _settings.CurrentValue.ShuffleCount; count++) { cards = await _shuffler.Shuffle(cards); } deck.SetCards(cards); return(deck); }
public static int[,] GenerateField(IShuffler shuffler, int width = 8, int height = 4) { if (width * height % 2 == 1) { throw new ArgumentException(); } var ids = Enumerable.Range(1, width * height / 2); var cardsIds = ids.Concat(ids); cardsIds = shuffler.Shuffle(cardsIds); return(ParseIdsToField(cardsIds, width, height)); }
public void TestIfShuffleChangeTheOrder() { var shuffledNumbers = _shuffler.Shuffle(_numbers).ToList(); var different = false; for (int i = 0; i < NumbersCount; i++) { if (_numbers[i] != shuffledNumbers[i]) { different = true; break; } } Assert.IsTrue(different); }
public IActionResult ShuffleDeck(string name) { if (name == "names") { return(BadRequest(DeckErrorMessages.ForbiddenName(name))); } var deck = deckStorage.Get(name); if (deck == null) { return(BadRequest(DeckErrorMessages.NotFound(name))); } deck = new Deck(deck.Name, shuffler.Shuffle(deck.Cards)); var success = deckStorage.InsertOrUpdate(deck); return(success ? (IActionResult)Ok(deck) : StatusCode(500)); }
/// <summary> /// Shuffles the cards that are contained in the <c>cardDeck.</c> /// </summary> /// <param name="cardDeck">The card deck that contains the cards that you want to shuffle.</param> public void ShuffleCards(IList <CardDto> cardDeck) { _shufflerAlgorithm.Shuffle(cardDeck); }
public void ShuffleDeck() { ValidateNonEmptyDeck(); DeckOfCards.Deck = shuffler.Shuffle(DeckOfCards.Deck); }
private ushort RollDie() { return((ushort)_randomDieRoller.Shuffle(Die).First()); }
public static IEnumerable <int> ShuffleResult(List <int> data) { return(_shuffler.Shuffle(data)); }
public Deck Shuffle(Deck deck) { return(_shuffler.Shuffle(deck)); }
public void Shuffle() { _nextCardToDeal = 0; _shuffler.Shuffle(_deck); }
public IEnumerable <Card> Deal() => Shuffler.Shuffle(DeckGenerator.GenerateDeck());
public void ShufflePages() { _groupDao.SufflePages = _shuffler.Shuffle(_groupDao.DublicatedPages, Infrastructure.Common.Properties.GetInstance().Groups); }
public static List <T> Shuffle <T>(this IEnumerable <T> elements, IShuffler shuffler) { return(shuffler.Shuffle(elements)); }
public List <CardInMemory> Shuffle() { return(_shuffler.Shuffle(Cards).ToList()); }
public CardDeck Shuffle(IShuffler shuffler) { shuffler.Shuffle(deck); return(this); }