Merge branch 'master' of bitbucket.org:Regalis11/barotrauma

This commit is contained in:
Sebastian Broberg
2016-08-28 16:07:59 +02:00
2 changed files with 30 additions and 1 deletions
+1 -1
View File
@@ -1471,7 +1471,7 @@ namespace Barotrauma.Networking
} }
float similarity = 0; float similarity = 0;
similarity += sender.ChatSpamSpeed; //the faster messages are being sent, the faster the filter will block similarity += sender.ChatSpamSpeed * 0.05f; //the faster messages are being sent, the faster the filter will block
for (int i = 0; i < sender.ChatMessages.Count; i++) for (int i = 0; i < sender.ChatMessages.Count; i++)
{ {
float closeFactor = 1.0f / (20.0f - i); float closeFactor = 1.0f / (20.0f - i);
+29
View File
@@ -366,6 +366,35 @@ namespace Barotrauma
return inputType; return inputType;
} }
/// <summary>
/// Calculates the minimum number of single-character edits (i.e. insertions, deletions or substitutions) required to change one string into the other
/// </summary>
public static int LevenshteinDistance(string s, string t)
{
int n = s.Length;
int m = t.Length;
int[,] d = new int[n + 1, m + 1];
if (n == 0 || m == 0) return 0;
for (int i = 0; i <= n; d[i, 0] = i++);
for (int j = 0; j <= m; d[0, j] = j++);
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
int cost = (t[j - 1] == s[i - 1]) ? 0 : 1;
d[i, j] = Math.Min(
Math.Min(d[i - 1, j] + 1, d[i, j - 1] + 1),
d[i - 1, j - 1] + cost);
}
}
return d[n, m];
}
public static string WrapText(string text, float lineLength, SpriteFont font) public static string WrapText(string text, float lineLength, SpriteFont font)
{ {
if (font.MeasureString(text).X < lineLength) return text; if (font.MeasureString(text).X < lineLength) return text;