// ---------------------------------------------------------------------------------------- /// <!-- 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); }