コード例 #1
0
ファイル: converters.py プロジェクト: hyyking/open-matchmaker
    async def convert(self, ctx, argument):
        if "-" not in argument:
            raise BadArgument(
                "Invalid result format, please use 'Score1-Score2'")

        result = argument.split("-")
        if len(result) != 2:
            raise BadArgument(
                "Invalid result format, please use 'Score1-Score2'")

        try:
            score1 = int(result[0])
            score2 = int(result[1])
        except ValueError as err:
            raise BadArgument(
                "Invalid score format, scores should be integers") from err

        ppm = ctx.bot.mm.config.points_per_match
        print(ppm)
        if not ppm in (score1, score2) or (score1 + score2) >= (2 * ppm):
            raise BadArgument(
                f"There should be a single winner with {ppm} points")

        result1 = Result(result_id=1, points=score1)
        result2 = Result(result_id=2, points=score2)
        return Match(team_one=result1, team_two=result2)
コード例 #2
0
ファイル: handlers.py プロジェクト: hyyking/open-matchmaker
    def test_end_trigger(self):
        evmap = EventMap.new()
        evmap.register(GameEndHandler(self.round, self.games, evmap))
        evmap.register(
            EqHandler(
                tag=1,
                key="round",
                expect=Round(round_id=self.round.round_id),
                kind=EventKind.ROUND_END,
                persistent=False,
            ))

        m = Match(
            match_id=1,
            round=self.round,
            team_one=Result(result_id=1, team=self.t1, points=3, delta=-1),
            team_two=Result(result_id=2, team=self.t2, points=7, delta=1),
        )

        ctx = self.games.add_result(m)
        assert not isinstance(ctx, Error)
        assert ctx == 1

        assert self.games[ctx].is_complete()

        e = ResultEvent(self.games[1], m)
        assert not isinstance(evmap.handle(e), HandlingError)

        assert len(self.games) == 0
        assert len(evmap[EventKind.ROUND_END]) == 0
コード例 #3
0
ファイル: ingamectx.py プロジェクト: hyyking/open-matchmaker
    def setUpClass(cls):
        cls.round = Round(round_id=1)
        cls.principal = get_principal(cls.round, Config())

        cls.p1 = Player(discord_id=1, name="Player_1")
        cls.p2 = Player(discord_id=2, name="Player_2")
        cls.p3 = Player(discord_id=3, name="Player_3")
        cls.p4 = Player(discord_id=4, name="Player_4")

        cls.t1 = Team(team_id=1,
                      name="Team_1_2",
                      player_one=cls.p1,
                      player_two=cls.p2,
                      elo=1000)
        cls.t2 = Team(team_id=2,
                      name="Team_3_4",
                      player_one=cls.p3,
                      player_two=cls.p4,
                      elo=1000)

        cls.r1 = Result(result_id=1, team=cls.t1, points=3.5, delta=0)
        cls.r2 = Result(result_id=2, team=cls.t2, points=3.5, delta=0)

        cls.m1 = Match(match_id=1,
                       round=cls.round,
                       team_one=cls.r1,
                       team_two=cls.r2)
コード例 #4
0
def generate(db):
    players = []
    for i in range(1, PLAYERS + 1):
        player = Player(i, f"Player_{i}")
        assert db.insert(player)
        players.append(player)
    print(f"-- Generated {len(players)} players")

    teams = []
    for i, team in enumerate(combinations(players, 2), 1):
        one, two = team
        team = Team(
            team_id=i,
            name=f"Team_{one.discord_id}_{two.discord_id}",
            player_one=one,
            player_two=two,
        )
        teams.append(team)
        assert db.insert(team)
    print(f"-- Generated {len(teams)} teams")
    assert len(teams) == no_teams()

    prev_round = None
    matches = 0
    prev_time = datetime.now()
    for i, team in enumerate(combinations(teams, 2), 1):
        if (i - 1) % ROUND_EVERY == 0:
            start = prev_time
            prev_time += timedelta(minutes=15)
            prev_round = Round(
                round_id=i // ROUND_EVERY + 1,
                start_time=start,
                end_time=prev_time,
                participants=4,
            )
            assert db.insert(prev_round)

        res1 = Result(result_id=i, team=team[0], points=7, delta=1.0)
        res2 = Result(result_id=i + 1, team=team[1], points=6, delta=-1.0)
        assert db.insert(res1)
        assert db.insert(res2)
        assert db.insert(
            Match(match_id=i,
                  round=prev_round,
                  team_one=res1,
                  team_two=res2,
                  odds_ratio=1))
        matches = i
    assert matches == no_matches()
    print(f"-- Generated {matches} matches")
    print(f"-- Generated {matches//ROUND_EVERY} rounds")
コード例 #5
0
    def setUpClass(cls):
        cls.round = Round(round_id=1)
        cls.ctx = QueueContext(cls.round)

        cls.p1 = Player(discord_id=1, name="Player_1")
        cls.p2 = Player(discord_id=2, name="Player_2")
        cls.p3 = Player(discord_id=3, name="Player_3")
        cls.p4 = Player(discord_id=4, name="Player_4")

        cls.t1 = Team(team_id=1,
                      name="Team_1_2",
                      player_one=cls.p1,
                      player_two=cls.p2)
        cls.t2 = Team(team_id=2,
                      name="Team_3_4",
                      player_one=cls.p3,
                      player_two=cls.p4)
        cls.t3 = Team(team_id=3,
                      name="Team_1_3",
                      player_one=cls.p1,
                      player_two=cls.p3)

        cls.r = Result(result_id=1, team=cls.t1, points=0)
        cls.m1 = Match(match_id=1,
                       round=cls.round,
                       team_one=cls.r,
                       team_two=cls.r)
        cls.m2 = Match(match_id=2,
                       round=cls.round,
                       team_one=cls.r,
                       team_two=cls.r)
コード例 #6
0
ファイル: handlers.py プロジェクト: hyyking/open-matchmaker
    def setUpClass(cls):
        cls.round = Round(round_id=1)

        cls.t1 = Team(
            team_id=42,
            elo=1000,
            player_one=Player(discord_id=1),
            player_two=Player(discord_id=2),
        )
        cls.t2 = Team(
            team_id=69,
            elo=1000,
            player_one=Player(discord_id=3),
            player_two=Player(discord_id=4),
        )
        m = Match(
            match_id=1,
            round=cls.round,
            team_one=Result(result_id=1, team=cls.t1),
            team_two=Result(result_id=2, team=cls.t2),
        )
        cls.principal = get_principal(cls.round, Config())
        cls.games = Games(
            {cls.round.round_id: InGameContext(cls.principal, [m])})
コード例 #7
0
ファイル: queries.py プロジェクト: hyyking/open-matchmaker
 def test_result_elo_for_team(self):
     for i in range(1, 46):
         team = Team(team_id=i)
         delta = self.db.execute(Result.elo_for_team(team),
                                 "FetchTeamElo").fetchone()[0]
         assert compute_mock_delta(team) == delta
コード例 #8
0
 def setUpClass(cls):
     cls.db = Database("tests/full_mockdb.sqlite3")
     cls.r1 = Result(result_id=1)
     cls.r2 = Result(result_id=1)
     cls.r3 = Result(result_id=2)
コード例 #9
0
 def test_load_result(self):
     for i in range(1, no_results() + 1):
         result = self.db.load(Result(result_id=i))
         assert result is not None
         assert result.result_id == i
コード例 #10
0
 def test_exists_result(self):
     for i in range(1, no_results() + 1):
         assert self.db.exists(Result(result_id=i))