From 524d0bee75488ebeabee93be86bf9b508e86fb4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20K=C3=BCpper?= Date: Sun, 15 Dec 2013 12:27:09 +0100 Subject: [PATCH] Make random a bit less random, but already sung songs shouldn't be suggested frequently. --- .../CPartyModeChallengeMedley.cs | 8 +++++++- Vocaluxe/Base/CSongs.cs | 15 ++++++++++++++- Vocaluxe/Screens/CScreenScore.cs | 1 + VocaluxeLib/Songs/CSong.cs | 2 ++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs index 234d1ca1..b0975714 100644 --- a/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs +++ b/PartyModes/PartyModeChallengeMedley/CPartyModeChallengeMedley.cs @@ -513,12 +513,18 @@ namespace VocaluxeLib.PartyModes.ChallengeMedley return false; } + //Calc avarage sing-count + int totalCounts = 0; + foreach (CSong song in visibleSongs) + totalCounts += song.NumPlayedSession; + int averageCount = totalCounts / visibleSongs.Count; + // ReSharper disable LoopCanBeConvertedToQuery foreach (CSong song in visibleSongs) { foreach (EGameMode mode in song.AvailableGameModes) { - if (mode == EGameMode.TR_GAMEMODE_MEDLEY) + if (mode == EGameMode.TR_GAMEMODE_MEDLEY && song.NumPlayedSession <= averageCount) ids.Add(song.ID); } } diff --git a/Vocaluxe/Base/CSongs.cs b/Vocaluxe/Base/CSongs.cs index c031209c..86a2f482 100644 --- a/Vocaluxe/Base/CSongs.cs +++ b/Vocaluxe/Base/CSongs.cs @@ -217,7 +217,20 @@ namespace Vocaluxe.Base public static void UpdateRandomSongList() { _SongsForRandom.Clear(); - _SongsForRandom.AddRange(VisibleSongs); + //Calc avarage sing-count + int totalCounts = 0; + foreach (CSong song in VisibleSongs) + totalCounts += song.NumPlayedSession; + int averageCount = totalCounts / NumSongsVisible; + + foreach(CSong song in VisibleSongs) + { + if (song.NumPlayedSession <= averageCount) + _SongsForRandom.Add(song); + } + + if(_SongsForRandom.Count == 0) + _SongsForRandom.AddRange(VisibleSongs); } public static int GetRandomCategory() diff --git a/Vocaluxe/Screens/CScreenScore.cs b/Vocaluxe/Screens/CScreenScore.cs index b1e06b1e..22cd465d 100644 --- a/Vocaluxe/Screens/CScreenScore.cs +++ b/Vocaluxe/Screens/CScreenScore.cs @@ -409,6 +409,7 @@ namespace Vocaluxe.Screens CSong song = CSongs.GetSong(players[p].SongID); CDataBase.IncreaseSongCounter(song.DataBaseSongID); song.NumPlayed++; + song.NumPlayedSession++; break; } } diff --git a/VocaluxeLib/Songs/CSong.cs b/VocaluxeLib/Songs/CSong.cs index 9eb3e5a6..d2c393e8 100644 --- a/VocaluxeLib/Songs/CSong.cs +++ b/VocaluxeLib/Songs/CSong.cs @@ -174,6 +174,7 @@ namespace VocaluxeLib.Songs public int DataBaseSongID = -1; public string DateAdded = ""; public int NumPlayed; + public int NumPlayedSession; // Notes public readonly CNotes Notes = new CNotes(); @@ -266,6 +267,7 @@ namespace VocaluxeLib.Songs DataBaseSongID = song.DataBaseSongID; DateAdded = song.DateAdded; NumPlayed = song.NumPlayed; + NumPlayedSession = song.NumPlayedSession; Notes = new CNotes(song.Notes); }