summaryrefslogtreecommitdiff
path: root/DiscoBot/Misc.cs
diff options
context:
space:
mode:
Diffstat (limited to 'DiscoBot/Misc.cs')
-rw-r--r--DiscoBot/Misc.cs162
1 files changed, 145 insertions, 17 deletions
diff --git a/DiscoBot/Misc.cs b/DiscoBot/Misc.cs
index 3876321..9c9456c 100644
--- a/DiscoBot/Misc.cs
+++ b/DiscoBot/Misc.cs
@@ -8,9 +8,12 @@ namespace DiscoBot
{
public static class Misc
{
- public static string Roll(string input)
+ private static readonly Random Rand = new Random();
+
+ // use: 4w6 +4
+ public static string Roll(string input)
{
- int count = 1, d,mod=0;
+ int count = 1, d ,mod=0;
var Output = new StringBuilder();
List<string> strings = input.Split('w','d').ToList();
count = Convert.ToInt32(strings[0]);
@@ -31,7 +34,131 @@ namespace DiscoBot
return Output.ToString();
}
+
+ public static double Random(double stdDev = 1, double mean = 0)
+ {
+ double u1 = Rand.NextDouble(); // uniform(0,1) random doubles
+ double u2 = Rand.NextDouble();
+ double randStdNormal = Math.Sqrt(-2.0 * Math.Log(u1)) *
+ Math.Sin(2.0 * Math.PI * u2); // random normal(0,1)
+ double randNormal =
+ mean + stdDev * randStdNormal; // random normal(mean,stdDev^2)
+ return randNormal;
+ }
+ }
+
+ public class SpellCorrect : StringComparer
+ {
+ public override int Compare(string x, string y)
+ {
+ if (x.Equals(y))
+ return 0;
+ x=x.ToLower();
+ y=y.ToLower();
+ if (x.Equals(y))
+ return 1;
+ var subs = y.Split(' ', '/');
+ int score = subs.Count();
+ foreach (string s in subs)
+ {
+ if (s.Equals(x))
+ {
+ score--;
+ }
+ }
+
+ if (score < subs.Count())
+ {
+ return score + 1;
+ }
+
+ return 100000 - (int)(compare_exact(x, y) * 1000.0);
+ /*if (y.Contains(x))
+ return 6;*/
+
+ }
+
+ public override bool Equals(string x, string y)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override int GetHashCode(string obj)
+ {
+ throw new NotImplementedException();
+ }
+
+ public double compare_exact(string s, string q)
+ {
+ int i, j;
+ const double Match = 3.0;
+ const double Gap = -2.0;
+ const double Mismatch = -2.0;
+
+ double decay = 0.0;
+
+ double[,] matrix = new double[s.Length + 1, q.Length + 1];
+ double max = 0.0;
+ matrix[0, 0] = 0.0;
+
+ for (i = 1; i < s.Length; i++)
+ {
+ matrix[i, 0] = 0.0;
+ }
+
+ for (i = 1; i < q.Length; i++)
+ {
+ matrix[0, i] = 0.0;
+ }
+
+ for (i = 1; i <= s.Length; i++)
+ {
+ for (j = 1; j <= q.Length; j++)
+ {
+ decay = j / (double)(s.Length * 1000);
+ double add = s[i - 1] == q[j - 1] ? (Match - decay) : Mismatch;
+ double score = matrix[i - 1, j - 1] + add;
+
+ if (score < (matrix[i - 1, j] + Gap))
+ {
+ score = matrix[i - 1, j] + Gap;
+ }
+
+ if (score < (matrix[i, j - 1] + Gap))
+ {
+ score = matrix[i, j - 1] + Gap;
+ }
+
+ if (i > 1 && j > 1)
+ {
+ if (s[i - 1] == q[j - 2] && s[i - 2] == q[j - 1])
+ {
+ add = (3 / 2.0) * Match - decay;
+ if (score < matrix[i - 2, j - 2] + add)
+ {
+ score = matrix[i - 2, j - 2] + add;
+ }
+ }
+ }
+
+ if (score < 0)
+ {
+ score = 0;
+ }
+
+ if (max < score)
+ {
+ max = score;
+ }
+
+ matrix[i, j] = score;
+ }
+ }
+
+ return max;
+ }
}
+
public static class dice//roll it!
{
static System.Random rnd = new System.Random();
@@ -40,6 +167,19 @@ namespace DiscoBot
return rnd.Next(1, d+1);
}
}
+
+ public class Vorteil //talent objekt
+ {
+ public string name;
+ public int value;
+
+ public Vorteil(string name, int value = 0)
+ {
+ this.name = name;
+ this.value = value;
+ }
+ }
+
public class Talent //talent objekt
{
public string name, probe;
@@ -55,24 +195,12 @@ namespace DiscoBot
public int CheckName(string quary)
{
- if (quary.Equals(name))
- return 0;
- if (String.Compare(name, quary, StringComparison.InvariantCultureIgnoreCase) == 0)
- return 1;
- var subs = name.Split(' ','/');
- int score = subs.Count();
- foreach (String s in subs)
- if (String.Compare(name, quary, StringComparison.InvariantCultureIgnoreCase) == 0)
- score--;
- if (score != subs.Count())
- return score+1;
- if (name.ToLowerInvariant().Contains(quary.ToLower()))
- return 3;
-
- return 100;
+ var sc = (StringComparer)new SpellCorrect();
+ return sc.Compare(quary, this.name);
}
}
+
public class Kampf
{
public string name;