Ejemplo n.º 1
0
        public static void Shuffle <T>(this IList <T> self, IControlledRandom random)
        {
            var count = self.Count;
            var last  = count - 1;

            for (var i = 0; i < last; ++i)
            {
                var r   = random.Next(i, count);
                var tmp = self[i];
                self[i] = self[r];
                self[r] = tmp;
            }
        }
Ejemplo n.º 2
0
 public RoundManager(
     IEnumerable <Bot> bots,
     TimerService timerService,
     EventNotifier notifier,
     IControlledRandom random)
 {
     this.playerCircle       = new PlayerCircle();
     this.handEvaluator      = new HandWinEvaluator();
     this.rulesEngine        = new GameRulesEngine();
     this.playerStateManager = new PlayerStateManager();
     this.agentLookup        = new AgentLookup();
     this.notifier           = notifier;
     this.random             = random;
     this.timerService       = timerService;
     this.AddBots(bots);
     this.Reset();
 }
Ejemplo n.º 3
0
 public void Shuffle(IControlledRandom random)
 {
     this.Cards.Shuffle(random);
 }
Ejemplo n.º 4
0
        private GameResult SimulateGame(IEnumerable <Bot> bots, int gameNumber, TimerService timerService, IControlledRandom random)
        {
            var  roundManager = new RoundManager(bots, timerService, this.notifier, random);
            var  gameResult   = new GameResult(bots.Select(i => i.Player), gameNumber);
            int  roundNumber  = 1;
            bool gameHasEnded;

            do
            {
                var roundResult = roundManager.Play(roundNumber);

                foreach (var player in bots.Select(i => i.Player))
                {
                    int playerScore = roundResult.Scores[player];

                    if (playerScore < MoonshotPoints)
                    {
                        gameResult.Scores[player] += playerScore;
                    }
                    else
                    {
                        ++gameResult.Moonshots[player];
                        int  shooterCumulativeScore            = gameResult.Scores[player];
                        var  otherScores                       = gameResult.Scores.Where(i => i.Key != player).ToList();
                        var  otherScoresPlus26                 = otherScores.Select(i => i.Value + MoonshotPoints).ToList();
                        bool hasShooterLostIfAddsScoreToOthers = otherScoresPlus26.Any(i => i >= GameLosingPoints) && shooterCumulativeScore > otherScoresPlus26.Min();

                        if (hasShooterLostIfAddsScoreToOthers)
                        {
                            gameResult.Scores[player] -= MoonshotPoints;
                        }
                        else
                        {
                            foreach (var otherPlayer in otherScores.Select(i => i.Key))
                            {
                                gameResult.Scores[otherPlayer] += MoonshotPoints;
                            }
                        }
                    }

                    gameResult.RoundWins[player]   += roundResult.Winners.Count(i => i == player); // TODO: make sure what ever sets winners and losers understands to account for 26pts elsewhere and on self
                    gameResult.RoundLosses[player] += roundResult.Losers.Count(i => i == player);  // TODO: make sure what ever sets winners and losers understands to account for 26pts elsewhere and on self
                }

                gameHasEnded = gameResult.Scores.Any(i => i.Value >= GameLosingPoints);

                if (gameHasEnded)
                {
                    foreach (var player in gameResult.Scores.Where(i => i.Value == gameResult.Scores.Min(j => j.Value)).Select(i => i.Key))
                    {
                        gameResult.Winners.Add(player);
                    }

                    foreach (var player in gameResult.Scores.Where(i => i.Value == gameResult.Scores.Max(j => j.Value)).Select(i => i.Key))
                    {
                        gameResult.Losers.Add(player);
                    }
                }

                ++gameResult.RoundsPlayed;
                ++roundNumber;
            } while (!gameHasEnded);

            Log.LogFinalWinner(gameResult);

            return(gameResult);
        }
Ejemplo n.º 5
0
        public SimulationResult SimulateGames(IEnumerable <Bot> bots, int simulationCount, IControlledRandom random, bool logOutput = true)
        {
            var gameResults  = new List <GameResult>();
            var timerService = new TimerService(bots);

            for (int i = 0; i < simulationCount; i++)
            {
                this.notifier.CallGameStarted(random.GetSeed());
                var gameResult = this.SimulateGame(bots, i + 1, timerService, random);
                gameResults.Add(gameResult);
                this.notifier.CallGameEnded(gameResult);
            }

            var simulationResult = new SimulationResult(gameResults, bots, timerService);

            if (logOutput)
            {
                Log.LogSimulationSummary(simulationResult);
            }

            return(simulationResult);
        }
Ejemplo n.º 6
0
 public IEnumerable <CardHand> DealStartingHands(IEnumerable <Player> players, IControlledRandom random)
 {
     this.NewDeck();
     this.Deck.Shuffle(random);
     return(this.dealAlgorithm.DealStartingHands(this.Deck, players));
 }
Ejemplo n.º 7
0
 public Dealer(IFactory <Deck> factory, IDealAlgorithm dealAlgorithm, IControlledRandom random)
 {
     this.factory       = factory;
     this.dealAlgorithm = dealAlgorithm;
     this.NewDeck();
 }