public static void randomlyGeneratedTest() { List <Player> players = new List <Player>(); Random random = new Random(); for (int i = 0; i < 10000; i++) { players.Clear(); Player player = new Player("Joe", new List <Card>() { new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)) }); player.display(); players.Add(player); player = new Player("Bob", new List <Card>() { new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)) }); player.display(); players.Add(player); player = new Player("Sally", new List <Card>() { new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)), new Card((Suit)random.Next(0, 3), (Rank)random.Next(2, 14)) }); player.display(); players.Add(player); PokerGame pgame = new PokerGame(players, 5); List <Player> winners = pgame.evaluate(); foreach (Player winner in winners) { Console.WriteLine("winner={0}, hand={1}\n", winner.Name, winner.determinePokerHand().pokerHand); } } }
public static void test1() { //game 1 List <Player> players = new List <Player>(); players.Add(new Player("Joe", new List <Card>() { new Card(Suit.S, Rank._8), new Card(Suit.D, Rank._8), new Card(Suit.D, Rank._A), new Card(Suit.D, Rank._Q), new Card(Suit.H, Rank._J) })); players.Add(new Player("Bob", new List <Card>() { new Card(Suit.S, Rank._A), new Card(Suit.S, Rank._Q), new Card(Suit.S, Rank._8), new Card(Suit.S, Rank._6), new Card(Suit.S, Rank._4) })); players.Add(new Player("Sally", new List <Card>() { new Card(Suit.S, Rank._4), new Card(Suit.H, Rank._4), new Card(Suit.H, Rank._3), new Card(Suit.C, Rank._Q), new Card(Suit.C, Rank._8) })); foreach (Player pl in players) { pl.display(); } PokerGame pgame = new PokerGame(players, 5); List <Player> winners = pgame.evaluate(); foreach (Player winner in winners) { Console.WriteLine("winner={0}, hand={1}\n", winner.Name, winner.determinePokerHand().pokerHand); } }
public static void interactiveTest() { bool answer; do { int numbPlayer = 0; bool loop; do { Console.Write("Enter Number of players:"); try { numbPlayer = Convert.ToInt32(Console.ReadLine()); loop = false; } catch { Console.WriteLine("Wrong input please enter number!"); loop = true; } } while (loop); List <Player> players = new List <Player>(); for (int i = 0; i < numbPlayer; i++) { List <Card> cards = new List <Card>(); Console.Write("Enter player{0} name:", i + 1); string name = Console.ReadLine(); string[] cardsArray; do { Console.WriteLine("Enter {0}'s 5 cards separated by spaces(E.g. 5S 2D 3C JS AH):", name); cardsArray = Console.ReadLine().Split(' '); if (cardsArray.Length != 5) { Console.WriteLine("Wrong input please enter number!"); } } while (cardsArray.Length != 5); foreach (var card in cardsArray) { string suit = card[1].ToString().ToUpper(); string rank = "_" + card[0].ToString().ToUpper(); Suit aSuit; Rank aRank; Enum.TryParse(suit, true, out aSuit); Enum.TryParse(rank, true, out aRank); cards.Add(new Card(aSuit, aRank)); } Player player = new Player(name, cards); player.display(); players.Add(player); } PokerGame pgame = new PokerGame(players, 5); List <Player> winners = pgame.evaluate(); foreach (Player winner in winners) { Console.WriteLine("winner={0}, hand={1}", winner.Name, winner.determinePokerHand().pokerHand); } Console.WriteLine("Do you want to play again? (Y/N)"); string temp = Console.ReadLine(); answer = temp.Equals("N") || temp.Equals("n"); } while (!answer); }