Esempio n. 1
0
        public void Cards()
        {
            var testCases = new List<Tuple<Card, int>>
            {
                Tuple.Create(new Card(Rank.King), 4),
                Tuple.Create(new Card(Rank.Five), 1),
                Tuple.Create(new Card(Rank.Ace), 0),
                Tuple.Create(new Card(Rank.Nine), 2),
                Tuple.Create(new Card(Rank.Jack), 3),
            };

            var orderStrategy = new StandardOrder();

            foreach (var testcase in testCases)
            {
                var sortedByOrderStrategy = testCases.OrderBy(c => orderStrategy.Order(c.Item1)).ToList();
                Assert.AreEqual(testcase.Item2, sortedByOrderStrategy.IndexOf(testcase));
            }
        }
Esempio n. 2
0
        public Player CreatePlayer(AiDifficulty difficulty, string name)
        {
            var standardOrder = new StandardOrder();
            var scoreCalculator = new ScoreCalculator();

            switch (difficulty)
            {
                case AiDifficulty.Easy:
                    return new Player(name, -1, new LowestCardPlayStrategy(standardOrder), new MinAverageDecision(scoreCalculator), new PercentageScoreCountStrategy(70, scoreCalculator));
                case AiDifficulty.Medium:
                    return new Player(name, -1, new LowestCardPlayStrategy(standardOrder), new RandomDecision(), new PercentageScoreCountStrategy(80, scoreCalculator));
                case AiDifficulty.Hard:
                    return new Player(name, -1, new LowestCardPlayStrategy(standardOrder), new OptimisticDecision(), new PercentageScoreCountStrategy(90, scoreCalculator));
                case AiDifficulty.Expert:
                    return new Player(name, -1, new LowestCardPlayStrategy(standardOrder), new MaxAverageDecision(scoreCalculator), new PercentageScoreCountStrategy(100, scoreCalculator));
                default:
                    throw new NotSupportedException("Difficulty type not supported.");
            }
        }
Esempio n. 3
0
        public void Handle(CardCutEvent cardCutEvent, GameState gameState)
        {
            gameState.OpeningRound.CutCards.Add(new PlayerIdCard { Player = cardCutEvent.PlayerId, Card = new Card(cardCutEvent.CutCard) });

            bool isDone = gameState.GameRules.PlayerCount == gameState.OpeningRound.CutCards.Count;
            gameState.OpeningRound.Complete = isDone;

            if (isDone && gameState.Rounds.Count == 0)
            {
                var order = new StandardOrder();

                var winningPlayerCut = gameState.OpeningRound.CutCards.MinBy(playerCard => order.Order(playerCard.Card));
                gameState.OpeningRound.WinningPlayerCut = winningPlayerCut.Player;
            }
        }
Esempio n. 4
0
 public void ArgumentNull()
 {
     var orderStrategy = new StandardOrder();
     orderStrategy.Order(null);
 }