-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
layagyasz
committed
Jul 23, 2019
0 parents
commit 09c9b3c
Showing
21 changed files
with
1,051 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Autosave files | ||
*~ | ||
|
||
# build | ||
[Oo]bj/ | ||
[Bb]in/ | ||
packages/ | ||
TestResults/ | ||
|
||
# globs | ||
Makefile.in | ||
*.DS_Store | ||
*.sln.cache | ||
*.suo | ||
*.cache | ||
*.pidb | ||
*.userprefs | ||
*.usertasks | ||
config.log | ||
config.make | ||
config.status | ||
aclocal.m4 | ||
install-sh | ||
autom4te.cache/ | ||
*.user | ||
*.tar.gz | ||
tarballs/ | ||
test-results/ | ||
Thumbs.db | ||
|
||
# Mac bundle stuff | ||
*.dmg | ||
*.app | ||
|
||
# resharper | ||
*_Resharper.* | ||
*.Resharper | ||
|
||
# dotCover | ||
*.dotCover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2012 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hauyne", "Hauyne\Hauyne.csproj", "{9B5BF73D-5F30-4C25-A5F0-B2162A4B0AC9}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|x86 = Debug|x86 | ||
Release|x86 = Release|x86 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{9B5BF73D-5F30-4C25-A5F0-B2162A4B0AC9}.Debug|x86.ActiveCfg = Debug|x86 | ||
{9B5BF73D-5F30-4C25-A5F0-B2162A4B0AC9}.Debug|x86.Build.0 = Debug|x86 | ||
{9B5BF73D-5F30-4C25-A5F0-B2162A4B0AC9}.Release|x86.ActiveCfg = Release|x86 | ||
{9B5BF73D-5F30-4C25-A5F0-B2162A4B0AC9}.Release|x86.Build.0 = Release|x86 | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using System.Collections.Generic; | ||
|
||
namespace Hauyne.Engine | ||
{ | ||
public class Generated<T> : IEnumerable<T> | ||
{ | ||
protected List<T> _Sounds = new List<T>(); | ||
|
||
T Last { get { return _Sounds[_Sounds.Count - 1]; } } | ||
T First { get { return _Sounds[0]; } } | ||
public int Length { get { return _Sounds.Count; } } | ||
|
||
public IEnumerator<T> GetEnumerator() { return _Sounds.GetEnumerator(); } | ||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() | ||
{ | ||
return GetEnumerator(); | ||
} | ||
|
||
public T this[int Index] { get { return _Sounds[Index]; } } | ||
|
||
public Generated() { } | ||
public Generated(T Initial) { _Sounds.Add(Initial); } | ||
|
||
|
||
public void Combine(Generated<T> Word) | ||
{ | ||
if (Word != null) foreach (T S in Word._Sounds) _Sounds.Add(S); | ||
} | ||
|
||
public void Remove(int Index, int Length) | ||
{ | ||
_Sounds.RemoveRange(Index, Length); | ||
} | ||
|
||
public void Insert(int Index, List<T> Values) | ||
{ | ||
for (int i = Values.Count - 1; i >= 0; --i) | ||
{ | ||
_Sounds.Insert(Index, Values[i]); | ||
} | ||
} | ||
|
||
public void RemoveDoubles() | ||
{ | ||
for (int i = 0; i < _Sounds.Count - 1; ++i) | ||
{ | ||
if (_Sounds[i].Equals(_Sounds[i + 1])) _Sounds.RemoveAt(i); | ||
} | ||
} | ||
|
||
public override string ToString() | ||
{ | ||
string R = ""; | ||
foreach (T S in _Sounds) R += S.ToString(); | ||
return R; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
|
||
namespace Hauyne.Engine | ||
{ | ||
interface Generator<T> | ||
{ | ||
double Frequency { get; } | ||
Generated<T> Generate(Random Random); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Hauyne.Parsing; | ||
|
||
namespace Hauyne.Engine | ||
{ | ||
class MatchRule<T> where T : Generator<T> | ||
{ | ||
public static readonly Set<T> StartGenerated = new Set<T>(); | ||
public static readonly Set<T> EndGenerated = new Set<T>(); | ||
|
||
List<Set<T>> _Sets = new List<Set<T>>(); | ||
int _Length; | ||
int _StartIndex = 0; | ||
int _EndIndex = -1; | ||
|
||
public int Length { get { return _Length; } } | ||
public int StartIndex { get { return _StartIndex; } } | ||
public int EndIndex { get { return _EndIndex; } } | ||
|
||
public MatchRule(string Source, List<Operator<T>> Operators, Dictionary<string, Generator<T>> Generators) | ||
{ | ||
string[] s = Source.Split(':'); | ||
for (int i = 0; i < s.Length; ++i) | ||
{ | ||
string S = s[i]; | ||
if (S.Trim() == "$") | ||
{ | ||
if (_Sets.Count == 0) | ||
{ | ||
_Sets.Add(StartGenerated); | ||
_StartIndex = 1; | ||
} | ||
else | ||
{ | ||
_Sets.Add(EndGenerated); | ||
_Length--; | ||
} | ||
} | ||
else | ||
{ | ||
if (S.Contains('(')) | ||
{ | ||
_StartIndex = _Length; | ||
S = S.Replace("(", ""); | ||
} | ||
if (S.Contains(')')) | ||
{ | ||
_EndIndex = _Length; | ||
S = S.Replace(")", ""); | ||
} | ||
_Sets.Add(Set<T>.ParseSet(S, Operators, Generators)); | ||
} | ||
_Length++; | ||
} | ||
if (_EndIndex == -1) _EndIndex = _Length - 1; | ||
_Length = _EndIndex - _StartIndex + 1; | ||
} | ||
|
||
public bool Match(Generated<T> CompareTo, int Index) | ||
{ | ||
for (int i = -StartIndex; i + StartIndex < _Sets.Count; ++i) | ||
{ | ||
if (Index + i < -1) return false; | ||
else if (Index + i > CompareTo.Length) return false; | ||
else if (Index + i == -1 && _Sets[i + StartIndex] != StartGenerated) return false; | ||
else if (Index + i == CompareTo.Length && _Sets[i + StartIndex] != EndGenerated) return false; | ||
else if (Index + i > -1 && Index + i < CompareTo.Length && !_Sets[i + StartIndex].Contains(CompareTo[Index + i])) return false; | ||
} | ||
return true; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
using Cardamom.Utilities; | ||
using Cardamom.Serialization; | ||
|
||
using Hauyne.Parsing; | ||
|
||
namespace Hauyne.Engine | ||
{ | ||
internal class PrintRule<T> where T : Generator<T> | ||
{ | ||
MatchRule<T> _Match; | ||
WeightedVector<string> _Options = new WeightedVector<string>(); | ||
|
||
public int Length { get { return _Match.Length; } } | ||
|
||
public PrintRule(ParseBlock Block, List<Operator<T>> Operators, Dictionary<string, Generator<T>> Generators) | ||
{ | ||
string[] def = Block.String.Split(new string[] { "=>" }, StringSplitOptions.None); | ||
_Match = new MatchRule<T>(def[0], Operators, Generators); | ||
string[] ops = def[1].Split(':'); | ||
for (int i = 0; i < ops.Length; ++i) | ||
{ | ||
if (ops[i].Contains('*')) | ||
{ | ||
string[] d = ops[i].Split('*'); | ||
_Options.Add(Convert.ToDouble(d[0], System.Globalization.CultureInfo.InvariantCulture), d[1].Trim()); | ||
} | ||
else | ||
{ | ||
_Options.Add(1, ops[i].Trim()); | ||
} | ||
} | ||
} | ||
|
||
public bool Match(Generated<T> MatchIn, int Index) | ||
{ | ||
return _Match.Match(MatchIn, Index); | ||
} | ||
|
||
public string Get(double Index) { return _Options[Index]; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
using Cardamom.Serialization; | ||
|
||
using Hauyne.Parsing; | ||
|
||
namespace Hauyne.Engine | ||
{ | ||
class ReplaceRule<T> where T : Generator<T> | ||
{ | ||
MatchRule<T> _Match; | ||
SingleGenerator<T> _Replacement; | ||
|
||
public ReplaceRule(ParseBlock Block, List<Operator<T>> Operators, Dictionary<string, Generator<T>> Generators) | ||
{ | ||
string[] def = Block.String.Split(new string[] { "=>" }, StringSplitOptions.None); | ||
_Match = new MatchRule<T>(def[0], Operators, Generators); | ||
_Replacement = new SingleGenerator<T>(def[1], Operators, Generators); | ||
} | ||
|
||
public void Replace(Random Random, Generated<T> ReplaceIn, int Index) | ||
{ | ||
if (_Match.Match(ReplaceIn, Index)) | ||
{ | ||
ReplaceIn.Remove(Index, _Match.Length); | ||
List<T> New = new List<T>(); | ||
Generated<T> R = _Replacement.Generate(Random); | ||
foreach (T S in R) New.Add(S); | ||
ReplaceIn.Insert(Index, New); | ||
} | ||
} | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.