Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 3: Determining if you have a winning hand Our goal is to determine the odds of winning for your starting hand. We will be

image text in transcribed

image text in transcribedimage text in transcribed

Part 3: Determining if you have a winning hand

Our goal is to determine the odds of winning for your starting hand. We will be calling a game the dealing of the opponent cards and the dealer cards, i.e., a total of 7 random cards. For each game, you will determine if your hand wins the game, if another player wins, or if there is a tie.

The setup code will generate the variables needed for one game:

  • your starting hand (starting_hand) following the "RankSuit" format;
  • the starting hand of the other players (players_cards), the 2d numpy array returned from the function generatePlayersCards;
  • the 5 community cards (dealer_cards), the 1d numpy array returned from the function generateDealerCards.

For each game, you will cycle through all the other players hands and if you lose to any one of them, your starting hand loses. If you win against all of them, your starting hand wins. If you tie against some of them and win against the others, that is a tie.

Your code snippet should define the function whoWin that takes as arguments the numpy arrays start_cards, players_cards and dealer_cards and returns a 1d numpy array game_result = [win,lose,tie] such that:

  • game_result = [1,0,0]: starting hand wins
  • game_result = [0,1,0]: another player wins
  • game_result = [0,0,1]: starting hand ties with another player

Note that you will need to use the function cardNameToInt from Part 1 to convert the given starting_hand to start_cards.

def whoWin(start_cards, players_cards, dealer_cards): # ... return game_result 

To help you determine the best hand that wins a game, we provide you with the function compareTwoPlayers that takes the cards of two different players and the community cards, and gives you who has the best hand. The function is defined as:

def compareTwoPlayers(player1_cards,player2_cards,dealer_cards): # player1_cards and player2_cards: 1d numpy array of shape (2,) # dealer_cards: 1d numpy array of shape (5,) # do things here... # Return 0 if player1 cards are better # Return 1 if player2 cards are better # Return 2 if equal 

The setup code defines the following variable(s) and/or function(s):

Name Type Description
starting_hand list list of two strings representing your starting hand
players_cards 2d ndarray an array of integers representing the starting hands of all other players
dealer_cards 1d ndarray an array of integers representing the community cards dealt
compareTwoPlayers function a function that compares two players hands
cardNameToInt function function that takes a string representing a card using 'RankSuit' format and returns an integer from 0-51

Your code snippet should define the following variable(s) and/or function(s):

Name Type Description
whoWin function A function that returns a 1d numpy array that indicates whether your hand has won, lost or tied
game_result 1d ndarray An array that indicates whether your hand has won, lost or tied

I have part one but I need help with part two and three coding in python please

Part 1: Card conversion Let's start by familiarizing ourselves with the deck. Each card has a Rank and a Suit. The ranks are in the following order given from lowest to highest: 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A where the T represents the number 10. There are 4 suits per rank: Clubs ("c"), Diamonds ("d"), Hearts ("h"), and Spade ("s"). We will deal you a starting hand given in the python variable starting_hand as a list of two strings. The strings represent the cards in your hand and are in the format "RankSuit". For example, assuming the hand dealt to you is the ten of hearts and five of diamonds, your starting hand will look like the following: starting_hand = ['Th', '5d'] To make things easier, the first thing we would like you to do is to define the function cardNameToInt that converts a card from the "RankSuit" format (for example, 'As') into an integer from 0-51 representing the card. For the purposes of this conversion (and not in the actual game) we order the suits from lowest to highest in the following way: "c", "d", "h", "s". The mapping from string to integer should follow the overall ranking of the card with O being the lowest ranked card, "2c", and 51 being the highest ranked card, "As". The cards should be first ordered by the rank, and then by the suit, so that all suits of a rank are enumerated before the next rank. In other words the order should follow: "2c" > array([ 6, 7, 9, 20, 23, 25, 29, 31, 33, 35, 38, 43, 44, 46]) players_cards >> array([[45, 4],[36, 2],[37, 47]]) Here is one example of the use of the fuction generatePlayersCards (remember the cards are drawn at random, so another evaluation of the code snippet below will likely result different output): available_deck np.array([ 2, 4, 6, 7, 9, 20, 23, 25, 29, 31, 33, 35, 36, 37, 38, 43, 44, 4 players_cards, updated_card_deck = generatePlayersCards (3, available_deck) updated_card_deck >> array([ 6, 7, 9, 20, 23, 25, 29, 31, 33, 35, 38, 43, 44, 46]) players_cards >> array([[45, 4],[36, 2],[37, 47]]) Write the function generateDealercards that takes as argument a 1d numpy array representing the available deck of cards. This function returns a 1d numpy array with the 5 community cards and a 1d numpy array with the remaining cards in the deck. def generateDealerCards (available_deck): # do things here return(dealer_cards, updated_card_deck) Your code snippet should define the following function(s): Name Type generatePlayersCards function function Description generate initial hands for opponents generate community cards (dealer hand) generateDealerCards user_code.py 1 import numpy as np Part 1: Card conversion Let's start by familiarizing ourselves with the deck. Each card has a Rank and a Suit. The ranks are in the following order given from lowest to highest: 2, 3, 4, 5, 6, 7, 8, 9, T, J, Q, K, A where the T represents the number 10. There are 4 suits per rank: Clubs ("c"), Diamonds ("d"), Hearts ("h"), and Spade ("s"). We will deal you a starting hand given in the python variable starting_hand as a list of two strings. The strings represent the cards in your hand and are in the format "RankSuit". For example, assuming the hand dealt to you is the ten of hearts and five of diamonds, your starting hand will look like the following: starting_hand = ['Th', '5d'] To make things easier, the first thing we would like you to do is to define the function cardNameToInt that converts a card from the "RankSuit" format (for example, 'As') into an integer from 0-51 representing the card. For the purposes of this conversion (and not in the actual game) we order the suits from lowest to highest in the following way: "c", "d", "h", "s". The mapping from string to integer should follow the overall ranking of the card with O being the lowest ranked card, "2c", and 51 being the highest ranked card, "As". The cards should be first ordered by the rank, and then by the suit, so that all suits of a rank are enumerated before the next rank. In other words the order should follow: "2c" > array([ 6, 7, 9, 20, 23, 25, 29, 31, 33, 35, 38, 43, 44, 46]) players_cards >> array([[45, 4],[36, 2],[37, 47]]) Here is one example of the use of the fuction generatePlayersCards (remember the cards are drawn at random, so another evaluation of the code snippet below will likely result different output): available_deck np.array([ 2, 4, 6, 7, 9, 20, 23, 25, 29, 31, 33, 35, 36, 37, 38, 43, 44, 4 players_cards, updated_card_deck = generatePlayersCards (3, available_deck) updated_card_deck >> array([ 6, 7, 9, 20, 23, 25, 29, 31, 33, 35, 38, 43, 44, 46]) players_cards >> array([[45, 4],[36, 2],[37, 47]]) Write the function generateDealercards that takes as argument a 1d numpy array representing the available deck of cards. This function returns a 1d numpy array with the 5 community cards and a 1d numpy array with the remaining cards in the deck. def generateDealerCards (available_deck): # do things here return(dealer_cards, updated_card_deck) Your code snippet should define the following function(s): Name Type generatePlayersCards function function Description generate initial hands for opponents generate community cards (dealer hand) generateDealerCards user_code.py 1 import numpy as np

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions