Skip to content

Commit

Permalink
feat: allow opponents in first round matches
Browse files Browse the repository at this point in the history
  • Loading branch information
CouchPartyGames committed Nov 27, 2024
1 parent bb971e5 commit e35ec57
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
8 changes: 8 additions & 0 deletions TournamentGenerator.sln
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31903.59
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TournamentGenerator", "src\TournamentGenerator.csproj", "{2F461160-5F52-48FB-884A-1EC5C5E876BB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -11,4 +13,10 @@ Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F461160-5F52-48FB-884A-1EC5C5E876BB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F461160-5F52-48FB-884A-1EC5C5E876BB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F461160-5F52-48FB-884A-1EC5C5E876BB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F461160-5F52-48FB-884A-1EC5C5E876BB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
13 changes: 11 additions & 2 deletions src/SingleEliminationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,17 @@ public Tournament<TOpponent> Build() {
var singleElim = new SingleProgression(_startingPositions,
_finals,
_thirdPlace);
var matches = singleElim.Matches
.Select( x => Match<TOpponent>.New(x))
var matches = singleElim
.Matches
.Select( x =>
{
if (_opponents.Count > 0)
{
return Match<TOpponent>.New(x, opponents[x.Position1], opponents[x.Position1]);
}

return Match<TOpponent>.New(x);
})
.ToList();


Expand Down
2 changes: 1 addition & 1 deletion src/TournamentGenerator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<PackageId>CouchPartyGames.TournamentGenerator</PackageId>
<Version>1.3.1</Version>
<Version>1.4.0</Version>
<Authors>CouchPartyGames</Authors>
<SymbolPackageForm>snupkg</SymbolPackageForm>
<PackageProjectUrl>https://github.com/CouchPartyGames/TournamentGenerator</PackageProjectUrl>
Expand Down
3 changes: 2 additions & 1 deletion src/TournamentSize.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace CouchPartyGames.TournamentGenerator;
using CouchPartyGames.TournamentGenerator.Position;

public enum TournamentSize
{
Expand All @@ -10,4 +11,4 @@ public enum TournamentSize
Size32 = 32,
Size64 = 64,
Size128 = 128
}
}
12 changes: 12 additions & 0 deletions src/Type/Match.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public static Match<TOpponent> New(MatchProgression matchProgression) =>
WinProgression = matchProgression.WinProgressionMatchId,
LoseProgression = matchProgression.LoseProgressionMatchId
};

public static Match<TOpponent> New(MatchProgression matchProgression, TOpponent opponent1, TOpponent opponent2) =>
new Match<TOpponent> {
LocalMatchId = matchProgression.LocalMatchId,
Round = matchProgression.Round,
Opponent1 = opponent1,
Opponent2 = opponent2,
Opponent1Position = matchProgression.Position1,
Opponent2Position = matchProgression.Position2,
WinProgression = matchProgression.WinProgressionMatchId,
LoseProgression = matchProgression.LoseProgressionMatchId
};

public bool NextWinProgressionExists() => WinProgression != NoProgression;
public bool NextLoseProgressionExists() => LoseProgression != NoProgression;
Expand Down

0 comments on commit e35ec57

Please sign in to comment.