From 366643a92407babb280f4570569eb234634b1ff7 Mon Sep 17 00:00:00 2001 From: bjorgastrid Date: Tue, 13 Aug 2024 15:56:29 +0200 Subject: [PATCH] completed core --- exercise.main/Core.cs | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/exercise.main/Core.cs b/exercise.main/Core.cs index bf5077d..661aea2 100644 --- a/exercise.main/Core.cs +++ b/exercise.main/Core.cs @@ -10,6 +10,13 @@ namespace exercise.main { public class Core { + Dictionary cardValue = new Dictionary() + { + ["J"] = 11, + ["Q"] = 12, + ["K"] = 13, + ["A"] = 14 + }; // Note: // IEnumerable is a class that the List inherits (ie List has all the functionality of IEnumerable) @@ -19,14 +26,33 @@ public class Core public bool winningPair(IEnumerable> hands, out Tuple result) { result = new Tuple(string.Empty, string.Empty); + int winnerValue = 0; - // your code here... + foreach(Tuple pair in hands) + { + if (pair.Item1.Equals(pair.Item2)) + { + + if (GetValueOfCard(pair.Item1) > winnerValue ) + { + result = pair; + winnerValue = GetValueOfCard(pair.Item1); + } + } + } return result.Item1!=string.Empty ? true : false; } public int GetValueOfCard(string card) { - return 0; + if (cardValue.ContainsKey(card)) + { + return cardValue[card]; + } + else + { + return int.Parse(card); + } } } }