Saturday, October 26, 2024

Euchre (Card Game) - Starting the bidding process


The code below starts the bidding process. It's possible now to add graphics, that might be next as well as continuing with picking up. 

Can be tested at https://www.onlinegdb.com/online_python_compiler

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

player_num = random.randint(0,3) #Assigns players a number.
suits = ["clubs", "spades", "diamonds", "hearts"]
trump_order = []
cnums_dealt = []
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♥"]
cards2 = ["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]
cnumscopy = cnums.copy() #This is for second round bidding.
cnums_value = []
cardsnum_dealt = 23


#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])

#Assigning values to each card
if cnums_dealt[20] < 6:  
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be clubs.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 12 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 13 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 14 or cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 15 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 16 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 17 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 0:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 1:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 2:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 3:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 4:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 5:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 12

   suitbid = 5 #filter for clubs in second bid round
   secondsuitbid = 0
    
 #print ("New cnums_dealtcopy", cnums_dealtcopy)
 


if cnums_dealt[20] > 5 and cnums_dealt[20] < 12:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be spades.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 12 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 13 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 14 or cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 15 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 16 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 17 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 6:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 7:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 9:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 10:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 11:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 2:
    cnums_dealtcopy[card_num] = 12

   suitbid = 11 #filter for spades in second bid round
   secondsuitbid = 1

 #print ("New cnums_dealtcopy", cnums_dealtcopy)


 
if cnums_dealt[20] > 11 and cnums_dealt[20] < 18:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be diamonds.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 2 or cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 12:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 13:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 14:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 15:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 16:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 17:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 12

   suitbid = 17 #filter for diamonds in second bid round
   secondsuitbid = 2

 #print ("New cnums_dealtcopy", cnums_dealtcopy)

     
if cnums_dealt[20] > 17 and cnums_dealt[20] < 24:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be hearts.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 12:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 13:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 2 or cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 15:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 16:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 17:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 14:
    cnums_dealtcopy[card_num] = 12

   suitbid = 23 #filter for hearts in second bid round
   secondsuitbid = 3
    
 #print ("New cnums_dealtcopy", cnums_dealtcopy)


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]

player1_bidding_points = cnums_dealtcopy[0]+cnums_dealtcopy[4]+cnums_dealtcopy[8]+cnums_dealtcopy[12]+cnums_dealtcopy[16]
player2_bidding_points = cnums_dealtcopy[1]+cnums_dealtcopy[5]+cnums_dealtcopy[9]+cnums_dealtcopy[13]+cnums_dealtcopy[17]
player3_bidding_points = cnums_dealtcopy[2]+cnums_dealtcopy[6]+cnums_dealtcopy[10]+cnums_dealtcopy[14]+cnums_dealtcopy[18]
player4_bidding_points = cnums_dealtcopy[3]+cnums_dealtcopy[7]+cnums_dealtcopy[11]+cnums_dealtcopy[15]+cnums_dealtcopy[19]

#print("\nPlayer 1: ",player1, "\nbidding points =", player1_bidding_points)
#print("\nPlayer 2: ",player2, "\nbidding points =", player2_bidding_points)
#print("\nPlayer 3: ",player3, "\nbidding points =", player3_bidding_points)
#print("\nPlayer 4: ",player4, "\nbidding points =", player4_bidding_points)
print("You are player", player_num+1, "\n")

#Is there another way to isolate a player's assignment? This makes them part of a list and can be referenced by position in the list.
playerlist = [player1, player2, player3, player4]
print("Your cards are:", playerlist[player_num])

#Passing or Picking up

for playerbid in range (4):
 #print ("player bid = ", playerbid)
 while playerbid+1 != player_num+1:
  print ("Player ",playerbid+1," will pass.")
  break
 if playerbid+1 == player_num+1 and playerbid+1 !=4:
  bidpickup = input("\nWill you pass or tell the dealer to pick up? Type \'skip' to pass or 'pick up'.\n\n")
  if bidpickup == "pick up":
   print("Will be programmed later, using skip for now.")
if player_num+1 == 4:
 dealerbid = input("\nYou are the dealer. Do you want to pick up \nor pass and go to a second round of bidding?\nType \'skip' to pass or 'pick up'.\n\n")

#print ("suit bid# is ", suitbid)
#print ("cnums is", cnumscopy)
for passbidsuit in range (6):
 cnumscopy.pop(cnumscopy[suitbid-passbidsuit])
#print ("cnums filtered is", cnumscopy)


suits.pop(secondsuitbid)

callsuit = "on"
while callsuit == "on":
 bidpasscall = input("\nWill you pass again or call a suit? Type \'skip' or 'call'.\n")   
 if bidpasscall == ("call"):
  print("\nThree suits left are:",suits)
  callbid = input("Choose one of the suits. \n")
  if callbid == suits[0] or callbid == suits[1] or callbid == suits[2]:
   callsuit = "off"
 elif bidpasscall == ("skip"): #Using else doesn't work here.
  print ("\nMore to be programmed later, call a suit for now.")

print("\nTrump will be", callbid)

Monday, September 30, 2024

Euchre (Card Game) - Placing values based on card turned over

The code below places values based on the card turned over. Next will be to add bidding and including dealer's (player 4) advantage taking the card. Can be tested at https://www.online-python.com/

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

import random

trump_order = []
cnums_dealt = []
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♥"]
cards2 = ["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]
cnums_value = []
cardsnum_dealt = 23


#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])

#Assigning values to each card
if cnums_dealt[20] < 6:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be clubs.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 12 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 13 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 14 or cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 15 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 16 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 17 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 0:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 1:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 2:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 3:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 4:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 5:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 12
    
 #print ("New cnums_dealtcopy", cnums_dealtcopy)
 


if cnums_dealt[20] > 5 and cnums_dealt[20] < 12:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be spades.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 12 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 13 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 14 or cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 15 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 16 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 17 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 6:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 7:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 9:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 10:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 11:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 2:
    cnums_dealtcopy[card_num] = 12

 #print ("New cnums_dealtcopy", cnums_dealtcopy)


 
if cnums_dealt[20] > 11 and cnums_dealt[20] < 18:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be diamonds.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 2 or cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 12:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 13:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 14:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 15:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 16:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 17:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 12

 #print ("New cnums_dealtcopy", cnums_dealtcopy)

     
if cnums_dealt[20] > 17 and cnums_dealt[20] < 24:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be hearts.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 12:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 13:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 2 or cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 15:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 16:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 17:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 14:
    cnums_dealtcopy[card_num] = 12
    
 #print ("New cnums_dealtcopy", cnums_dealtcopy)


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]

player1_bidding_points = cnums_dealtcopy[0]+cnums_dealtcopy[4]+cnums_dealtcopy[8]+cnums_dealtcopy[12]+cnums_dealtcopy[16]
player2_bidding_points = cnums_dealtcopy[1]+cnums_dealtcopy[5]+cnums_dealtcopy[9]+cnums_dealtcopy[13]+cnums_dealtcopy[17]
player3_bidding_points = cnums_dealtcopy[2]+cnums_dealtcopy[6]+cnums_dealtcopy[10]+cnums_dealtcopy[14]+cnums_dealtcopy[18]
player4_bidding_points = cnums_dealtcopy[3]+cnums_dealtcopy[7]+cnums_dealtcopy[11]+cnums_dealtcopy[15]+cnums_dealtcopy[19]

print("\n\nPlayer 1: ",player1, "\nbidding points =", player1_bidding_points)
print("\nPlayer 2: ",player2, "\nbidding points =", player2_bidding_points)
print("\nPlayer 3: ",player3, "\nbidding points =", player3_bidding_points)
print("\nPlayer 4: ",player4, "\nbidding points =", player4_bidding_points)

Friday, September 13, 2024

Euchre (Card Game) - Placing values based on card turned over

The code below places values based on the card turned over. Next will be to add bidding and including dealer's (player 4) advantage taking the card. 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 = []
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♥"]
cards2 = ["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]
cnums_value = []
cardsnum_dealt = 23


#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])

#Assigning values to each card
if cnums_dealt[20] < 6:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be clubs.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 12 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 13 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 14 or cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 15 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 16 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 17 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 0:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 1:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 2:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 3:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 4:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 5:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 12
    
 #print ("New cnums_dealtcopy", cnums_dealtcopy)
 


if cnums_dealt[20] > 5 and cnums_dealt[20] < 12:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be spades.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 12 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 13 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 14 or cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 15 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 16 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 17 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 6:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 7:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 9:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 10:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 11:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 2:
    cnums_dealtcopy[card_num] = 12

 #print ("New cnums_dealtcopy", cnums_dealtcopy)


 
if cnums_dealt[20] > 11 and cnums_dealt[20] < 18:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be diamonds.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 2 or cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 12:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 13:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 14:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 15:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 16:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 17:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 12

 #print ("New cnums_dealtcopy", cnums_dealtcopy)

     
if cnums_dealt[20] > 17 and cnums_dealt[20] < 24:
 cnums_dealtcopy = cnums_dealt.copy()
 #print("cnums_dealtcopy:", cnums_dealtcopy)
 #print("Trump could be hearts.")
 for value in range (13):
  for card_num in range (21):
   if cnums_dealt[card_num] == 0 or cnums_dealt[card_num] == 6 or cnums_dealt[card_num] == 12:
    cnums_dealtcopy[card_num] = 1
   if cnums_dealt[card_num] == 1 or cnums_dealt[card_num] == 7 or cnums_dealt[card_num] == 13:
    cnums_dealtcopy[card_num] = 2
   if cnums_dealt[card_num] == 2 or cnums_dealt[card_num] == 8:
    cnums_dealtcopy[card_num] = 3
   if cnums_dealt[card_num] == 3 or cnums_dealt[card_num] == 9 or cnums_dealt[card_num] == 15:
    cnums_dealtcopy[card_num] = 4
   if cnums_dealt[card_num] ==  4 or cnums_dealt[card_num] == 10 or cnums_dealt[card_num] == 16:
    cnums_dealtcopy[card_num] = 5
   if cnums_dealt[card_num] == 5 or cnums_dealt[card_num] == 11 or cnums_dealt[card_num] == 17:
    cnums_dealtcopy[card_num] = 6
    
   if cnums_dealt[card_num] == 18:
    cnums_dealtcopy[card_num] = 7

   if cnums_dealt[card_num] == 19:
    cnums_dealtcopy[card_num] = 8

   if cnums_dealt[card_num] == 20:
    cnums_dealtcopy[card_num] = 13

   if cnums_dealt[card_num] == 21:
    cnums_dealtcopy[card_num] = 9

   if cnums_dealt[card_num] == 22:
    cnums_dealtcopy[card_num] = 10

   if cnums_dealt[card_num] == 23:
    cnums_dealtcopy[card_num] = 11

   if cnums_dealt[card_num] == 14:
    cnums_dealtcopy[card_num] = 12
    
 #print ("New cnums_dealtcopy", cnums_dealtcopy)


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]

player1_bidding_points = cnums_dealtcopy[0]+cnums_dealtcopy[4]+cnums_dealtcopy[8]+cnums_dealtcopy[12]+cnums_dealtcopy[16]
player2_bidding_points = cnums_dealtcopy[1]+cnums_dealtcopy[5]+cnums_dealtcopy[9]+cnums_dealtcopy[13]+cnums_dealtcopy[17]
player3_bidding_points = cnums_dealtcopy[2]+cnums_dealtcopy[6]+cnums_dealtcopy[10]+cnums_dealtcopy[14]+cnums_dealtcopy[18]
player4_bidding_points = cnums_dealtcopy[3]+cnums_dealtcopy[7]+cnums_dealtcopy[11]+cnums_dealtcopy[15]+cnums_dealtcopy[19]

print("\n\nPlayer 1: ",player1, "\nbidding points =", player1_bidding_points)
print("\nPlayer 2: ",player2, "\nbidding points =", player2_bidding_points)
print("\nPlayer 3: ",player3, "\nbidding points =", player3_bidding_points)
print("\nPlayer 4: ",player4, "\nbidding points =", player4_bidding_points)

Thursday, September 12, 2024

Euchre (Card Game) Placing values (using dictionary command)

Below is code to show possible trump with values. The dictionary {} was used, and it nicely lists things without [] brackets. Next will be to actually compare the cards dealt. Either that code will be put back in or something new will replace. 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.)

import random

trump_order = []
cnums_dealt = []
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]
cardsnum_dealt = 23

#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])

#Assigning values to each card
if cnums_dealt[20] < 6:
 print("Trump could be clubs.")
 clubstrump =    {
  "High Trump": "\nTop 3: A♣ J♠ J♣", "High Trump2": "Other trump: 9♣ 10♣ Q♣ K♣",
  "One Point": "\n1 point cards: 9♠ 9♦ 9♥",
  "Two Points": "\n2 point cards: 10♠ 10♦ 10♥",
  "Three Points": "\n3 point cards: J♦ J♥",
  "Four Points": "\n4 point cards: Q♠ Q♦ Q♥",
  "Five Points": "\n5 point cards: K♠ K♦ K♥",
  "Six Points": "\n6 point cards: A♠ A♦ A♥",
}
 print(clubstrump["High Trump"],clubstrump["High Trump2"], clubstrump["One Point"], clubstrump["Two Points"], clubstrump["Three Points"], clubstrump["Four Points"], clubstrump["Five Points"], clubstrump["Six Points"])

if cnums_dealt[20] > 5 and cnums_dealt[20] < 12:
 print("Trump could be spades.")
 spadestrump =    {
  "High Trump": "\nTop 3: A♠ J♣ J♠", "High Trump2": "Other trump: 9♠ 10♠ Q♠ K♠",
  "One Point": "\n1 point cards: 9♣ 9♦ 9♥",
  "Two Points": "\n2 point cards: 10♣ 10♦ 10♥",
  "Three Points": "\n3 point cards: J♦ J♥",
  "Four Points": "\n4 point cards: Q♣ Q♦ Q♥",
  "Five Points": "\n5 point cards: K♣ K♦ K♥",
  "Six Points": "\n6 point cards: A♣ A♦ A♥",
}
 print(spadestrump["High Trump"],spadestrump["High Trump2"], spadestrump["One Point"], spadestrump["Two Points"], spadestrump["Three Points"], spadestrump["Four Points"], spadestrump["Five Points"], spadestrump["Six Points"])
 
if cnums_dealt[20] > 11 and cnums_dealt[20] < 18:
 print("Trump could be diamonds.")
 diamondtrump = {
  "High Trump": "\nTop 3: A♦ J♥ J♦", "High Trump2": "Other trump: 9♦, 10♦, Q♦, K♦",
  "One Point": "\n1 point cards: 9♣ 9♠ 9♥",
  "Two Points": "\n2 point cards: 10♣ 10♠ 10♥",
  "Three Points": "\n3 point cards: J♣ J♠",
  "Four Points": "\n4 point cards: Q♣ Q♠ Q♥",
  "Five Points": "\n5 point cards: K♣ K♠ K♥",
  "Six Points": "\n6 point cards: A♣ A♠ A♥",
}

 print(diamondtrump["High Trump"],diamondtrump["High Trump2"], diamondtrump["One Point"], diamondtrump["Two Points"], diamondtrump["Three Points"], diamondtrump["Four Points"], diamondtrump["Five Points"], diamondtrump["Six Points"])
     
if cnums_dealt[20] > 17 and cnums_dealt[20] < 24:
 print("Trump could be hearts.")
 heartstrump = {
  "High Trump": "\nTop 3: A♥ J♦ J♥", "High Trump2": "Other trump: 9♥, 10♥, Q♥, K♥",
  "One Point": "\n1 point cards: 9♣ 9♠ 9♦",
  "Two Points": "\n2 point cards: 10♣ 10♠ 10♦",
  "Three Points": "\n3 point cards: J♣ J♠",
  "Four Points": "\n4 point cards: Q♣ Q♠ Q♦",
  "Five Points": "\n5 point cards: K♣ K♠ K♦",
  "Six Points": "\n6 point cards: A♣ A♠ A♦",

}
 print(heartstrump["High Trump"], heartstrump["High Trump2"], heartstrump["One Point"], heartstrump["Two Points"], heartstrump["Three Points"], heartstrump["Four Points"], heartstrump["Five Points"], heartstrump["Six Points"])

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)

Saturday, July 27, 2024

Euchre (card game) Strategy Brainstorming

What's a more Michiganian card game than Euchre?

Euchre is a card game using all 9-A cards (24 total). 20 cards are dealt, 5 to each player (4 players), and I have played it by dealing 2, then 3, then 2, then 3, and 3, 2, 3, 2 to get 5. In this project, I am just going to simplify and deal 1 card each. In person, the 3/2 approach speeds it up. Does it matter on computers? The distribution of cards is different, so I will tackle that later. But first, strategy and this will be a to do list of things to add to what I have done so far.


Intro to the game

Player 1 is next to the dealer (player 4) and the first to tell dealer to pick up (aka "calling it", the trump suit) the card turned over (21st card) or pass to player 2. The dealer then discards one of their cards. Player 1 works with player 3 to get three tricks. This earns players 1 and 3 one point. If they get all five, they get two points, and you can "shoot the moon". This means your partner sits out and you play alone. There is also an optional rule where the dealer can shoot the moon which overrides the first person to call it. In either case, 5 points can be given (online I am seeing some weird point variations). I won't be including this, so the first player to tell dealer to pick up determines trump. If 3 tricks are not won by the team calling it, the other team gets two points. In this case, the team that called it and didn't get three tricks is referred to as being "euchred". I think a new rule could be instead to lose 2 points if you want the game to last longer. I might add that later.

Strategy and evaluation are very similar. The difference is how far the human can calculate in a limited time frame. Evaluation before playing? In the chess world, we call that preparation. So, in a way I am doing both strategy and evaluation here, but I am going to stick to simplicity.

The first factor is whether or not you are the dealer and what card is being picked up.

The second is a guideline, where the player calling it tries to get two tricks and relies on their partner to get one.

The third involves a second round of bidding. If no one calls it in the first round, the remaining three suits can be called in the second round. Also, in the second round if players 1-3 don't call it, the dealer has to. This is referred to as "stick the dealer". I will add this, but it will have zero effect on strategy. It won't be used so the opposing team can try to euchre and get two points. Instead, losing two points will probably be put in. This forces both teams to earn the points and not just get points based on a bad deal. If you truly are the better team, you can get those two points back.

Right and left bower (what makes Euchre Euchre). Jack of the suit called is called the right bower. This makes it the highest card, and jack of the other suit of the same color is the left bower, second highest before ace, king, queen, 10, and 9. Jacks of opposite color are treated normally, higher than 10, lower than queen.

Lead with high non-trump cards (in the beginning)/Getting rid of low non-trump cards. This means after trump has been determined, the highest probability players will have a 9 or 10 where you have the ace will be in the beginning. Also, if you don't have an ace, playing a 9 or 10 trump card where you partner called it will allow them to lead and get rid of four trumps or show who doesn't have trump.


Levels

This will be a work in progress, but a few examples should provide a yardstick for comparison.

♠ is trump and J♠ is the card the dealer turned over.
The dealer has been dealt: J♦ Q♥ A♠ 10♠ J♣

This is a guaranteed point for players 2 and 4(dealer), and since the dealer doesn't have a non-trump 9 or 10 they could go alone and shoot the moon. Another way of thinking is that player 2 has high diamonds (Q, K, and A) and high hearts (K and A). This could give two points in case players 1 and 3 also have them. At this stage, I will use a 9/10 approach. If the dealer doesn't have non-trump 9 or 10 cards then shoot the moon. If they have 2, maybe 1 (flip a coin?), then don't shoot the moon. Another factor is the score. If it is near the end of the game and you are down, shooting the moon might be worth it since you won't lose or give points. I won't program this in and just focus on each round independently.

In this next example Player 1 has good reason to call it.

The card the dealer turned over was 9♣.

 Player 1 has:  J♣ Q♦ 9♦ A♣ 10♣
 Player 2 has:  9♥ Q♥ K♦ K♠ A♠
 Player 3 has:  K♥ Q♠ A♦ 10♦ J♥
 Dealer has:  K♣ Q♣ 10♠ 9♠ J♠

Player 1 has two of the top three cards and can rely on their partner for the third trick. Plus, they have an extra trump in case hearts are played which they don't have. The dealer would only get a low 9 for trump. However, they do have left bower and two trump cards.

Game play could go: J♣, 9♥, 10♦, 9♣ (1-0) / 9♦, K♦, A♦, Q♣ (1-1) / J♠, 10♣, K♠, J♥ (1-2) / 10♠, A♣, Q♥, Q♠ (2-2) / Q♦, A♠, K♥, K♣ (2-3) Euchred!!

The 9♦ is to see if their partner has the ace or trump and use it up with 2 more trump in hand to get the point. The irony is if A♣ was played instead, Player 4 (dealer) could take it with left bower and then rely on their partner who has K♠ and A♠ to get the third trick.

Game play with 9♦ first: 9♦, K♦, A♦, 9♣ (0-1) / Q♣, J♣, 9♥, J♥ (1-1) also leads to being euchred.

9♦, K♦, A♦, 9♣ (0-1) / 10♠, 10♣, K♠, J♥ (1-1) / Q♦, 9♥, 10♦, Q♣ (1-2) Not Euchred

If I am correct here, then it all boils down to the fact Player 4 (dealer) had more trump to outnumber Player 1. In chess, this is similar to more knights and bishops (maybe queen) in a position. If players 2 and 3 had trump, player 1 would be able to get at least a point.

In cases like this, I will program it with a flip of the coin. In the beginning, non-trump could be played, but later (3rd trick?) it would play the trump. If that shows human play winning more, another level could be set to calculate it out more by counting cards. I am going to stick to least calculating at first.


Last example:

The card the dealer turned over was 9♠.

 Player 1 has:  K♣ K♠ 9♥ A♥ J♣
 Player 2 has:  9♣ 10♠ 9♦ Q♣ J♠
 Player 3 has:  K♥ Q♦ A♠ Q♠ 10♥
 Dealer has:  K♦ Q♥ A♣ 10♣ J♥

This one is unclear and possibly a "stick the dealer" scenario. With dealer passing, and it coming back, ♥ would probably be called.

Game play could be: K♠, 10♠, Q♠, Q♥ (0-1) / J♥, 9♥, 9♣, 10♥ (0-2) / A♣, A♥, 9♦, Q♦ (1-2) / K♣, Q♣, A♠, 10♣ (2-2) /  J♣, J♠, K♥, K♦ (3-2) Euchred!!

With Players 1 and 3 winning, did 2 and 4 have a better option? Player 2 could have left bower for clubs and player 4 (dealer) has the ace.

Game play could then be: A♥, 9♣, 10♥, J♥ (0-1) / J♠, Q♠, 10♣, J♣ (1-1) / K♠, 10♠, A♠, A♣ (1-2) / K♦, K♣, 9♦, Q♦ (2-2) / 9♥, Q♣, K♥, Q♥ (2-3) Not Euchred

So, how do you know Player 2 has potential? J♣, A♣, and K♣ were not in Player 2's hand. The only thing I can see is Player 2 could get two of three tricks. This seems to be a good factor to put in for initial strategy. Well, off to programming all this and see what breaks.  

Thursday, July 18, 2024

Card Shuffling

In this one, the user sets the number of players and cards per player. Then, it shuffles and lists cards dealt, as well as which cards each player is dealt. In the Clue program, it was suggested I use "random.variable" to simplify things, but I don't see how to isolate the position of each card drawn in the array. So, instead of removing from a set list, I created the array and then listed. I would like to try this again, where each card dealt out is removed from the 52 card list, and instead of listing based on position, it is more real with place holders. To do this, I need to find out how to deal with an indeterminate number of players so I can assign a list/array to each player. Then, it is not needed to base things on position.

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. Also, the site seems to time out, but it's the only one I see that can run this one.)

import random

a=0
card_progress_num = 51
cards = ["Ace of Clubs", "Ace of Diamonds", "Ace of Hearts", "Ace of Spades", "2 of Clubs", "2 of Diamonds", "2 of Hearts", "2 of Spades", "3 of Clubs", "3 of Diamonds", "3 of Hearts", "3 of Spades", "4 of Clubs", "4 of Diamonds", "4 of Hearts", "4 of Spades", "5 of Clubs", "5 of Diamonds", "5 of Hearts", "5 of Spades", "6 of Clubs", "6 of Diamonds", "6 of Hearts", "6 of Spades", "7 of Clubs", "7 of Diamonds", "7 of Hearts", "7 of Spades", "8 of Clubs", "8 of Diamonds", "8 of Hearts", "8 of Spades", "9 of Clubs", "9 of Diamonds", "9 of Hearts", "9 of Spades", "10 of Clubs", "10 of Diamonds", "10 of Hearts", "10 of Spades","Jack of Clubs", "Jack of Diamonds", "Jack of Hearts", "Jack of Spades", "Queen of Clubs", "Queen of Diamonds", "Queen of Hearts", "Queen of Spades", "King of Clubs", "King of Diamonds", "King of Hearts", "King of Spades"]   
player_num = int(input("How many players? "))
card_num = int(input("How many cards per player? "))
cards_dealt_num = player_num * card_num
cards_dealt = []
print ("\n")


while a < (cards_dealt_num):

#random.choice HOW DO YOU ISOLATE THE POSITION OF THE CARD TO REMOVE IT?
#cards = random.choice (("Ace of Clubs", "Ace of Diamonds", "Ace of Hearts", "Ace of Spades", "2 of Clubs", "2 of Diamonds", "2 of Hearts", "2 of Spades", "3 of Clubs", "3 of Diamonds", "3 of Hearts", "3 of Spades", "4 of Clubs", "4 of Diamonds", "4 of Hearts", "4 of Spades", "5 of Clubs", "5 of Diamonds", "5 of Hearts", "5 of Spades", "6 of Clubs", "6 of Diamonds", "6 of Hearts", "6 of Spades", "7 of Clubs", "7 of Diamonds", "7 of Hearts", "7 of Spades", "8 of Clubs", "8 of Diamonds", "8 of Hearts", "8 of Spades", "9 of Clubs", "9 of Diamonds", "9 of Hearts", "9 of Spades", "10 of Clubs", "10 of Diamonds", "10 of Hearts", "10 of Spades","Jack of Clubs", "Jack of Diamonds", "Jack of Hearts", "Jack of Spades", "Queen of Clubs", "Queen of Diamonds", "Queen of Hearts", "Queen of Spades", "King of Clubs", "King of Diamonds", "King of Hearts", "King of Spades"))
#print(cards)
#a = a+1
    card_selection = (random.randint(0,card_progress_num))
    cards_dealt.append(cards[card_selection])
    print (card_selection, " - ", cards[card_selection])
    cards.pop(card_selection)
    card_progress_num = card_progress_num - 1
    a=a+1

print ("\n")

for x in range(player_num):     
    print ("Player ", x+1, "has:")
    for y in range(card_num):
        print (cards_dealt[(x)])
        x=x+player_num
    print ("\n")