private static int strongestHand(Player currPlayer) { //Iterates through every card from the players hand and marks which cards the player has foreach (string card in currPlayer.pokerHand) { if (ReadCheckHand.readCard(currPlayer, card)) { return(0); } } //Iterates through every card from the community cards and marks which cards the player has foreach (string card in currPlayer.tableHand) { if (ReadCheckHand.readCard(currPlayer, card)) { return(-1); } } //Finds all poker hands the player has ReadCheckHand.checkHand(currPlayer); //Gives a weight to determine the strength of a poker hand. Based on the poker hand and the highest value for that hand. //E.g. A pair 8 will have a weight of 36. -> (140 - 14*8 + 8). //The weight decreases by 14 to prevent a weaker poker hand from having a higher value then a stronger poker hand //E.g. A pair of Aces has a weight of 42(140 - 14*8 + 14), while 2 pairs of 2's is 44(140 - 14*7 + 2). int weight = 140; foreach (KeyValuePair <string, int> hand in currPlayer.handTable) { if (hand.Value > 0) { currPlayer.strongestHandWeight = hand.Value + weight; return(hand.Value + weight); } weight -= 14; } return(weight); }
//Call this method with the parameter being the input with all cards and players as a string in the proper format. //Will return a list of winners as a string[]. If there's an error, it will return the error message as a string[] at position [0]. public static string[] findPokerWinner(string input) { string[] read = InputOutput.readInput(input); List <String> winnersList = new List <String>(); if (read.Length != 1) { List <Player> players = ReadCheckHand.createPlayerList(read); winnersList = InputOutput.callAddOn(players); int index = 0; read = new string[winnersList.Count]; foreach (string player in winnersList) { read[index++] = player; } if (printResults) { foreach (Player person in players) { TestMethods.printPlayerTables(person); } } } return(read); }