// ---------------------------------------------------------------------------------------- /// <!-- EndemeLeaf_Constructor_test --> /// <summary> /// /// </summary> private void EndemeLeaf_Constructor_test() { Assert.ThingsAbout("hi", "world"); Endeme endeme = InfoAccessTests.WetlandAnimals.RandomEndeme(); EndemeUnit item = new EndemeUnit(endeme); item.Label = "hi"; item.Number = 7; item.Text = "fosdfjej"; Assert.That(item.Endeme.ToString(), Is.equal_to, endeme.ToString()); _result += Assert.Conclusion; }
// ---------------------------------------------------------------------------------------- /// <!-- ToString --> /// <summary> /// Make sure that the endeme set is in the endeme refernce /// </summary> /// <param name="endeme"></param> internal EndemeSet Educe(Endeme endeme) { if (endeme != null && endeme.EnSet != null) { if (this.Contains(endeme.EnSet)) { return(endeme.EnSet); } else { this.Add(endeme.EnSet); return(endeme.EnSet); } } return(null); }
// ---------------------------------------------------------------------------------------- /// <!-- Diff --> /// <summary> /// /// </summary> /// <param name="eq"></param> /// <param name="e2"></param> /// <returns></returns> public int Diff(Endeme e1, Endeme e2) { int total = 0; foreach (char cha in _char.Keys) { if (e1.Contains(cha) && e2.Contains(cha)) { total += Math.Abs((e1.Index(cha)) - (e2.Index(cha))); } else { total += 49; } } return(total); }
// ---------------------------------------------------------------------------------------- /// <!-- ExactlyLike --> /// <summary> /// Returns an item only if it has exactly the same endeme /// </summary> /// <param name="en"></param> /// <returns></returns> public EndemeItem ExactlyLike(Endeme en) { int count = 0; EndemeItem item = null; for (int i = 0; i < this.Count; ++i) { if (this[i].ItemEndeme == en) { count++; item = this[i]; } } if (count > 1) { throw new Exception("boom"); } return(item); }
// ---------------------------------------------------------------------------------------- /// <!-- SetFieldExactly --> /// <summary> /// /// </summary> /// <param name="enSet"></param> /// <param name="endeme"></param> /// <param name="value"></param> /// <returns></returns> public EndemeItem SetFieldExactly(EndemeSet enSet, Endeme endeme, object value) { EndemeItem item = null; // -------------------------------------------------------------------------- // Preprocess the endeme // -------------------------------------------------------------------------- if (endeme == null) { return(null); } else { if (endeme.EnSet == null) { endeme.EnSet = enSet; } if (endeme.EnSet != enSet) { throw new Exception("boom"); } // ---------------------------------------------------------------------- // Figure out what value to store and where to store the value // ---------------------------------------------------------------------- item = this.ExactlyLike(endeme); if (item == null) { item = this.Add("", enSet, endeme, EndemeItem.Simple(new EndemeValue(value))); } else { item.Item = EndemeItem.Simple(new EndemeValue(value)); } //string str = AsciiValue; } return(item); }
// ---------------------------------------------------------------------------------------- /// <!-- SetField --> /// <summary> /// /// </summary> /// <param name="key1"></param> /// <param name="key2"></param> /// <param name="value"></param> public void SetField(EndemeSet enSet, Endeme endeme, object value) { // -------------------------------------------------------------------------- // Preprocess the endeme // -------------------------------------------------------------------------- if (endeme == null) { return; // storage location not definced } else { if (endeme.EnSet == null) { endeme.EnSet = enSet; } if (endeme.EnSet != enSet) { throw new Exception("error- storage endeme has wrong endeme set"); } // ---------------------------------------------------------------------- // Figure out what value to store and where to store the value // ---------------------------------------------------------------------- EndemeItem item = this.MostLike(endeme); if (item == null || item.TempMatch < this.EqualityThreshold) { item = this.Add("", enSet, endeme, EndemeItem.Simple(new EndemeValue(value))); } else { item.Item = EndemeItem.Simple(new EndemeValue(value)); } //string str = AsciiValue; } }
// ---------------------------------------------------------------------------------------- /// <!-- Equals --> /// <summary> /// The first major test is whether height and width are the same /// </summary> /// <param name="obj"></param> /// <returns></returns> public override bool Equals(object obj) { if (obj == null) { return(false); } if (obj == this) { return(true); } if (!(obj is Array2dEndeme)) { return(false); } Array2dEndeme that = (Array2dEndeme)obj; if (that.Height != Height) { return(false); } if (that.Width != Width) { return(false); } bool equals = true; for (int i = 0; equals && i < Height; ++i) { for (int j = 0; equals && j < Width; ++j) { Endeme e1 = this[i, j]; Endeme e2 = that[i, j]; equals = e1.Equals(e2); } } return(equals); }
// ---------------------------------------------------------------------------------------- /// <!-- EndemeAccess_HappyPath_tests --> /// <summary> /// Methods used as intended, no null, empty or border tests /// </summary> /// <remarks></remarks> private void EndemeAccess_HappyPath_tests() { Assert.ThingsAbout("EndemeAccess", "HappyPath"); EndemeSet enSet1 = EndemeTests.WetlandAnimals; Guid setID1 = EndemeAccess.InsertEndemeSet(enSet1, connection, trx); Guid setID2 = EndemeAccess.GetEndemeSetID(enSet1.Label, connection, trx); EndemeSet enSet2 = EndemeAccess.GetEndemeSet(setID2, connection, trx); Endeme en1 = new Endeme(enSet2, "ABC"); Guid enID = EndemeAccess.InsertEndeme(en1, connection, trx); Endeme en2 = EndemeAccess.GetEndeme(enID, connection, trx); Endeme en3 = en2.Copy(); en3.Add("DEF"); int status = EndemeAccess.UpdateEndeme(en3, enID, connection, trx); Assert.That(setID2, Is.equal_to, setID1); Assert.That(enSet2.Count, Is.equal_to, 22); Assert.That(enSet2.Label, Is.equal_to, enSet1.Label); Assert.That(en2.ToString(), Is.equal_to, en1.ToString()); Assert.That(en3.ToString(), Is.equal_to, "ABCDEF"); Assert.That(enSet1.SetId, Is.not_equal_to, Guid.Empty); _result += Assert.Conclusion; }
// ---------------------------------------------------------------------------------------- /// <!-- GetField --> /// <summary> /// /// </summary> /// <param name="enSet"></param> /// <param name="en"></param> /// <returns></returns> public EndemeItem GetField(EndemeSet enSet, Endeme en) { if (en == null || enSet == null) { return(null); } else { if (en.EnSet == null) { en.EnSet = enSet; } if (en.EnSet != enSet) { throw new Exception("boom"); } if (!this.ContainsSet(enSet)) { return(null); } EndemeItem item = this.MostLike(en); return(item); } }
public static Guid A(Exception ex, Endeme actions, GuiActionTrace gat) { return(A(ex, actions, _eventSource, gat)); } /// <param name="level">level of error: 18 if generally good for programmer warnings, 21 is good for critical user level errors</param>
// ---------------------------------------------------------------------------------------- /// <!-- A --> /// <summary> /// Provides a breakpoint in development and throws an exception in production /// </summary> /// <param name="e">exception</param> /// <param name="actions">bug action</param> /// <returns>The id in the database if sent to the database</returns> public static Guid A(Exception ex, Endeme actions, EventSourceCreationData eventSource , GuiActionTrace gat) { if (_exceptionAct == null) { FillExceptionAct(); } // -------------------------------------------------------------------------- // Handle missing exception actions with a default Squawk-Log-Pause // -------------------------------------------------------------------------- if (_actions == null) { _actions = "" + Squawk + EventLog + Pauses; } if (actions == null) { actions = _actions; } // -------------------------------------------------------------------------- // Handle missing event log operational data by complaining // -------------------------------------------------------------------------- if (eventSource == null) { throw new NoNullAllowedException("EventSourceCreationData is null!" + "\r\n" + " You may have to add code something like this before running Throw:" + "\r\n" + " Throw.EventSourceBuild(\"MyProj\", \"MyProLog\");" ); } Guid guid = Guid.Empty; string strGat = ""; // -------------------------------------------------------------------------- // Prepare message text // -------------------------------------------------------------------------- string msg = ""; if (ex.InnerException != null) { msg = ex.InnerException.GetType().ToString() + "\r\n" + ex.InnerException.Message + "\r\n" + "\r\n" + ex.Message; } else { msg = ex.GetType().ToString() + " - " + ex.Message; } // -------------------------------------------------------------------------- // Determine action level // -------------------------------------------------------------------------- //int idx = actions.ToString().IndexOf('L'); //if (idx < 0) idx = 11; //int actionLevel; //if (idx >= 0) actionLevel = 22 - idx; //else actionLevel = 20; // default action level, action level is a callable/programmable cutoff point //// N is a mandatory cutoff point // -------------------------------------------------------------------------- // This is how to do it with an endeme // -------------------------------------------------------------------------- if (msg != _lastMessage && // don't keep spewing out the same messages msg != _prevMessage && !Regex.IsMatch(msg, "Deadlock victim", RegexOptions.IgnoreCase)) // I don't want to hear about deadlock victims { char[] act = actions.ToCharArray(); bool run = true; for (int i = 0; run && i < act.Length; ++i) { switch (act[i]) { //case DataLog: guid = SendToDatabase("CodeWhite", msg, strGat); break; case EventLog: SendToActionLog(msg, eventSource, strGat); break; case Ignore: break; case Email: break; case None: run = false; break; case Pauses: Pause(); break; // set a breakpoint here case Squawk: MessageBox.Show(msg); break; case Throws: throw ex; // turn this on in production and make sure it's handled } } } _prevMessage = _lastMessage; _lastMessage = msg; return(guid); }
//public void Add(EndemeItem item) //{ // ListField.Add(item); //} //public void Add(EndemeObject item) //{ // RegField.Add(item); //} public EndemeList OrderBy(Endeme en) { return(ListField.OrderBy(en)); }
public void Add(Endeme profile, EndemeValue value) { ListField.Add(new EndemeItem(value.Label, profile, value)); }
public Guid Subscribe(Concept observer, string label, EndemeSet enSetRelationship, Endeme enRelationship, EndemeSet enSet, Endeme en) { // -------------------------------------------------------------------------- // Most Concepts will be added to the Observer list // -------------------------------------------------------------------------- EndemeItem standard = new EndemeItem(null); if (standard.ItemKey == Guid.Empty) { throw new Exception("boom"); } if (enRelationship.Count > 1 || !enRelationship.Contains('L')) { standard = Observer.Add(label, enSetRelationship, enRelationship, observer); } if (standard.ItemKey == Guid.Empty) { throw new Exception("boom"); } // -------------------------------------------------------------------------- // A few Concepts will be added to the Friend list // -------------------------------------------------------------------------- if (enRelationship.Contains('L')) { EndemeItem friend = Friend.Add(label, enSet, en, observer); Observer.ChangeGuid(friend.ItemKey, standard.ItemKey); } return(standard.ItemKey); }
// ---------------------------------------------------------------------------------------- // Short methods and properties // ---------------------------------------------------------------------------------------- public void Add(Endeme en) { EndemeItem item = new EndemeItem(en, ""); item.TempMatch = 0.0; Segment.Add(item); }
// ---------------------------------------------------------------------------------------- /// <!-- AsciiArt --> /// <summary> /// /// </summary> /// <param name="cellHeight"></param> /// <param name="cellWidth"></param> /// <returns></returns> public string AsciiArt(int cellHeight, int cellWidth) { Array2dChar cha = new Array2dChar(Height * (cellHeight + 1) + 1, Width * (cellWidth + 1) + 1); // -------------------------------------------------------------------------- // Horizontal lines // -------------------------------------------------------------------------- for (int y = 0; y < cha.Height; ++y) { int mod = y % (cellHeight + 1); if (mod == 0) { for (int x = 0; x < cha.Width; ++x) { cha[y, x] = '-'; } } else { for (int x = 0; x < cha.Width; ++x) { cha[y, x] = '|'; } } } // -------------------------------------------------------------------------- // Vertical lines // -------------------------------------------------------------------------- for (int y = 0; y < cha.Height; ++y) { for (int x = 0; x < cha.Width; ++x) { int mod = y % (cellHeight + 1) + x % (cellWidth + 1); if (mod == 0) { cha[y, x] = '+'; } } } // -------------------------------------------------------------------------- // Endeme array letters // -------------------------------------------------------------------------- for (int y = 0; y < this.Height; ++y) { for (int x = 0; x < this.Width; ++x) { Endeme en = this[y, x]; int i = y * (cellHeight + 1) + 1; int j0 = x * (cellHeight + 1) + 1; int j = j0; cha[i, j] = TreatAs.CharValue(en[0], ' ', ' '); j++; cha[i, j] = TreatAs.CharValue(en[1], ' ', ' '); j = j0; i++; cha[i, j] = TreatAs.CharValue(en[2], ' ', ' '); j++; cha[i, j] = TreatAs.CharValue(en[3], ' ', ' '); } } string str = ""; string line = "+"; for (int j = 0; j < this.Width; ++j) { line += "--+"; } for (int i = 0; i < this.Height; ++i) { str += line; string delim = "\r\n|"; for (int j = 0; j < this.Width; ++j) { str += delim + "AB"; delim = "|"; } str += delim; line = "\r\n+"; for (int j = 0; j < this.Width; ++j) { line += "--+"; } } str += line; //return str; return(cha.AsciiArt("", ' ')); }
public EndemeItem(long endemeId, Endeme en, object value) { Init("", en, new EndemeValue(value)); EndemeId = endemeId; }
private void Init(string label, Endeme path, EndemeValue[] value) { Init(label, path, 0.0); _value = value.ToList <EndemeValue>(); // with linq //_value = new List<object>(value); // without linq }
private EndemeItem(string label, Endeme endeme, EndemeValue[] value) { Init(label, endeme, value); }
public EndemeItem(string label, Endeme endeme, EndemeValue value) { Init(label, endeme, value); }
public EndemeItem(Endeme endeme, EndemeValue value) { Init("", endeme, value); }
} /// <param name="level">level of error: 18 if generally good for programmer warnings, 21 is good for critical user level errors</param><param name="actions">D)atalog, E)ventlog, G)ATtrace, I)gnore, eM)ail, N)one, P)ause, S)quawk, T)hrows</param> public static Guid A(Exception ex, Endeme actions) { return(A(ex, actions, _eventSource, _trace)); }
public void SetField(string enFormatted, object value) { SetField(this.EnRef[Endeme.Part(0, enFormatted)], Endeme.Part(1, enFormatted), value); }
// ---------------------------------------------------------------------------------------- /// <!-- OrderBy --> /// <summary> /// Orders the elements in the list using the 'NewMatch' algorithm (produces a new list) /// </summary> /// <param name="sortEndeme"></param> /// <returns></returns> /// <remarks>beta code - nearly production ready</remarks> public EndemeList OrderBy(Endeme sortEndeme) { if (sortEndeme.EnSet == null) { sortEndeme.EnSet = DefaultEnSet; } // -------------------------------------------------------------------------- // Put the keys in order, preserving the keys // -------------------------------------------------------------------------- EndemeList toOrder = this.CopyAll(); foreach (Guid key in toOrder) { toOrder[key].TempMatch = sortEndeme.Match(toOrder[key].ItemEndeme, WeightFormula.Refined); // TODO: change this to Match1 } // -------------------------------------------------------------------------- // Order the list by match using Linq TODO: use this! // -------------------------------------------------------------------------- List <Guid> orderedKeys = toOrder._list.OrderBy(x => x.Value.TempMatch).Select(x => x.Key).ToList(); //// -------------------------------------------------------------------------- //// Order the list by match without Linq //// -------------------------------------------------------------------------- //Dictionary<Guid,double> quantRaw = new Dictionary<Guid,double>(); //for (int i = 0; i < toOrder.Count; ++i) // quantRaw.Add(toOrder[i].ItemKey, toOrder[i].TempMatch); //SortedDictionary<Guid,double> raw = new SortedDictionary<Guid,double>(quantRaw); //List<Guid> orderedKeys = new List<Guid>(); //List<double> values = new List<double>(raw.Values); //values.Sort(); //for (int i = 0; i < values.Count; ++i) //{ // Guid g = Guid.Empty; // foreach (Guid key in raw.Keys) // { // if (raw[key] == values[i] && raw[key] > 0) // g = key; // } // if (g != Guid.Empty) // { // orderedKeys.Add(g); // raw.Remove(g); // } //} // -------------------------------------------------------------------------- // Put the list in order, preserving the keys // -------------------------------------------------------------------------- EndemeList ordered = new EndemeList(Label, toOrder.DefaultEnSet); foreach (Guid key in orderedKeys) { ordered.Add(key, toOrder[key]); } if (!Sane) { throw new NullReferenceException("EndemeList '" + Label + "' is insane."); } return(ordered); }
public EndemeProfile(Endeme en) { Init(); Segment.Add(new EndemeItem(en, "")); Operator = '+'; }
// ---------------------------------------------------------------------------------------- /// <!-- Knowledge_test --> /// <summary> /// /// </summary> public static void Knowledge_test() { DateTime loc = DateTime.Now; DateTime utc = loc.ToUniversalTime(); string strUtc = utc.ToString(); string strLoc = loc.ToString(); TimeSpan span = loc - utc; bool dltime = loc.IsDaylightSavingTime(); decimal timezone = span.Hours + span.Minutes / 30.0M; object tz = TimeZone.CurrentTimeZone; EndemeNode list1 = new EndemeNode(); EndemeUnit item1 = null; item1 = (EndemeUnit)list1.AddItem(EndemeSet.WetlandAnimals.RandomEndeme(), "A"); item1 = (EndemeUnit)list1.AddItem(EndemeSet.WetlandAnimals.RandomEndeme(), "B"); item1 = (EndemeUnit)list1.AddItem(EndemeSet.WetlandAnimals.RandomEndeme(), "Carrot"); item1 = (EndemeUnit)list1.AddItem(EndemeSet.WetlandAnimals.RandomEndeme(), "C"); item1 = (EndemeUnit)list1.AddItem(EndemeSet.WetlandAnimals.RandomEndeme(), "C"); item1 = (EndemeUnit)list1.AddItem(EndemeSet.WetlandAnimals.RandomEndeme(), "Ducky", 1); EndemeNode list2 = (EndemeNode)list1["C"]; ReflectorTests.Equality("EndemeCollection", "[str]", "C", list2.Count, 2); EndemeNode list3 = (EndemeNode)list1[0]; ReflectorTests.Equality("EndemeCollection", "[0]", 0, list3.Count, 5); Endeme e = EndemeSet.WetlandAnimals.RandomEndeme(); EndemeNode list4 = (EndemeNode)list1[e]; ReflectorTests.Equality("EndemeCollection", "[e]", e, list4.Count, 6); EndemeNode combo = (EndemeNode)list1["C"][0][e]; ReflectorTests.Equality("EndemeCollection", "[C][0][set]", 0, combo.Count, 2); EndemeUnit item2 = (EndemeUnit)list1.GetItem(0); ReflectorTests.Equality("EndemeCollection", "GetItem", 0, item2.Count, 1); EndemeNode list5 = new EndemeNode(); EndemeNode list6 = (EndemeNode)list5.AddList(list1, EndemeSet.WetlandAnimals.RandomEndeme(), "Eagle"); EndemeNode list7 = (EndemeNode)list5.AddList(list1, EndemeSet.WetlandAnimals.RandomEndeme(), "Owl"); EndemeNode list8 = (EndemeNode)list5.AddList(list1, EndemeSet.WetlandAnimals.RandomEndeme(), "Pelican"); ReflectorTests.Equality("EndemeCollection", "AddList", 0, list5.Count, 3); EndemeNode knowledge = new EndemeNode(); knowledge.Enter("/Identity:1-F(1)", "hi world F"); knowledge.Enter("/Identity:.09-G(1)", "hi world G"); knowledge.Enter("/Identity:H(1)", "hi world H"); knowledge.Enter("/Identity:I", "hi world I"); knowledge.Enter("/Identity:1-J", "hi world J"); knowledge.Enter("/Identity:.09-K", "hi world K"); EndemeHierarchy each1 = knowledge.QueryOne("/Identity:1-G(1)"); ReflectorTests.Equality("EndemeCollection", "QueryOne", "/Identity:1-G(1)", each1.Value, "hi world G"); knowledge.Enter("/story part:.9-GTV(1)/identity:1-F(1)", "Gnoephoe"); EndemeHierarchy each2 = knowledge.QueryOne("/story part:.9-GTV(1)"); Type type = each2.GetType(); EndemeUnit sub = (EndemeUnit)((EndemeNode)each2).GetItem(0); ReflectorTests.Equality("EndemeCollection", "GetItem", "0", sub.Value, "Gnoephoe"); EndemeHierarchy each3 = knowledge.QueryOne("/story part:.9-GTV(1)/identity:1-F(1)"); ReflectorTests.Equality("EndemeCollection", "QueryOne", "/story part:.9-GTV(1)/identity:1-F(1)", each3.Value, "Gnoephoe"); // A Associate of X loyalty servant / henchman / involved / partner to X knowledge.Enter("/story part:.9-GTV/identity:1-L(1)", "Brew"); // B Band of X membership group of X // C Competetor of X rivalry rival knowledge.Enter("/story part:1-VRPAGT/identity:1-F(1)", "Pashalia"); // D Destroyer of X destruction killer of X knowledge.Enter("/story part:1-VRPAGT/identity:1-L(1)", "au Taq"); // E Enemy of X evil villain // F Fighter combat combatant / fighting knowledge.Enter("/story part:1-RPVAGT/identity:1-H(1)", "Queen"); // G Guardian of X prevention preventer of X knowledge.Enter("/story part:1-RPVAGT/identity:1-F(1)", "Chelaune"); // H Hero of X goodness good knowledge.Enter("/story part:1-RPVAGT/identity:1-L(1)", "au Taq"); // I Investigator of X investigation detective / inquiry / query / suspect / possible // J Junk / object owner thing / owner / McGuffin / item knowledge.Enter("/story part:1-PRVEGTH/identity:1-H(1)", "King"); // K Knows / witness of X knowledge knowledge belief / witness of X / saw knowledge.Enter("/story part:1-PRVEGTH/identity:1-F(1)", "Mekton"); // L Local non traveling knowledge.Enter("/story part:1-PRVEGTH/identity:1-L(1)", "au Taq"); // M Monster monstrous creature // N Next X subsequent future x knowledge.Enter("/story part:1-LOFHAP/identity:1-F(1)", "Zelda"); // O Official of X leadership leader of X knowledge.Enter("/story part:1-LOFHAP/identity:1-P(1)", "The Amazon Queen"); // P Patron of X patronage client / customer // Q Quester of X traveling company / party / traveler knowledge.Enter("/story part:1-FAH/identity:1-F(1)", "Lida"); // R Related to X family // S Spy / scout secret knowledge.Enter("/story part:1-ARGT/identity:1-F(1)", "Ilso"); // T Thief / kidnapper taker stealer / capturer of X knowledge.Enter("/story part:1-ARGT/identity:1-L(1)", "Brew"); // U Unknowing unknown unbelieving / nonbeliever / ignorant / amnesia / sceptic // V Victim missing lost / damsel knowledge.Enter("/story part:1-OAPSGT/identity:1-H(1)", "Page"); // knowledge.Enter("/story part:1-OAPSGT/identity:1-F(1)", "Jeffrey"); // // knowledge.Enter("/story part:1-AGTPRLH/identity:1-H(1)", "Captain"); // knowledge.Enter("/story part:1-AGTPRLH/identity:1-F(1)", "Bravard"); // knowledge.Enter("/story part:1-AGTPRLH/identity:1-A(1)", "Barvard"); // knowledge.Enter("/player/Identity:1-F(1)", "Jon"); knowledge.Enter("/player/Identity:1-L(1)", "Grover"); //txtMain.Text = (new History()).Generate('y').Display(); //txtMain.Text = (new MapTests()).AllTests() + (new EndemeTests()).AllTests(); }
// ---------------------------------------------------------------------------------------- // Short methods // ---------------------------------------------------------------------------------------- public void AddSegment(Endeme en) { ItemProfile.Add(en); }
// ---------------------------------------------------------------------------------------- // IConceptSource Interface implementation // ---------------------------------------------------------------------------------------- /// <summary> /// Implements a method of IConceptSource (similar to IObservable) /// </summary> /// <returns></returns> public Guid Subscribe(Concept observer, string label, EndemeSet enSetRelationship, Endeme enRelationship) { EndemeItem item = Observer.Add(label, enSetRelationship, enRelationship, observer, true); return(item.ItemKey); }
// ---------------------------------------------------------------------------------------- /// <!-- SelectionBag --> /// <summary> /// Places a bunch of marbles (chars) in a bag for random selection /// </summary> /// <param name="size">number of marbles in bag (try a multiple of 8 <= 120)</param> /// <returns></returns> private List <char> SelectionBag(Endeme e, int size) { Random r = RandomSource.New().Random; if (this.Count > this.OriginalCount) { throw new Exception("SelectionBag"); } // ---------------------------------------------------------------- // Define number of each kind of marble (character) // ---------------------------------------------------------------- char[] endeme = e.ToCharArray(); string str = ""; switch (size) { case 128: str = "@>=;:98765544332221111"; break; case 120: str = "@><;987665443322221111"; break; case 112: str = "?=;:987654433322211111"; break; case 104: str = "><:9876654433222211111"; break; case 96: str = "=;:9776544333222111110"; break; case 88: str = "<:98765544332221111110"; break; case 80: str = ";987665443322221111110"; break; case 72: str = ":877654433322211111100"; break; case 64: str = "9876544333222111111000"; break; case 60: str = "8766544332222111111000"; break; case 56: str = "8765543332221111110000"; break; case 52: str = "7665443322221111110000"; break; case 48: str = "7655433322211111100000"; break; case 44: str = "6554433222211111100000"; break; case 40: str = "6544333222111111000000"; break; case 36: str = "5544332221111110000000"; break; case 32: str = "5433322221111110000000"; break; case 28: str = "4433222211111100000000"; break; case 24: str = "4332222111111000000000"; break; case 20: str = "3322221111110000000000"; break; case 16: str = "3222111111100000000000"; break; case 14: str = "2222111111000000000000"; break; case 12: str = "2221111110000000000000"; break; case 10: str = "2211111100000000000000"; break; case 8: str = "2111111000000000000000"; break; case 7: str = "2111110000000000000000"; break; case 6: str = "1111110000000000000000"; break; case 5: str = "1111100000000000000000"; break; case 4: str = "1111000000000000000000"; break; case 3: str = "1110000000000000000000"; break; case 2: str = "1100000000000000000000"; break; case 1: str = "1000000000000000000000"; break; default: str = ""; Dictionary <char, int> cha = new Dictionary <char, int>(22); foreach (char c in endeme) { cha.Add(c, 0); } for (int i = 0; i < size; ++i) { cha[e.RandomLetter(0.89)]++; } var query = from ch in cha orderby cha.Values descending select cha; str = ""; foreach (var item in query) { str = str + item.ToString(); } break; // TODO: build the function that approximates these series (.89 * one before) } // ---------------------------------------------------------------- // Put marbles (characters) in bag // ---------------------------------------------------------------- List <int> quantity = StringToNums(str); List <char> bag = new List <char>(size); for (int i = 0; i < quantity.Count; ++i) { for (int j = 0; j < quantity[i]; ++j) { if (i < endeme.Length) { bag.Add(endeme[i]); } else if (endeme.Length > 0) { bag.Add(endeme[0]); } } } return(bag); }
private void Init(string label, string code, Endeme endeme, double match) { Init(label, new EndemeProfile(endeme), match); }