Ejemplo n.º 1
0
        public MainViewModelDesignData()
        {
            var game = Config.BuildDefaultGame();
            var me   = game.Players.Last();

            var random = new Random();

            Solver = new Solver(game, me);

            var shuffledCards = game.Categories
                                .SelectMany(category => category.Cards)
                                .OrderBy(card => random.Next())
                                .Skip(game.CardsPerSuggestion) // the answer
                                .ToArray();

            var cardsPerHand = shuffledCards.Length / game.Players.Count;

            foreach (var card in shuffledCards.Take(cardsPerHand))
            {
                Solver.PlayerHasCard(me, card, $"{me.Name} was dealt card.");
            }

            Solver.PlayerHasCard(game.Players.First(), shuffledCards.Skip(cardsPerHand).First(), "Player has card");
            Solver.PlayerMightHaveCards(game.Players.Skip(1).First(), shuffledCards.Skip(cardsPerHand + 1).Take(game.CardsPerSuggestion), "Player has card");
            Solver.PlayerDoesNotHaveCards(game.Players.Skip(2).First(), shuffledCards.Skip(cardsPerHand + game.CardsPerSuggestion + 1).Take(game.CardsPerSuggestion), "Player has card");
            Solver.SuggestionLooped(game.Players.First(), shuffledCards.Skip(cardsPerHand + 2 * game.CardsPerSuggestion + 1).Take(game.CardsPerSuggestion));
            Solver.SuggestionLooped(game.Players.First(), shuffledCards.Skip(cardsPerHand + 3 * game.CardsPerSuggestion + 1).Take(game.CardsPerSuggestion));
            Solver.SuggestionLooped(game.Players.Skip(1).First(), shuffledCards.Skip(cardsPerHand + 4 * game.CardsPerSuggestion + 1).Take(game.CardsPerSuggestion));

            shuffledCards.Last().IsPartOfAccusation = true;


            PromptForSuggestionResult?.Invoke(this, null);
            PromptForSimpleResponse?.Invoke(this, null);
        }
Ejemplo n.º 2
0
        private bool GetSuggestionResponse(Player player, ref bool stopped)
        {
            if (ReferenceEquals(player, _solver.MyPlayer))
            {
                var prompt = new SimplePrompt("Hit OK when done.", "Hit OK when done.", MessageBoxButton.OK, MessageBoxImage.None);
                PromptForSimpleResponse?.Invoke(this, prompt);
                if (player.Hand.Intersect(_selectedCards).Any())
                {
                    _solver.Changes.Add(new SuggestionResponse(DateTime.Now, player, "?"));
                    stopped = true;
                    return(false);
                }
                _solver.Changes.Add(new SuggestionResponse(DateTime.Now, player, null));
                return(true);
            }

            _currentAsk = new SuggestionResponseViewModel(PlayerTakingTurn, player, _solver.MyPlayer.IsTakingTurn, _selectedCards);
            PromptForSuggestionResult?.Invoke(this, _currentAsk);
            var addedChange = false;

            try
            {
                switch (_currentAsk.Result)
                {
                case DialogResult.Cancel:
                    return(false);

                case DialogResult.Skip:
                    return(true);

                case DialogResult.Maybe:
                    _solver.Changes.Add(new SuggestionResponse(DateTime.Now, player, "?"));
                    addedChange = true;
                    _solver.PlayerMightHaveCards(player, _selectedCards,
                                                 $"{player.Name} showed a card to {PlayerTakingTurn.Name}.");
                    stopped = true;
                    return(false);

                case DialogResult.None:
                    _solver.Changes.Add(new SuggestionResponse(DateTime.Now, player, null));
                    addedChange = true;
                    _solver.PlayerDoesNotHaveCards(player, _selectedCards,
                                                   $"{player.Name} said they didn't have this card when asked.");
                    return(true);

                case DialogResult.Card:
                    _solver.Changes.Add(new SuggestionResponse(DateTime.Now, player, _currentAsk.ResultCard.Name));
                    addedChange = true;
                    _solver.PlayerHasCard(player, _currentAsk.ResultCard, $"{player.Name} showed me {_currentAsk.ResultCard}.");
                    stopped = true;
                    return(false);

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }
            catch (GameException)
            {
                if (addedChange)
                {
                    _solver.Changes.RemoveAt(_solver.Changes.Count - 1);
                }
                throw;
            }
        }