Skip to content

Commit

Permalink
Release v1.0.5: Added option to show absolute similarity instead of p…
Browse files Browse the repository at this point in the history
…ercentage.
  • Loading branch information
djdookie committed May 23, 2017
1 parent 598d07e commit 1e3eeb0
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 14 deletions.
24 changes: 16 additions & 8 deletions Advisor/Advisor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,12 @@ internal async void UpdateCardList()
// Only continue if in valid game mode or game format
if (!IsValidGameMode || !IsValidGameFormat) return;

// Small delay to guarantee opponents cards list is up to date
// Small delay to guarantee opponents cards list is up to date (should be 300+ ms in debug mode or with attached debugger, otherwise restarting HDT could lead to an incomplete opponent decklist!)
#if DEBUG
await Task.Delay(1000);
#else
await Task.Delay(100);
#endif

// Get opponent's cards list (all yet revealed cards)
//var opponentCardlist = Core.Game.Opponent.RevealedCards;
Expand Down Expand Up @@ -264,14 +268,18 @@ internal async void UpdateCardList()
// Select best matched deck with both highest similarity value and most played games
var matchedDeck = topGamesDecks.First();

// Count how many cards from opponent deck are in selected deck
int matchingCards = 0;
foreach (var opponentDeckCard in opponentCardlist)
foreach (var selectedDeckCard in matchedDeck.Key.Cards)
if (!opponentDeckCard.IsCreated && opponentDeckCard.Equals(selectedDeckCard))
matchingCards++;
// Show matched deck name and similarity value or number of matching cards and number of all played cards
if (Settings.Default.ShowAbsoluteSimilarity)
{
// Count how many cards from opponent deck are in matched deck
int matchingCards = matchedDeck.Key.CountMatchingCards(opponentCardlist);
_advisorOverlay.LblArchetype.Text = String.Format("{0} ({1}/{2})", matchedDeck.Key.Name, matchingCards, opponentCardlist.Sum(x => x.Count));
}
else
{
_advisorOverlay.LblArchetype.Text = String.Format("{0} ({1}%)", matchedDeck.Key.Name, Math.Round(matchedDeck.Value * 100, 2));
}

_advisorOverlay.LblArchetype.Text = String.Format("{0} ({1}/{2})", matchedDeck.Key.Name, matchingCards, opponentCardlist.Count);
_advisorOverlay.LblStats.Text = String.Format("{0}", matchedDeck.Key.Note);
Deck deck = DeckList.Instance.Decks.Where(d => d.TagList.ToLowerInvariant().Contains("archetype")).First(d => d.Name == matchedDeck.Key.Name);
if (deck != null)
Expand Down
2 changes: 1 addition & 1 deletion Advisor/AdvisorPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void OnUpdate()
{
}

public Version Version => new Version(1, 0, 4);
public Version Version => new Version(1, 0, 5);

public async Task CheckForUpdate()
{
Expand Down
28 changes: 26 additions & 2 deletions Advisor/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public static float Similarity(this Deck thisDeck, Deck deck)
}

/// <summary>
/// Uses the Jaccard index to give a indication of similarity between the two decks.</summary>
/// <returns>Returns a float between 0 and 1 inclusive</returns>
/// Uses the Jaccard index to give a indication of similarity between a deck and a cardlist.</summary>
/// <returns>The Jaccard index, a float between 0 and 1</returns>
public static float Similarity(this Deck thisDeck, IList<Card> cards)
{
if (cards == null)
Expand All @@ -68,6 +68,30 @@ public static float Similarity(this Deck thisDeck, IList<Card> cards)
return (float)Math.Round((float)lenAnB / (lenA + lenB - lenAnB), 4);
}

/// <summary>
/// Counts the absolute number of matching/intersecting cards between a deck and a cardlist.</summary>
/// <returns>The number of intersecting cards</returns>
public static int CountMatchingCards(this Deck thisDeck, IList<Card> cards)
{
if (cards == null)
return 0;

int count = 0;

foreach (var i in thisDeck.Cards)
{
foreach (var j in cards)
{
if (i.Equals(j))
{
count += Math.Min(i.Count, j.Count);
}
}
}

return count;
}

/// <summary>
/// Gets the number of played games stored in the deck's note field.
/// </summary>
Expand Down
7 changes: 6 additions & 1 deletion Advisor/Layout/SettingsView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@
HorizontalAlignment="Left" Margin="0,5,0,0"
VerticalAlignment="Top"
ToolTip="Shows statistics of the archetype deck like winrate and number of played games." />
<CheckBox Content="Check for updates"
<CheckBox Content="Check for plugin updates"
IsChecked="{Binding Settings.Default.CheckForUpdates}"
HorizontalAlignment="Left" Margin="0,5,0,0"
VerticalAlignment="Top"
ToolTip="Automatically check for updates when the plugin is loaded." />
<CheckBox Content="Show absolute similarity"
IsChecked="{Binding Settings.Default.ShowAbsoluteSimilarity}"
HorizontalAlignment="Left" Margin="0,5,0,0"
VerticalAlignment="Top"
ToolTip="Shows the similarity of decks as absolute number of matching and played cards instead of a percentage." />
<StackPanel Orientation="Horizontal">
<Label Content="Overlay position (x, y):" VerticalAlignment="Center"></Label>
<TextBox Text="{Binding Settings.Default.OverlayPositionX, UpdateSourceTrigger=PropertyChanged}"
Expand Down
4 changes: 2 additions & 2 deletions Advisor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.4.0")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyVersion("1.0.5.0")]
[assembly: AssemblyFileVersion("1.0.5.0")]
12 changes: 12 additions & 0 deletions Advisor/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions Advisor/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,8 @@
<Setting Name="ShowStatistics" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="ShowAbsoluteSimilarity" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
</Settings>
</SettingsFile>
3 changes: 3 additions & 0 deletions Advisor/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@
<setting name="ShowStatistics" serializeAs="String">
<value>True</value>
</setting>
<setting name="ShowAbsoluteSimilarity" serializeAs="String">
<value>True</value>
</setting>
</Advisor.Properties.Settings>
</userSettings>
</configuration>

0 comments on commit 1e3eeb0

Please sign in to comment.