1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-13 03:42:57 +08:00

Simplified ban order logic

Implemented tests to make sure logic works as intended
This commit is contained in:
Rodrigo Pina 2023-12-05 12:56:24 +00:00
parent ecbf07c52a
commit cda55065e7
2 changed files with 126 additions and 7 deletions

View File

@ -5,6 +5,7 @@ using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Testing;
using osu.Game.Tournament.Components;
using osu.Game.Tournament.Models;
@ -151,6 +152,105 @@ namespace osu.Game.Tournament.Tests.Screens
});
}
[Test]
public void TestSingleTeamBan()
{
AddStep("set ban count", () => Ladder.CurrentMatch.Value!.Round.Value!.BanCount.Value = 1);
AddStep("load some maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 4; i++)
addBeatmap();
});
AddStep("update displayed maps", () => Ladder.SplitMapPoolByMods.Value = false);
AddStep("perform bans", () =>
{
var tournamentMaps = screen.ChildrenOfType<TournamentBeatmapPanel>().ToList();
screen.ChildrenOfType<TourneyButton>().Where(btn => btn.Text == "Red Ban").First().TriggerClick();
PerformMapAction(tournamentMaps[0]);
PerformMapAction(tournamentMaps[1]);
});
AddAssert("ensure 1 ban per team", () => Ladder.CurrentMatch.Value!.PicksBans.Count() == 2 && Ladder.CurrentMatch.Value!.PicksBans.Last().Team == TeamColour.Blue);
AddStep("reset match", () =>
{
InputManager.UseParentInput = true;
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
Ladder.CurrentMatch.Value.PicksBans.Clear();
});
}
[Test]
public void TestMultipleTeamBans()
{
AddStep("set ban count", () => Ladder.CurrentMatch.Value!.Round.Value!.BanCount.Value = 3);
AddStep("load some maps", () =>
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Clear();
for (int i = 0; i < 12; i++)
addBeatmap();
});
AddStep("update displayed maps", () => Ladder.SplitMapPoolByMods.Value = false);
AddStep("red team ban", () =>
{
var tournamentMaps = screen.ChildrenOfType<TournamentBeatmapPanel>().ToList();
screen.ChildrenOfType<TourneyButton>().Where(btn => btn.Text == "Red Ban").First().TriggerClick();
PerformMapAction(tournamentMaps[0]);
});
AddAssert("ensure red team ban", () => Ladder.CurrentMatch.Value!.PicksBans.Last().Team == TeamColour.Red);
AddStep("blue team bans", () =>
{
var tournamentMaps = screen.ChildrenOfType<TournamentBeatmapPanel>().ToList();
PerformMapAction(tournamentMaps[1]);
PerformMapAction(tournamentMaps[2]);
});
AddAssert("ensure blue team double ban", () => Ladder.CurrentMatch.Value!.PicksBans.Count(ban => ban.Team == TeamColour.Blue) == 2);
AddStep("red team bans", () =>
{
var tournamentMaps = screen.ChildrenOfType<TournamentBeatmapPanel>().ToList();
PerformMapAction(tournamentMaps[3]);
PerformMapAction(tournamentMaps[4]);
});
AddAssert("ensure red team double ban", () => Ladder.CurrentMatch.Value!.PicksBans.Count(ban => ban.Team == TeamColour.Red) == 3);
AddStep("blue team bans", () =>
{
var tournamentMaps = screen.ChildrenOfType<TournamentBeatmapPanel>().ToList();
PerformMapAction(tournamentMaps[5]);
});
AddAssert("ensure blue team ban", () => Ladder.CurrentMatch.Value!.PicksBans.Last().Team == TeamColour.Blue);
AddStep("reset match", () =>
{
InputManager.UseParentInput = true;
Ladder.CurrentMatch.Value = new TournamentMatch();
Ladder.CurrentMatch.Value = Ladder.Matches.First();
Ladder.CurrentMatch.Value.PicksBans.Clear();
});
}
private void addBeatmap(string mods = "NM")
{
Ladder.CurrentMatch.Value!.Round.Value!.Beatmaps.Add(new RoundBeatmap
@ -159,5 +259,12 @@ namespace osu.Game.Tournament.Tests.Screens
Mods = mods
});
}
private void PerformMapAction(TournamentBeatmapPanel map)
{
InputManager.MoveMouseTo(map);
InputManager.Click(osuTK.Input.MouseButton.Left);
}
}
}

View File

@ -153,23 +153,35 @@ namespace osu.Game.Tournament.Screens.MapPool
const TeamColour roll_winner = TeamColour.Red; //todo: draw from match
var previousBan = CurrentMatch.Value.PicksBans.LastOrDefault()?.Team ?? roll_winner;
var previousColour = CurrentMatch.Value.PicksBans.LastOrDefault()?.Team ?? roll_winner;
var nextColour = previousBan == TeamColour.Red ? TeamColour.Blue : TeamColour.Red;
TeamColour nextColour;
bool hasAllBans = CurrentMatch.Value.PicksBans.Count(p => p.Type == ChoiceType.Ban) >= totalBansRequired;
if (!hasAllBans)
// If it's the third ban or later, we need to check if it's the team's first or second ban in a row
nextColour = (CurrentMatch.Value.PicksBans.Count >= 2 ? CurrentMatch.Value.PicksBans[^2]?.Team : previousBan) == TeamColour.Red ? TeamColour.Blue : TeamColour.Red;
if (hasAllBans && pickType == ChoiceType.Ban)
{
// When switching from bans to picks, we don't rotate the team colour.
// Ban phase.
// Switch teams every second ban.
nextColour = CurrentMatch.Value.PicksBans.Count % 2 == 1
? getOppositeTeamColour(previousColour)
: previousColour;
}
else if (pickType == ChoiceType.Ban)
{
// Switching from bans to picks - stay with the last team that was banning.
nextColour = pickColour;
}
else
{
// Pick phase.
// Switch teams every pick.
nextColour = getOppositeTeamColour(previousColour);
}
setMode(nextColour, hasAllBans ? ChoiceType.Pick : ChoiceType.Ban);
TeamColour getOppositeTeamColour(TeamColour colour) => colour == TeamColour.Red ? TeamColour.Blue : TeamColour.Red;
}
protected override bool OnMouseDown(MouseDownEvent e)