コード例 #1
0
        public void OnGet()
        {
            var gameRunner = new GameRunner();

            gameRunner.AddBot(new RockOnlyBot("Rocky"));
            gameRunner.AddBot(new PaperOnlyBot("Paper"));
            gameRunner.AddBot(new ScissorsOnlyBot("Sharpy"));
            gameRunner.AddBot(new WaterOnlyBot("All Washed Up"));

            BotRankings = gameRunner.StartAllMatches().OrderByDescending(x => x.Wins).ToList();
        }
コード例 #2
0
        public void OnPost()
        {
            List <Competitor> competitors = _db.Competitors.ToList();

            if (!competitors.Any())
            {
                competitors = GetDefaultCompetitors();
                _db.Competitors.AddRange(competitors);
                _db.SaveChanges();
            }

            var gameRunner = new GameRunner();

            foreach (var competitor in competitors)
            {
                BaseBot bot = CreateBotFromCompetitor(competitor);
                gameRunner.AddBot(bot);
            }

            GameRunnerResult gameRunnerResult = gameRunner.StartAllMatches();

            SaveResults(gameRunnerResult);
            BotRankings    = gameRunnerResult.GameRecord.BotRecords.OrderByDescending(x => x.Wins).ToList();
            AllFullResults = gameRunnerResult.AllMatchResults.OrderBy(x => x.Competitor.Name).ToList();
        }
コード例 #3
0
        public void ReturnOneBot_GivenOneBotCompeting()
        {
            var gameRunner = new GameRunner();

            gameRunner.AddBot(new RockOnlyBot());

            var result = gameRunner.StartAllMatches();

            result.GameRecord.BotRecords.Should().ContainSingle();
        }
コード例 #4
0
        public async Task OnPostAsync()
        {
            List <Competitor> competitors = db.Competitors.ToList();

            if (!competitors.Any())
            {
                competitors = GetDefaultCompetitors();
                db.Competitors.AddRange(competitors);
                db.SaveChanges();
            }

            var gameRunner = new GameRunner(metrics);

            foreach (var competitor in competitors)
            {
                BaseBot bot = CreateBotFromCompetitor(competitor);
                gameRunner.AddBot(bot);
            }

            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            GameRunnerResult gameRunnerResult = gameRunner.StartAllMatches();

            stopwatch.Stop();

            var metric = new Dictionary <string, double> {
                { "GameLength", stopwatch.Elapsed.TotalMilliseconds }
            };

            // Set up some properties:
            var properties = new Dictionary <string, string> {
                { "Source", configuration["P20HackFestTeamName"] }
            };

            // Send the event:
            metrics.TrackEventDuration("GameRun", properties, metric);

            SaveResults(gameRunnerResult);
            BotRankings    = gameRunnerResult.GameRecord.BotRecords.OrderByDescending(x => x.Wins).ToList();
            AllFullResults = gameRunnerResult.AllMatchResults.OrderBy(x => x.Competitor.Name).ToList();

            //Get 20 Last
            GamesForTable = db.GameRecords.OrderByDescending(g => g.GameDate).Take(20).Include(g => g.BotRecords).ToList();

            if (bool.Parse(configuration["EventGridOn"]))
            {
                await PublishMessage(BotRankings.First().GameRecord.Id.ToString(), BotRankings.First().Competitor.Name);
            }
        }
コード例 #5
0
        public async Task <string> PostAsync()
        {
            List <Competitor> competitors = db.Competitors.ToList();

            var gameRunner = new GameRunner(metrics);

            foreach (var competitor in competitors)
            {
                BaseBot bot = CreateBotFromCompetitor(competitor);
                gameRunner.AddBot(bot);
            }

            var stopwatch = System.Diagnostics.Stopwatch.StartNew();

            GameRunnerResult gameRunnerResult = gameRunner.StartAllMatches();

            stopwatch.Stop();

            var metric = new Dictionary <string, double> {
                { "GameLength", stopwatch.Elapsed.TotalMilliseconds }
            };

            // Set up some properties:
            var properties = new Dictionary <string, string> {
                { "Source", configuration["P20HackFestTeamName"] }
            };

            // Send the event:
            metrics.TrackEventDuration("GameRun", properties, metric);

            SaveResults(gameRunnerResult);
            var winner = gameRunnerResult.AllMatchResults.Select(x => x.MatchResults).First().First().Player1.Name;

            await PublishMessage(gameRunnerResult.GameRecord.Id.ToString(), winner);

            //return gameRunnerResult.AllMatchResults.Select(x => x.MatchResults).First().First().Player1.Name;
            var bestRecord = gameRunnerResult.GameRecord.BotRecords.OrderByDescending(x => x.Wins).First();

            return($"{bestRecord.Competitor.Name}:{bestRecord.Wins}-{bestRecord.Losses}");
        }