public async Task Winner_Score_Is_Total_Score()
        {
            var strategyRepository   = new StrategyRepository(connection);
            var strategyService      = new StrategyService(strategyRepository);
            var simulationRepository = new SimulationRepository(connection);
            var gameService          = new GameService(strategyService, gameSettingsProvider);
            var populationService    = new PopulationService(gameService);
            //TODO: simplify /\
            var simulationServce = new SimulationService(simulationRepository, populationService,
                                                         strategyService, new SimulationSettingsProvider());
            Strategy cooperator = await strategyRepository
                                  .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name);

            var players = new List <Player>();

            for (int i = 0; i < 10; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }

            Simulation simulation = await simulationServce.Run(players);

            GameSettings gameSettings = gameSettingsProvider.GetGameSettings();
            int          totalScore   = gameSettings.TotalRounds
                                        * (gameSettings.CooperateModifier + gameSettings.MoveModifier)
                                        * (players.Count - 1);

            Assert.AreEqual(totalScore, simulation.Winner.Score);
        }
        public async Task Get_Cooperator_Players_Strategies()
        {
            var strategyRepository   = new StrategyRepository(connection);
            var strategyService      = new StrategyService(strategyRepository);
            var simulationRepository = new SimulationRepository(connection);
            var gameService          = new GameService(strategyService, gameSettingsProvider);
            var populationService    = new PopulationService(gameService);
            //TODO: simplify /\
            var simulationServce = new SimulationService(simulationRepository, populationService,
                                                         strategyService, new SimulationSettingsProvider());
            Strategy cooperator = await strategyRepository
                                  .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name);

            var players = new List <Player>();

            for (int i = 0; i < 10; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }
            players = simulationServce.GetPlayersStrategies(players);

            bool badPlayers = players.Where(p => p.StrategyId != cooperator.Id).Any();

            Assert.IsFalse(badPlayers);
        }
        public async Task Run_Once_When_Consistent()
        {
            var strategyRepository   = new StrategyRepository(connection);
            var strategyService      = new StrategyService(strategyRepository);
            var simulationRepository = new SimulationRepository(connection);
            var gameService          = new GameService(strategyService, gameSettingsProvider);
            var populationService    = new PopulationService(gameService);
            //TODO: simplify /\
            var simulationServce = new SimulationService(simulationRepository, populationService,
                                                         strategyService, new SimulationSettingsProvider());
            Strategy cooperator = await strategyRepository
                                  .GetByNameAsync(NoMemoryStrategies.GetSimpleCooperator().Name);

            var players = new List <Player>();

            for (int i = 0; i < 10; i++)
            {
                players.Add(new Player()
                {
                    StrategyId = cooperator.Id
                });
            }

            Simulation simulation = await simulationServce.Run(players);

            Assert.IsNotNull(simulation.Winner);
            Assert.AreEqual(1, simulation.PopulationsCompleated);
        }
        public async Task PopulateDb()
        {
            //TODO: remove when GUI created
            var strategyRepository = new StrategyRepository(connection);

            var strategies = new List <Strategy>()
            {
                NoMemoryStrategies.GetSimpleCheater(),
                NoMemoryStrategies.GetSimpleCooperator(),
                OneRoundStrategies.GetCopycat(),
                OneRoundStrategies.GetCheaterCopycat(),
                OneRoundStrategies.GetReverser(),
                OneRoundStrategies.GetCheaterReverser()
            };

            var newStrategies = new List <string>();

            foreach (Strategy strategy in strategies)
            {
                Strategy tmp = await strategyRepository.GetByNameAsync(strategy.Name);

                if (tmp == null)
                {
                    string newId = await strategyRepository.AddAsync(strategy);

                    newStrategies.Add(newId);
                }
            }

            List <Strategy> addedStrategies = await strategyRepository.GetAsync(newStrategies);

            Assert.AreEqual(newStrategies.Count, addedStrategies.Count);
        }