public ActionResult DetermineWinner(int tableID) { TableSqlDal dal = new TableSqlDal(); Table table = GetTableInfo(tableID); Dictionary <string, Hand> handsToCompare = new Dictionary <string, Hand>(); IList <string> winnerByFold = new List <string>(); foreach (Seat s in table.Seats) { if (!s.HasFolded) { winnerByFold.Add(s.Username); } } if (winnerByFold.Count == 1) { dal.SaveWinner(tableID, winnerByFold); dal.SaveWiningMoney(tableID, winnerByFold[0], table.Pot); } else { foreach (var seat in table.Seats) { if (!seat.HasFolded && seat.Username != "Available") { handsToCompare.Add(seat.Username, seat.Hand); } } IList <string> winner = FiveCardDrawEvaluator.Evaluate(handsToCompare); dal.SaveWinner(tableID, winner); foreach (var person in winner) { dal.SaveWiningMoney(tableID, person, (table.Pot / winner.Count)); } } foreach (var seat in table.Seats) { if (seat.Username != "Available") { dal.SetNotFolded(table.TableID, seat.Username); dal.SetCurrentBet(table.TableID, seat.Username); } } return(RedirectToAction("HandSetup", new { tableID = tableID })); }
public void EvaluateTest() { Dictionary <string, Hand> hands = new Dictionary <string, Hand>(); Hand h1 = new Hand(); h1.MyHand = new List <Card>() { new Card { Suit = "diamonds", Number = 5 }, new Card { Suit = "diamonds", Number = 4 }, new Card { Suit = "diamonds", Number = 2 }, new Card { Suit = "diamonds", Number = 7 }, new Card { Suit = "diamonds", Number = 3 }, }; hands.Add("isaac", h1); Hand h2 = new Hand(); h2.MyHand = new List <Card>() { new Card { Suit = "spades", Number = 11 }, new Card { Suit = "spades", Number = 4 }, new Card { Suit = "spades", Number = 2 }, new Card { Suit = "spades", Number = 7 }, new Card { Suit = "spades", Number = 3 }, }; hands.Add("dan", h2); var result = FiveCardDrawEvaluator.Evaluate(hands); Assert.AreEqual(1, result.Count); Assert.AreEqual("dan", result[0]); }