Skip to content

Commit

Permalink
make fraction of popular maps configurable in dynamic configs
Browse files Browse the repository at this point in the history
  • Loading branch information
Licho1 committed Apr 6, 2024
1 parent f4ee61e commit cdf3a86
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 1 deletion.
5 changes: 5 additions & 0 deletions ZkData/Ef/DynamicConfig.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
Expand Down Expand Up @@ -35,6 +36,10 @@ public class DynamicConfig

public int MaximumStatLimitedBattlePlayers { get; set; } // if a battle has more than this number of players, maxelo/minelo, maxrank/minrank and maxleve/minlevel are disabled

[Description("Map vote always tries to include some of the most popular maps (precentile <0.2), this value controls how big fraction of offers is most popular maps.")]
public double MapVoteFractionOfPopularMaps { get; set; } = 0.5;


public static DynamicConfig Instance;

static DynamicConfig()
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions ZkData/Migrations/202404060935038_AddPopularMapsFraction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ZkData.Migrations
{
using System;
using System.Data.Entity.Migrations;

public partial class AddPopularMapsFraction : DbMigration
{
public override void Up()
{
AddColumn("dbo.DynamicConfigs", "MapVoteFractionOfPopularMaps", c => c.Double(nullable: false, defaultValue: 0.5));
}

public override void Down()
{
DropColumn("dbo.DynamicConfigs", "MapVoteFractionOfPopularMaps");
}
}
}
126 changes: 126 additions & 0 deletions ZkData/Migrations/202404060935038_AddPopularMapsFraction.resx

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions ZkData/ZkData.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,10 @@
<Compile Include="Migrations\202303191424586_RemoveGlacierId.Designer.cs">
<DependentUpon>202303191424586_RemoveGlacierId.cs</DependentUpon>
</Compile>
<Compile Include="Migrations\202404060935038_AddPopularMapsFraction.cs" />
<Compile Include="Migrations\202404060935038_AddPopularMapsFraction.Designer.cs">
<DependentUpon>202404060935038_AddPopularMapsFraction.cs</DependentUpon>
</Compile>
<Compile Include="SpringFilesUnitsyncAttempt.cs" />
<Compile Include="SteamWebApi.cs" />
<Compile Include="UserLanguageNoteAttribute.cs" />
Expand Down Expand Up @@ -939,6 +943,9 @@
<EmbeddedResource Include="Migrations\202303191424586_RemoveGlacierId.resx">
<DependentUpon>202303191424586_RemoveGlacierId.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Migrations\202404060935038_AddPopularMapsFraction.resx">
<DependentUpon>202404060935038_AddPopularMapsFraction.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="ZkDataResources.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>ZkDataResources.Designer.cs</LastGenOutput>
Expand Down
12 changes: 11 additions & 1 deletion ZkLobbyServer/ServerBattle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,9 +1077,19 @@ private async Task<bool> CreateMultiMapPoll()
pickedMaps.Add(HostedMap?.ResourceID ?? 0);
using (var db = new ZkDataContext())
{
var popularMapCount = Math.Round(NumberOfMapChoices * DynamicConfig.Instance.MapVoteFractionOfPopularMaps).Clamp(0, NumberOfMapChoices - 1);

for (int i = 0; i < NumberOfMapChoices; i++)
{
Resource map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Featured) ? MapSupportLevel.Featured : MinimalMapSupportLevel, db.Resources.Where(x => !pickedMaps.Contains(x.ResourceID)));
Resource map = null;
if (i < popularMapCount)
{
map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Supported) ? MapSupportLevel.Supported : MinimalMapSupportLevel, MapRatings.GetMapRanking(Mode).TakeWhile(x => x.Percentile < 0.2).Select(x => x.Map).Where(x => !pickedMaps.Contains(x.ResourceID)).AsQueryable()); //choose the popular maps
}
if (map == null)
{
map = MapPicker.GetRecommendedMap(GetContext(), (MinimalMapSupportLevel < MapSupportLevel.Featured) ? MapSupportLevel.Supported : MinimalMapSupportLevel, db.Resources.Where(x => !pickedMaps.Contains(x.ResourceID)));
}
pickedMaps.Add(map.ResourceID);
options.Add(new PollOption()
{
Expand Down

0 comments on commit cdf3a86

Please sign in to comment.