Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 68 additions & 7 deletions exercise.main/Core.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;

using System.Collections.Generic;
using System.Linq;
using System.Reflection;
Expand All @@ -10,23 +11,83 @@ namespace exercise.main
{
public class Core
{


//TODO: complete the following method, keeping the signature the same
public bool winningPair(IEnumerable<Tuple<string, string>> hand, out Tuple<string, string> result)
{
result = new Tuple<string,string>(string.Empty, string.Empty);


result = new Tuple<string, string>(string.Empty, string.Empty);


foreach (var pair in hand)
{
if (GetValueOfCard(pair.Item1) == GetValueOfCard(pair.Item2) &&
GetValueOfCard(pair.Item1) > GetValueOfCard(result.Item1))
{
result = pair;


}


}

return result.Item1!=string.Empty ? true : false;

}
public int GetValueOfCard(string card)
{
return 0;
if (card == "2")
{
return 2;
}
else if (card == "3")
{
return 3;
}
else if (card == "4")
{
return 4;
}
else if (card == "5")
{
return 5;
}
else if (card == "6")
{
return 6;
}
else if (card == "7")
{
return 7;
}
else if (card == "8")
{
return 8;
}
else if (card == "9")
{
return 9;
}
else if (card == "10")
{
return 10;
} else if (card == "J")
{
return 11;
} else if (card == "Q")
{
return 12;
} else if (card == "K")
{
return 13;
} else if (card == "A")
{
return 14;
} else
{
return 0;
}

}
}
}
72 changes: 71 additions & 1 deletion exercise.main/Extension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,77 @@ public bool winningThree(IEnumerable<Tuple<string, string, string>> hand, out Tu
{
result = new Tuple<string, string, string>(string.Empty, string.Empty, string.Empty);

return false;

foreach (var triplePair in hand) {

if (triplePair.Item1 == triplePair.Item2 && triplePair.Item3 == triplePair.Item2
&& GetValueOfCard(triplePair.Item1) > GetValueOfCard(result.Item1)){
result = triplePair;
}
}

return result.Item1 != string.Empty ? true : false;
}

public int GetValueOfCard(string card)
{
if (card == "2")
{
return 2;
}
else if (card == "3")
{
return 3;
}
else if (card == "4")
{
return 4;
}
else if (card == "5")
{
return 5;
}
else if (card == "6")
{
return 6;
}
else if (card == "7")
{
return 7;
}
else if (card == "8")
{
return 8;
}
else if (card == "9")
{
return 9;
}
else if (card == "10")
{
return 10;
}
else if (card == "J")
{
return 11;
}
else if (card == "Q")
{
return 12;
}
else if (card == "K")
{
return 13;
}
else if (card == "A")
{
return 14;
}
else
{
return 0;
}

}

}
Expand Down
24 changes: 24 additions & 0 deletions exercise.main/Objects/Card.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main.Objects
{
public class Card
{
private string _value;

private string _suit;

public Card(string value, string suit)
{
_value = value;
_suit = suit;
}

public string Value { get { return _value; } set { _value = value; } }
public string Suit { get { return _suit; } set { _suit = value; } }
}
}
50 changes: 50 additions & 0 deletions exercise.main/Objects/Deck.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main.Objects
{
public class Deck
{

private List<Card> _cards;

public Deck(List<Card> cards)
{
_cards = cards;
}

public List<Card> Cards { get { return _cards; } set { _cards = value; } }

public void Shuffle()
{
Random rng = new Random();
int n = Cards.Count;
while (n > 1)
{
n--;
int k = rng.Next(n + 1);
Card value = Cards[k];
Cards[k] = Cards[n];
Cards[n] = value;

}


}

public Card Deal()
{
Card drawnCard = Cards.First();
Cards.Remove(Cards.First());
return drawnCard;
}



}
}
40 changes: 40 additions & 0 deletions exercise.main/Objects/Player.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;

namespace exercise.main.Objects
{
public class Player
{
private string _name;
private List<Card> _hand;

public Player (string name, List<Card> hand)
{
_name = name;
_hand = hand;

}

public string Name { get { return _name; } set { _name = value; } }
public List<Card> Hand { get { return _hand; } set { _hand = value; } }

public void AddCard(Card newCard){
Hand.Add(newCard);
}

public void ClearHand(){
Hand.Clear();
}

public List<Card> currentHand(){
return Hand;
}



}
}
Loading