コード例 #1
0
        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);
            }
        }
コード例 #2
0
ファイル: TeamGenerator.cs プロジェクト: k-o-t-n/SfwFootball
        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());
        }
コード例 #3
0
        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);
        }
コード例 #4
0
        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)));
        }
コード例 #5
0
        public async Task ShuffleDeck(Deck deck)
        {
            await using var transaction = await dbContext.Database.BeginTransactionAsync();

            shuffler.Shuffle(deck);
            await dbContext.SaveChangesAsync();

            await transaction.CommitAsync();
        }
コード例 #6
0
ファイル: When.cs プロジェクト: dflynn1024/katas-2PC
        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--;
            }
        }
コード例 #7
0
        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));
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
ファイル: Game.cs プロジェクト: balandin228/team4
        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));
        }
コード例 #10
0
        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);
        }
コード例 #11
0
        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));
        }
コード例 #12
0
 /// <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);
 }
コード例 #13
0
        public void ShuffleDeck()
        {
            ValidateNonEmptyDeck();

            DeckOfCards.Deck = shuffler.Shuffle(DeckOfCards.Deck);
        }
コード例 #14
0
 private ushort RollDie()
 {
     return((ushort)_randomDieRoller.Shuffle(Die).First());
 }
コード例 #15
0
 public static IEnumerable <int> ShuffleResult(List <int> data)
 {
     return(_shuffler.Shuffle(data));
 }
コード例 #16
0
 public Deck Shuffle(Deck deck)
 {
     return(_shuffler.Shuffle(deck));
 }
コード例 #17
0
ファイル: Card.cs プロジェクト: bin0m/ObjectOrientedDesign
 public void Shuffle()
 {
     _nextCardToDeal = 0;
     _shuffler.Shuffle(_deck);
 }
コード例 #18
0
ファイル: Dealer.cs プロジェクト: Jaecen/Deckard
 public IEnumerable <Card> Deal()
 => Shuffler.Shuffle(DeckGenerator.GenerateDeck());
コード例 #19
0
 public void ShufflePages()
 {
     _groupDao.SufflePages = _shuffler.Shuffle(_groupDao.DublicatedPages, Infrastructure.Common.Properties.GetInstance().Groups);
 }
コード例 #20
0
 public static List <T> Shuffle <T>(this IEnumerable <T> elements, IShuffler shuffler)
 {
     return(shuffler.Shuffle(elements));
 }
コード例 #21
0
 public List <CardInMemory> Shuffle()
 {
     return(_shuffler.Shuffle(Cards).ToList());
 }
コード例 #22
0
 public CardDeck Shuffle(IShuffler shuffler)
 {
     shuffler.Shuffle(deck);
     return(this);
 }