Sunday, September 1, 2024

Euchre (Card Game) Evaluating Possible Trump

First Euchre page can be read at:

https://1a2b3c4d5e6f7g8h9i10j11k12l13m14n.blogspot.com/2024/07/

 

Below is code to check if jacks and aces were dealt to all four players. Next, will be to compare each hand to the card turned over. Can be tested at https://www.programiz.com/python-programming/online-compiler/ (Remove the 3 lines of "stuff" on the left on their site, or it might not run properly.)

 

#This is to evaluate dealt cards for all four players.

import random

trump_order = []
cnums_dealt = []
#trump_firstplayer = random.randint(0,3) / to determine who is the dealer and order of bidding
trump_firstplayer = 0
cards = ["9♣", "10♣", "J♣", "Q♣", "K♣", "A♣", "9♠", "10♠", "J♠", "Q♠", "K♠", "A♠", "9♦", "10♦", "J♦", "Q♦", "K♦", "A♦", "9♥", "10♥", "J♥", "Q♥", "K♥", "A♥"]
cnums = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"]
player1 = []
player2 = []
player3 = []
player4 = []
player1_potential = []
player2_potential = []
player3_potential = []
player4_potential = []
cnums_number = 0
cardsnum_dealt = 23
trump_suit = 0
round1 = ["bid"]
round2 = []
round3 = []
round4 = []
round5 = [] #NEED TO ADD 4 OR 5 AND LOOP FOR ROUNDS

#Generating cards dealt out
for x in range (21):
    cards_dealt = (random.randint(0,cardsnum_dealt))
    if len (cnums) == 4:
        cnums_number = cnums[cards_dealt]
    trump_order.append(cards[cards_dealt])
    cnums_dealt.append(cnums[cards_dealt])
    cardsnum_dealt = cardsnum_dealt - 1
    cards.pop(cards_dealt)
    cnums.pop(cards_dealt)
print ("trump order ", trump_order)
print ("cnums_dealt ", cnums_dealt)
print ("\nThe card the dealer turned over was", trump_order[20])

#Assgning cards to each hand
player1 = trump_order[0], trump_order[4], trump_order[8], trump_order[12], trump_order[16]
player2 = trump_order[1], trump_order[5], trump_order[9], trump_order[13], trump_order[17]
player3 = trump_order[2], trump_order[6], trump_order[10], trump_order[14], trump_order[18]
player4 = trump_order[3], trump_order[7], trump_order[11], trump_order[15], trump_order[19]


#Corresponding card assignment to numbers
player1_potential = int(cnums_dealt[0]), int(cnums_dealt[4]), int(cnums_dealt[8]), int(cnums_dealt[12]), int(cnums_dealt[16])
player2_potential = int(cnums_dealt[1]), int(cnums_dealt[5]), int(cnums_dealt[9]), int(cnums_dealt[13]), int(cnums_dealt[17])
player3_potential = int(cnums_dealt[2]), int(cnums_dealt[6]), int(cnums_dealt[10]), int(cnums_dealt[14]), int(cnums_dealt[18])
player4_potential = int(cnums_dealt[3]), int(cnums_dealt[7]), int(cnums_dealt[11]), int(cnums_dealt[15]), int(cnums_dealt[19])


#cjackace = ["2", "5", "8", "11", "14", "17", "20", "23"]
cjackace = [2, 5, 8, 11, 14, 17, 20, 23]
cjackace_pop1 = [2, 5, 8, 11, 14, 17, 20, 23]
player1card = [cnums_dealt[0], cnums_dealt[4], cnums_dealt[8], cnums_dealt[12], cnums_dealt[16]]
player2card = [cnums_dealt[1], cnums_dealt[5], cnums_dealt[9], cnums_dealt[13], cnums_dealt[17]]
player3card = [cnums_dealt[2], cnums_dealt[6], cnums_dealt[10], cnums_dealt[14], cnums_dealt[18]]
player4card = [cnums_dealt[3], cnums_dealt[7], cnums_dealt[11], cnums_dealt[15], cnums_dealt[19]]

print ("player 1: ", player1, " - player 1 potential: ", player1_potential)
print ("player 2: ", player2, " - player 2 potential: ", player2_potential)
print ("player 3: ", player3, " - player 3 potential: ", player3_potential)
print ("player 4: ", player4, " - player 4 potential: ", player4_potential)

#Evaluating each hand

print ("\n\n")

player1_potential_results = [] ##If in loops, it will reset each time##
player2_potential_results = []
player3_potential_results = []
player4_potential_results = []

for count_topcards in range (4):
    for all_cards in range (20):##If 1t is 19, it won't indicate if the fifth card in player 4's hand is trump##
        player1_check = player1card[count_topcards]
        player2_check = player2card[count_topcards]
        player3_check = player3card[count_topcards]
        player4_check = player4card[count_topcards]
        cnums_get = cnums_dealt[all_cards]
        cnums_get = int(cnums_get)
        if cnums_get == cjackace [0] or cnums_get == cjackace [1] or cnums_get == cjackace [2] or cnums_get == cjackace [3] or cnums_get == cjackace [4] or cnums_get == cjackace [5] or cnums_get == cjackace [6] or cnums_get == cjackace [7]:            
           if cnums_get == player1_potential [0] or cnums_get == player1_potential [1] or cnums_get == player1_potential [2] or cnums_get == player1_potential [3] or cnums_get == player1_potential [4]:                   
             if trump_order[all_cards] not in player1_potential_results:
              player1_potential_results.append(trump_order[all_cards])
              
           if cnums_get == cjackace [0] or cnums_get == cjackace [1] or cnums_get == cjackace [2] or cnums_get == cjackace [3] or cnums_get == cjackace [4] or cnums_get == cjackace [5] or cnums_get == cjackace [6] or cnums_get == cjackace [7]:            
            if cnums_get == player2_potential [0] or cnums_get == player2_potential [1] or cnums_get == player2_potential [2] or cnums_get == player2_potential [3] or cnums_get == player2_potential [4]:                   
              if trump_order[all_cards] not in player2_potential_results:
               player2_potential_results.append(trump_order[all_cards])
                    
            if cnums_get == cjackace [0] or cnums_get == cjackace [1] or cnums_get == cjackace [2] or cnums_get == cjackace [3] or cnums_get == cjackace [4] or cnums_get == cjackace [5] or cnums_get == cjackace [6] or cnums_get == cjackace [7]:            
             if cnums_get == player3_potential [0] or cnums_get == player3_potential [1] or cnums_get == player3_potential [2] or cnums_get == player3_potential [3] or cnums_get == player3_potential [4]:                   
              if trump_order[all_cards] not in player3_potential_results:
               player3_potential_results.append(trump_order[all_cards])
                    
            if cnums_get == cjackace [0] or cnums_get == cjackace [1] or cnums_get == cjackace [2] or cnums_get == cjackace [3] or cnums_get == cjackace [4] or cnums_get == cjackace [5] or cnums_get == cjackace [6] or cnums_get == cjackace [7]:            
             if cnums_get == player4_potential [0] or cnums_get == player4_potential [1] or cnums_get == player4_potential [2] or cnums_get == player4_potential [3] or cnums_get == player4_potential [4]:                   
              if trump_order[all_cards] not in player4_potential_results:
               player4_potential_results.append(trump_order[all_cards])
 

if len(player1_potential_results) == 0:
 print("Player 1 has no possible top trump cards.")
else:
 print ("Player 1 has possible trump!! The cards are:", player1_potential_results)
if len(player2_potential_results) == 0:
 print("Player 2 has no possible top trump cards.")
else:
 print ("Player 2 has possible trump!! The cards are:", player2_potential_results)
if len(player3_potential_results) == 0:
 print("Player 3 has no possible top trump cards.")
else:
 print ("Player 3 has possible trump!! The cards are:", player3_potential_results)
if len(player4_potential_results) == 0:
 print("Player 4 has no possible top trump cards.")
else:
 print ("Player 4 has possible trump!! The cards are:", player4_potential_results)

No comments:

Post a Comment