Exemple #1
0
        public async Task GetAssignedPlayers_ThreePlayers_TwoPlayersVersusOnePlayerPlusBot()
        {
            var match = new Match {
                Id = "M1"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 1, Id = "1", Kills = 1, Deaths = 1
            });
            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 2, Id = "2", Kills = 2, Deaths = 2
            });
            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 3, Id = "3", Kills = 3, Deaths = 3
            });
            myMatchRepository.Add(match);
            myMatchRepository.SaveChanges();
            var skillBasedAssigner = new SkillBasedAssigner(myMatchRepository, new SteamworksApi());

            (var t, var ct) = await skillBasedAssigner.GetAssignedPlayers(new List <Player> {
                new Player {
                    SteamID = "1", Name = "Emma"
                },
                new Player {
                    SteamID = "2", Name = "Kathy"
                },
                new Player {
                    SteamID = "3", Name = "Baltasar"
                }
            });

            Assert.Equal(2, t.Players.Count);
            Assert.Equal(2, ct.Players.Count);
            Assert.True(t.Players.Any(x => x.Name.Equals("BOT")) || ct.Players.Any(x => x.Name.Equals("BOT")));
        }
Exemple #2
0
        public async Task GetAssignedPlayers_TwoPlayers_OnePlayerAssignedToEachTeam()
        {
            var match = new Match {
                Id = "M1"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 1, Id = "1", Kills = 1, Deaths = 1
            });
            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 2, Id = "2", Kills = 2, Deaths = 2
            });
            myMatchRepository.Add(match);
            myMatchRepository.SaveChanges();
            var skillBasedAssigner = new SkillBasedAssigner(myMatchRepository, new SteamworksApi());

            (var t, var ct) = await skillBasedAssigner.GetAssignedPlayers(new List <Player> {
                new Player {
                    SteamID = "1"
                }, new Player {
                    SteamID = "2"
                }
            });

            Assert.Single(t.Players);
            Assert.Single(ct.Players);
        }
Exemple #3
0
        public async Task GetAssignedPlayers_NoMatchesForPlayer_UsesKDRating()
        {
            var steamworksApiMock = new Mock <SteamworksApi>();

            steamworksApiMock
            .Setup(x => x.ParsePlayerStatistics(It.IsAny <string>()))
            .Returns(Task.FromResult((IList <Statistic>) new List <Statistic> {
                new Statistic {
                    Name = "total_kills", Value = 5
                },
                new Statistic {
                    Name = "total_deaths", Value = 1
                },
                new Statistic {
                    Name = "last_match_kills", Value = 5
                },
                new Statistic {
                    Name = "last_match_deaths", Value = 5
                }
            }));

            var skillBasedAssigner            = new SkillBasedAssigner(myMatchRepository, steamworksApiMock.Object);
            var steamIdOfPlayerWithoutMatches = "111";

            (var t, var ct) = await skillBasedAssigner.GetAssignedPlayers(new List <Player> {
                new Player {
                    SteamID = steamIdOfPlayerWithoutMatches
                }
            });

            steamworksApiMock.Verify(x => x.ParsePlayerStatistics(steamIdOfPlayerWithoutMatches));
            var playersOfBothTeams = t.Players.Concat(ct.Players);

            Assert.Equal(5, playersOfBothTeams.Single(x => x.SteamID.Equals(steamIdOfPlayerWithoutMatches)).Skill.SkillScore);
        }
Exemple #4
0
        public async Task GetAssignedPlayers_TwoStrongPlayersAndFourMediumPlayers_OneStrongTwoMediumEach()
        {
            var match = new Match {
                Id = "M1"
            };
            var strongPlayer1 = new Player {
                SteamID = "1"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 1, Id = Guid.NewGuid().ToString(), Kills = 10, Deaths = 2, Rounds = 5
            });
            var strongPlayer2 = new Player {
                SteamID = "2"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 2, Id = Guid.NewGuid().ToString(), Kills = 11, Deaths = 3, Rounds = 5
            });
            var mediumPlayer1 = new Player {
                SteamID = "3"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 3, Id = Guid.NewGuid().ToString(), Kills = 2, Deaths = 2, Rounds = 5
            });
            var mediumPlayer2 = new Player {
                SteamID = "4"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 4, Id = Guid.NewGuid().ToString(), Kills = 2, Deaths = 3, Rounds = 5
            });
            var mediumPlayer3 = new Player {
                SteamID = "5"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 5, Id = Guid.NewGuid().ToString(), Kills = 2, Deaths = 3, Rounds = 5
            });
            var mediumPlayer4 = new Player {
                SteamID = "6"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 6, Id = Guid.NewGuid().ToString(), Kills = 2, Deaths = 3, Rounds = 5
            });
            myMatchRepository.Add(match);
            myMatchRepository.SaveChanges();
            var skillBasedAssigner = new SkillBasedAssigner(myMatchRepository, new SteamworksApi());

            (var t, var ct) = await skillBasedAssigner.GetAssignedPlayers(new List <Player> {
                strongPlayer1, strongPlayer2, mediumPlayer1, mediumPlayer2, mediumPlayer3, mediumPlayer4
            });

            Assert.Equal(3, t.Players.Count);
            Assert.Equal(3, ct.Players.Count);
            Assert.False(t.Players.Contains(strongPlayer1) && t.Players.Contains(strongPlayer2));
            Assert.False(ct.Players.Contains(strongPlayer1) && ct.Players.Contains(strongPlayer2));
        }
Exemple #5
0
        public async Task GetAssignedPlayers_NoMatchesForPlayerProfileNotPublic_UsesDummyRating()
        {
            var steamworksApiMock = new Mock <SteamworksApi>();

            steamworksApiMock.Setup(x => x.ParsePlayerStatistics(It.IsAny <string>())).Throws(new ProfileNotPublicException());

            var skillBasedAssigner            = new SkillBasedAssigner(myMatchRepository, steamworksApiMock.Object);
            var steamIdOfPlayerWithoutMatches = "111";

            (var t, var ct) = await skillBasedAssigner.GetAssignedPlayers(new List <Player> {
                new Player {
                    SteamID = steamIdOfPlayerWithoutMatches
                }
            });

            var player = t.Players.Concat(ct.Players).Single(x => x.SteamID.Equals(steamIdOfPlayerWithoutMatches));

            Assert.InRange(player.Skill.SkillScore, 0.3, 1.3);
        }
Exemple #6
0
        public async Task GetAssignedPlayers_ThreePlayersIncludeBotParameterFalse_NoBotAddedToBalanceTeamSizes()
        {
            var match = new Match {
                Id = "M1"
            };

            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 1, Id = "1", Kills = 1, Deaths = 1
            });
            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 2, Id = "2", Kills = 2, Deaths = 2
            });
            match.PlayerResults.Add(new MatchStatistics {
                SteamID = 3, Id = "3", Kills = 3, Deaths = 3
            });
            myMatchRepository.Add(match);
            myMatchRepository.SaveChanges();
            var skillBasedAssigner = new SkillBasedAssigner(myMatchRepository, new SteamworksApi());

            (var t, var ct) = await skillBasedAssigner.GetAssignedPlayers(
                new List <Player> {
                new Player {
                    SteamID = "1", Name = "Emma"
                },
                new Player {
                    SteamID = "2", Name = "Kathy"
                },
                new Player {
                    SteamID = "3", Name = "Baltasar"
                }
            },
                false);

            var numberOfAssignedPlayers = t.Players.Count + ct.Players.Count;

            Assert.Equal(3, numberOfAssignedPlayers);
        }