diff --git a/94 War/csharp/War/War.sln b/94 War/csharp/War/War.sln index a03a3a64..fcb2d2c2 100644 --- a/94 War/csharp/War/War.sln +++ b/94 War/csharp/War/War.sln @@ -5,8 +5,6 @@ VisualStudioVersion = 16.0.31112.23 MinimumVisualStudioVersion = 10.0.40219.1 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "War", "War\War.csproj", "{C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WarTester", "WarTester\WarTester.csproj", "{ACB0D6AD-9675-4E72-BB97-BBB2241CB494}" -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -17,10 +15,6 @@ Global {C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}.Debug|Any CPU.Build.0 = Debug|Any CPU {C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}.Release|Any CPU.ActiveCfg = Release|Any CPU {C13BE0FA-D8F7-4CA7-A95D-DA03A9DE8950}.Release|Any CPU.Build.0 = Release|Any CPU - {ACB0D6AD-9675-4E72-BB97-BBB2241CB494}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {ACB0D6AD-9675-4E72-BB97-BBB2241CB494}.Debug|Any CPU.Build.0 = Debug|Any CPU - {ACB0D6AD-9675-4E72-BB97-BBB2241CB494}.Release|Any CPU.ActiveCfg = Release|Any CPU - {ACB0D6AD-9675-4E72-BB97-BBB2241CB494}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/94 War/csharp/War/War/Cards.cs b/94 War/csharp/War/War/Cards.cs index 1efdc715..7c31c3b2 100644 --- a/94 War/csharp/War/War/Cards.cs +++ b/94 War/csharp/War/War/Cards.cs @@ -111,7 +111,8 @@ namespace War public class Deck { - private const int deckSize = 52; + public const int deckSize = 52; + private Card[] theDeck = new Card[deckSize]; public Deck() @@ -127,9 +128,21 @@ namespace War } } + public Card GetCard(int i) => theDeck[i]; + public void Shuffle() { + // https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle + for (int i = deckSize - 1; i >= 1; i--) + { + var rand = new Random(); + int j = rand.Next(0, i); + // Swap the cards at i and j + Card temp = theDeck[j]; + theDeck[j] = theDeck[i]; + theDeck[i] = temp; + } } } } diff --git a/94 War/csharp/War/WarTester/Tests.cs b/94 War/csharp/War/WarTester/Tests.cs deleted file mode 100644 index 1e811c9e..00000000 --- a/94 War/csharp/War/WarTester/Tests.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Microsoft.VisualStudio.TestTools.UnitTesting; -using War; - - - -namespace WarTester -{ - [TestClass] - public class CardTest - { - Card c1 = new Card(Suit.clubs, Rank.two); - Card c2 = new Card(Suit.clubs, Rank.ten); - Card c3 = new Card(Suit.diamonds, Rank.ten); - Card c4 = new Card(Suit.diamonds, Rank.ten); - - [TestMethod] - public void LessThan_IsValid() - { - Assert.IsTrue(c1 < c2, "c1 < c2"); // Same suit, different rank. - Assert.IsFalse(c2 < c1, "c2 < c1"); // Same suit, different rank. - - Assert.IsFalse(c3 < c4, "c3 < c4"); // Same suit, same rank. - - Assert.IsTrue(c1 < c3, "c1 < c3"); // Different suit, different rank. - Assert.IsFalse(c3 < c1, "c3 < c1"); // Different suit, different rank. - - Assert.IsFalse(c2 < c4, "c2 < c4"); // Different suit, same rank. - Assert.IsFalse(c4 < c2, "c4 < c2"); // Different suit, same rank. - } - - [TestMethod] - public void GreaterThan_IsValid() - { - Assert.IsFalse(c1 > c2, "c1 > c2"); // Same suit, different rank. - Assert.IsTrue(c2 > c1, "c2 > c1"); // Same suit, different rank. - - Assert.IsFalse(c3 > c4, "c3 > c4"); // Same suit, same rank. - - Assert.IsFalse(c1 > c3, "c1 > c3"); // Different suit, different rank. - Assert.IsTrue(c3 > c1, "c3 > c1"); // Different suit, different rank. - - Assert.IsFalse(c2 > c4, "c2 > c4"); // Different suit, same rank. - Assert.IsFalse(c4 > c2, "c4 > c2"); // Different suit, same rank. - } - - [TestMethod] - public void LessThanEquals_IsValid() - { - Assert.IsTrue(c1 <= c2, "c1 <= c2"); // Same suit, different rank. - Assert.IsFalse(c2 <= c1, "c2 <= c1"); // Same suit, different rank. - - Assert.IsTrue(c3 <= c4, "c3 <= c4"); // Same suit, same rank. - - Assert.IsTrue(c1 <= c3, "c1 <= c3"); // Different suit, different rank. - Assert.IsFalse(c3 <= c1, "c3 <= c1"); // Different suit, different rank. - - Assert.IsTrue(c2 <= c4, "c2 <= c4"); // Different suit, same rank. - Assert.IsTrue(c4 <= c2, "c4 <= c2"); // Different suit, same rank. - } - - [TestMethod] - public void GreaterThanEquals_IsValid() - { - Assert.IsFalse(c1 >= c2, "c1 >= c2"); // Same suit, different rank. - Assert.IsTrue(c2 >= c1, "c2 >= c1"); // Same suit, different rank. - - Assert.IsTrue(c3 >= c4, "c3 >= c4"); // Same suit, same rank. - - Assert.IsFalse(c1 >= c3, "c1 >= c3"); // Different suit, different rank. - Assert.IsTrue(c3 >= c1, "c3 >= c1"); // Different suit, different rank. - - Assert.IsTrue(c2 >= c4, "c2 >= c4"); // Different suit, same rank. - Assert.IsTrue(c4 >= c2, "c4 >= c2"); // Different suit, same rank. - } - - [TestMethod] - public void ToString_IsValid() - { - string s1 = c1.ToString(); - string s2 = c3.ToString(); - string s3 = new Card(Suit.hearts, Rank.queen).ToString(); - string s4 = new Card(Suit.spades, Rank.ace).ToString(); - - Assert.IsTrue(s1 == "C-2", "s1 invalid"); - Assert.IsTrue(s2 == "D-10", "s2 invalid"); - Assert.IsTrue(s3 == "H-Q", "s3 invalid"); - Assert.IsTrue(s4 == "S-A", "s4 invalid"); - } - } -} diff --git a/94 War/csharp/War/WarTester/WarTester.csproj b/94 War/csharp/War/WarTester/WarTester.csproj deleted file mode 100644 index 84aa459a..00000000 --- a/94 War/csharp/War/WarTester/WarTester.csproj +++ /dev/null @@ -1,20 +0,0 @@ - - - - netcoreapp3.1 - - false - - - - - - - - - - - - - -