public static int compareHands(HandEvaluator evaluator1, HandEvaluator evaluator2) { // Returns 1 if player with cards1 has better cards // Returns 2 if player with cards2 has better cards // Returns 3 if the players have same power cards int[] hand1Points = evaluator1.returnResultAsInt(); int[] hand2Points = evaluator2.returnResultAsInt(); for (int i = 0; i < hand1Points.Length; i++) { if (hand1Points[i] > hand2Points[i]) { return(1); } else if (hand1Points[i] < hand2Points[i]) { return(2); } else { continue; } } return(3); }
public void evaluateHands() { //create player's and computer's evaluation objects;(podavame podredenata ryka na konstructora) HandEvaluator playerHandEvaluator = new HandEvaluator(sortedPlayerHand); HandEvaluator computerHandEvaluator = new HandEvaluator(sortedComputerHand); //get the player and computer hands Hand playerHand = playerHandEvaluator.EvaluateHand(); Hand computerHand = computerHandEvaluator.EvaluateHand(); //display the hands Console.WriteLine("\n\n\n\n\n"); Console.WriteLine("Your hand: " + playerHand); Console.WriteLine("\n"); Console.WriteLine("Computer's hand: " + computerHand); //pokazva pobeditelq if (playerHand > computerHand) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("YOU WIN!!!"); } else if (computerHand > playerHand) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("COMPUTER WINS."); } else //ako rycete sa ednakvi { //pyrvo proverqva ako imat ednakvi kombinacii if (playerHandEvaluator.Handvalues.Total > computerHandEvaluator.Handvalues.Total) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("YOU WIN!!!"); } else if (playerHandEvaluator.Handvalues.Total < computerHandEvaluator.Handvalues.Total) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("COMPUTER WINS."); } //ako i se stigne do visoka karta else if (playerHandEvaluator.Handvalues.HighCard > computerHandEvaluator.Handvalues.HighCard) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("YOU WIN!!!"); } else if (playerHandEvaluator.Handvalues.HighCard < computerHandEvaluator.Handvalues.HighCard) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("COMPUTER WINS."); } else { Console.WriteLine("DRAW! No one wins."); } } Console.ForegroundColor = ConsoleColor.White; }
public void EvaluateHands() { //create player's and computer's evaluation object(passing Sorted Hand to Constructor) HandEvaluator playerHandEval = new HandEvaluator(sortedPlayerHand); HandEvaluator computerHandEval = new HandEvaluator(sortedComputerHand); //get the players and computers hand Hand playerHand = playerHandEval.EvaluateHand(); Hand computerHand = computerHandEval.EvaluateHand(); //display each hand Console.WriteLine("\n\n\n\n\nPlayer's Hand: " + playerHand); Console.WriteLine("\nComputer's Hand: " + computerHand); //evalue hands if (playerHand > computerHand) { Console.WriteLine("Player WINS"); } else if (playerHand < computerHand) { Console.WriteLine("Computer WINS!"); } else // if hands are the same eval the values { if (playerHandEval.HandValues.Total > computerHandEval.HandValues.Total) { Console.WriteLine("Player WINS!"); } else if (playerHandEval.HandValues.Total < computerHandEval.HandValues.Total) { Console.WriteLine("Computer WINS!"); } else if (playerHandEval.HandValues.HightCard > computerHandEval.HandValues.HightCard) { Console.WriteLine("Player WINS!"); } else if (playerHandEval.HandValues.HightCard < computerHandEval.HandValues.HightCard) { Console.WriteLine("Computer WINS!"); } else { Console.WriteLine("DRAW!"); } } }
public void evaluateCards() { HandEvaluator firstPlayerHandEvaluator = new HandEvaluator(sortedFirstPlayerHand); HandEvaluator secondPlayerHandEvaluator = new HandEvaluator(sortedSecondPlayerHand); Hand firstPlayerHand = firstPlayerHandEvaluator.EvaluateHand(); Hand secondPlayerHand = secondPlayerHandEvaluator.EvaluateHand(); Console.WriteLine("\nFirst Player Hand: " + firstPlayerHand); Console.WriteLine("\nSecond Player Hand: " + secondPlayerHand); if (firstPlayerHand > secondPlayerHand) { Console.WriteLine("\n--------------------"); Console.WriteLine("\nFirst player WINS!"); Console.WriteLine("\n--------------------"); } else if (firstPlayerHand < secondPlayerHand) { Console.WriteLine("\n--------------------"); Console.WriteLine("\nSecond player WINS!"); Console.WriteLine("\n--------------------"); } else { if (firstPlayerHandEvaluator.HandValues.Total > secondPlayerHandEvaluator.HandValues.Total) { Console.WriteLine("\n-------------------- \nFirst player WINS! \n--------------------"); } else if (firstPlayerHandEvaluator.HandValues.Total < secondPlayerHandEvaluator.HandValues.Total) { Console.WriteLine("\n-------------------- \nSecond player WINS! \n--------------------"); } else if (firstPlayerHandEvaluator.HandValues.HighCard > secondPlayerHandEvaluator.HandValues.HighCard) { Console.WriteLine("\n-------------------- \nFirst player WINS! \n--------------------"); } else if (firstPlayerHandEvaluator.HandValues.HighCard < secondPlayerHandEvaluator.HandValues.HighCard) { Console.WriteLine("\n-------------------- \nSecond player WINS! \n--------------------"); } else { Console.WriteLine("\n-------------------- \nTIE! \n--------------------"); } } }
public void resetState() { removeCards(); evaluator = new HandEvaluator(); evaluatorString = new HandEvaluator(); }
public Player() { evaluator = new HandEvaluator(); evaluatorString = new HandEvaluator(); }
public void EvaluateHands() { //evaluate each players hand pre flop HandEvaluator firstPlayerHandEvaluator = new HandEvaluator(FirstPlayerHand); HandEvaluator firstComputerHandEvaluator = new HandEvaluator(FirstComputerHand); //get each players high card value Hand playerHighCard = firstPlayerHandEvaluator.EvaluateHand(); Hand computerHighCard = firstComputerHandEvaluator.EvaluateHand(); //create player's computer's evaluation objects (passing SORTED hand to constructor) HandEvaluator playerHandEvaluator = new HandEvaluator(SortedPlayerHand); HandEvaluator computerHandEvaluator = new HandEvaluator(SortedComputerHand); //get the player's and computer's hand Hand playerHand = playerHandEvaluator.EvaluateHand(); Hand computerHand = computerHandEvaluator.EvaluateHand(); //display each hand Console.WriteLine("\n\n\n\n\n\n\n\nPlayer's Hand: " + playerHand); Console.WriteLine("\nComputer's Hand: " + computerHand); //evaluate hands if (playerHand > computerHand) { Console.WriteLine("Player WINS!"); } else if (playerHand < computerHand) { Console.WriteLine("Computer WINS!"); } else //if the hands are the same, evaluate the values { //first evaluate who has higher value of poker hand if (playerHandEvaluator.HandValues.Total > computerHandEvaluator.HandValues.Total) { Console.WriteLine("Player WINS!"); } else if (playerHandEvaluator.HandValues.Total < computerHandEvaluator.HandValues.Total) { Console.WriteLine("Computer WINS!"); } //if both have the same poker hand (for example, both have a pair of queens), //then the player with the next higher card wins else if (firstPlayerHandEvaluator.HandValues.HighCard > firstComputerHandEvaluator.HandValues.HighCard) { Console.WriteLine("Player WINS!"); } else if (firstPlayerHandEvaluator.HandValues.HighCard < firstComputerHandEvaluator.HandValues.HighCard) { Console.WriteLine("Computer WINS!"); } //if high card is of same value check second card in players hand else if (firstPlayerHandEvaluator.HandValues.SecondHighCard > firstComputerHandEvaluator.HandValues.SecondHighCard) { Console.WriteLine("Player WINS!"); } else if (firstPlayerHandEvaluator.HandValues.SecondHighCard < firstComputerHandEvaluator.HandValues.SecondHighCard) { Console.WriteLine("Computer WINS!"); } else { Console.WriteLine("DRAW, everyone's a winner!"); } } }
public void EvaluateHands() { //create each players hand evaluator object pre flop (to establish each players high cards) HandEvaluator firstPlayerHandEvaluator = new HandEvaluator(FirstPlayerHand); HandEvaluator firstComputerHandEvaluator = new HandEvaluator(FirstComputerHand); //create player and cpu evaluation objects (passing SORTED hand to constructor) HandEvaluator playerHandEvaluator = new HandEvaluator(SortedPlayerHand); HandEvaluator computerHandEvaluator = new HandEvaluator(SortedComputerHand); //evaluate the player's and computer's hand Hand playerHand = playerHandEvaluator.EvaluateHand(); Hand computerHand = computerHandEvaluator.EvaluateHand(); //assign to public variable to send to model winningPlayerHand = playerHand; winningCpuHand = computerHand; //evaluate hands if (playerHand > computerHand) { result = 1; } else if (playerHand < computerHand) { result = 0; } else //if the hands are the same, evaluate the values { //first evaluate who has higher value of poker hand if (playerHandEvaluator.HandValues.Total > computerHandEvaluator.HandValues.Total) { result = 1; } else if (playerHandEvaluator.HandValues.Total < computerHandEvaluator.HandValues.Total) { result = 0; } //if both have the same poker hand (for example, both have a pair of queens), //then the player with the next higher card wins else if (firstPlayerHandEvaluator.HighCard > firstComputerHandEvaluator.HighCard) { result = 1; } else if (firstPlayerHandEvaluator.HighCard < firstComputerHandEvaluator.HighCard) { result = 0; //if high card is of same value check second card in players hand } else if (firstPlayerHandEvaluator.SecondHighCard > firstComputerHandEvaluator.SecondHighCard) { result = 1; } else if (firstPlayerHandEvaluator.SecondHighCard < firstComputerHandEvaluator.SecondHighCard) { result = 0; } else { result = 2; } } }