From 57bf2cc6a029ec875baa99dda5f23ec78a5c05cd Mon Sep 17 00:00:00 2001 From: Tonnes Date: Tue, 28 Jan 2025 10:21:37 +0100 Subject: [PATCH] Done --- exercise.main/Core.cs | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/exercise.main/Core.cs b/exercise.main/Core.cs index bf5077d..6bc34c9 100644 --- a/exercise.main/Core.cs +++ b/exercise.main/Core.cs @@ -10,23 +10,44 @@ namespace exercise.main { public class Core { - + // Note: // IEnumerable is a class that the List inherits (ie List has all the functionality of IEnumerable) // IEnumerable allows you to use a foreach loop on the variable hands (which is a List of tuples) - + //TODO: complete the winningPair method, without chaning the method signature public bool winningPair(IEnumerable> hands, out Tuple result) { - result = new Tuple(string.Empty, string.Empty); - // your code here... + result = new Tuple(string.Empty, string.Empty); + + Dictionary cardValues = new Dictionary + {{ "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 }, { "6", 6 }, { "7", 7 }, { "8", 8 }, + { "9", 9 }, { "10", 10 }, { "J", 11 }, { "Q", 12 }, { "K", 13 }, { "A", 14 }}; + + var handList = hands.ToList(); + int topScore = 0; + + foreach (var hand in handList) + { + if (hand.Item1 == hand.Item2) + { + if (cardValues[hand.Item1] > topScore) + { + topScore = cardValues[hand.Item1]; + result = hand; + } + } + } return result.Item1!=string.Empty ? true : false; } public int GetValueOfCard(string card) { - return 0; + Dictionary cardValues = new Dictionary + {{ "2", 2 }, { "3", 3 }, { "4", 4 }, { "5", 5 }, { "6", 6 }, { "7", 7 }, { "8", 8 }, + { "9", 9 }, { "10", 10 }, { "J", 11 }, { "Q", 12 }, { "K", 13 }, { "A", 14 }}; + return cardValues[card]; } } }