public void Test_Indexes() { DeckDescriptor dd = new DeckDescriptor("TestDeck", _cardNames1, _cardSets1); Assert.AreEqual(0, dd.GetIndex("Q")); Assert.AreEqual(1, dd.GetIndex("K")); Assert.AreEqual(2, dd.GetIndex("A")); Assert.AreEqual(new int[] {}, dd.GetIndexes("")); Assert.AreEqual(new int[] { 2 }, dd.GetIndexes("A")); Assert.AreEqual(new int[] { 1, 2 }, dd.GetIndexes("K A")); Assert.AreEqual(new int[] { 2, 1 }, dd.GetIndexes("A K")); Assert.AreEqual(new List <int>(), dd.GetIndexesAscending(new CardSet { bits = 0x0 })); Assert.AreEqual(new List <int>(new int[] { 0 }), dd.GetIndexesAscending(new CardSet { bits = 0x1 })); Assert.AreEqual(new List <int>(new int[] { 0, 2 }), dd.GetIndexesAscending(new CardSet { bits = 0x11 })); }
public void Benchmark_GetIndex() { DeckDescriptor dd = StdDeck.Descriptor; int repetitions = 10000000; DateTime start = DateTime.Now; int sum = 0; for (int r = 0; r < repetitions; ++r) { sum += dd.GetIndex(dd.CardNames[r % dd.Size]); } double time = (DateTime.Now - start).TotalSeconds; Console.WriteLine("Repetitions: {0:#,#}, time: {1:0.00} s, rep/s: {2:#,#}", repetitions, time, repetitions / time); }
private static bool ReadCard(string gameString, ref int curPos, ref string error, DealerAction parsedAction, DeckDescriptor deckDescr) { int card; int nextSpace = gameString.IndexOf(' ', curPos); int cardLength = nextSpace == -1 ? gameString.Length - curPos : nextSpace - curPos; string textCard = gameString.Substring(curPos, cardLength); if (deckDescr == null) { if (!int.TryParse(textCard, out card)) { return(Error(out error, String.Format("Wrong card {0}", textCard))); } } else { card = deckDescr.GetIndex(textCard); } parsedAction.Card = card; curPos += cardLength; return(true); }