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")
       

 

Friday, June 28, 2024

Clue Game

Here is a one day practice Clue game. It's not multiplayer yet, and I may never add that. Just for practice. 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

guess = "wrong"
progress_array = ["person", "place", "weapon"]
progress_counter = 2
progress_person = "no"
progress_place = "no"
progress_weapon = "no"
firstguess = 2
people = ("Colonel Mustard", "Miss Scarlet", "Mr. Green", "Mrs. Peacock", "Mrs. White", "Professor Plum")
places = ("hall", "lounge", "dining room", "kitchen", "ballroom", "conservatory", "billiard room", "library", "study")
weapons = ("candlestick", "dagger", "revolver", "lead pipe", "wrench", "rope")

people_random = (random.randint(0,5))
places_random = (random.randint(0,8))
weapons_random = (random.randint(0,5))
shuffle = (people [people_random], places [places_random], weapons [weapons_random])

#print (shuffle)

print ("List of people: Colonel Mustard, Miss Scarlet, Mr. Green, Mrs. Peacock, Mrs. White, Professor Plum\n")
print ("List of places: hall, lounge, dining room, kitchen, ballroom, conservatory, billiard room, library, study\n")
print ("List of weapons: candlestick, dagger, revolver, lead pipe, wrench, rope")
print ("---------------------------------------\n")


while guess == ("wrong"):
    
    if progress_person != "yes":
        person_guess = input ("Make your guess of the person: ")
    if progress_place != "yes":
        place_guess = input ("Make your guess of the place: ")
    if progress_weapon != "yes":
        weapon_guess = input ("Make your guess of the weapon: ")

    if progress_counter == 3:    

        if person_guess == (people [people_random]) and progress_person != "yes":
            print ("\nYou got the person right.\n")
            progress_person = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1
            progress_array.pop(firstguess-2)
        if progress_person == "yes":
            firstguess = firstguess - 1
        if place_guess == (places [places_random]) and progress_place != "yes":
            print ("\nYou got the place right.\n")
            progress_place = "yes"
            progress_counter = progress_counter - 1
            progress_array.pop(firstguess-1)
        if progress_place == "yes" and progress_person != "yes":
            firstguess = firstguess - 1
        if weapon_guess == (weapons [weapons_random]) and progress_weapon != "yes":
            print ("\nYou got the weapon right.\n")
            progress_weapon = "yes"
            progress_counter = progress_counter - 1
            progress_array.pop(firstguess)
        if progress_weapon == "yes":
            firstguess = firstguess - 1
    else:

        if person_guess == (people [people_random]) and progress_person != "yes":
            print ("\nYou got the person right.\n")
            progress_person = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1
        if place_guess == (places [places_random]) and progress_place != "yes":
            print ("\nYou got the place right.\n")
            progress_place = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1
        if weapon_guess == (weapons [weapons_random]) and progress_weapon != "yes":
            print ("\nYou got the weapon right.\n")
            progress_weapon = "yes"
            progress_array.pop(progress_counter - 1)
            progress_counter = progress_counter - 1   
        
    if (progress_person == "yes" and progress_place == "yes" and progress_weapon == "yes"):
        print ("\n****YOU SOLVED IT!!!****")
        print (people [people_random], "did it in the", places [places_random], "with a", weapons [weapons_random])
        guess = "solved"
    else:
        tryagain = 2
        print ("Try Again\n")

Saturday, June 22, 2024

Rock Paper Scissors (with adjustments)

I forgot to put the spellchecker conditional back in, and when I did I realized "elif" had to be used. Otherwise, it would skip in the array and end with less results instead of 5.

Repeating the post with the adjustment.

Code 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 load properly.)

First attempt at rock, paper, scissors in Python. I was inspired by this post, https://bsky.app/profile/coding.bsky.social/post/3kq7rtxldn42v (Remove the 3 lines of "stuff" on the left on their site, or it might not run properly.)

 

import random
#import numpy/itertools later (install, run pip, code later)

#a = 1
turnresults = []
choiceplayer = []
scoreplayer = 0
opponentresults = 0
#Do 128 later, 5 for now
while (len(turnresults)<5):
    #for a in range(1, 5):
    #Have to reindent if using for
    choice = input("Enter rock, paper, or scissors: ")
    opponent = (random.randint(1,3))

    if (choice == "rock") and (opponent == 2):
        print("Rock loses to paper \n")
        opponentresults = opponentresults + 1        
    if (choice == "rock") and (opponent == 3):
        print("Rock wins to scissors \n")
        scoreplayer = scoreplayer + 1        
    if (choice == "paper") and (opponent == 1):
        print("Paper wins to rock \n")
        scoreplayer = scoreplayer + 1  
    if (choice == "paper") and (opponent == 3):
        print("Paper loses to scissors \n")
        opponentresults = opponentresults + 1        
    if (choice == "scissors") and (opponent == 1):
        print("Scissors loses to rock \n")
        opponentresults = opponentresults + 1
    if (choice == "scissors") and (opponent == 2):
        print("Scissors wins to paper \n")
        scoreplayer = scoreplayer + 1

    #opponent = str(opponent)
    #choice = str(choice)

    if (choice == "rock" and opponent == 1) or (choice == "paper" and opponent == 2) or (choice == "scissors" and opponent == 3):        
       print("SAME!! Try again. \n")
       #print ("turnresults = ", turnresults)
       #print ("SAME / Turn results = ", turnresults)
    elif (choice != "rock" and choice != "paper" and choice != "scissors"):
       print("Type rock, paper, or scissors (lower case). \n")

    
        
    else:
        choiceplayer.append(choice)
        turnresults.append(opponent)
        #print ("opponent's choices: ", turnresults)
        #print ("your choices: ", choiceplayer)
        #print (turnresults)
        print ("Score: YOU ", scoreplayer, " - THEM ", opponentresults)
        

if (scoreplayer > opponentresults):
    print ("***YOU WIN!!!***")
else:
    print ("***YOU LOSE!!!***")
               
        
    #print (len(turnresults))

    
    #if (choice == "rock" or choice == "paper" or choice == "scissors"):
        #print("choice is: " + choice)
        #opponent = (random.randint(1,3))
        #opponent = str(opponent)
        #turnresults.append(opponent)
        #print (turnresults)
    #else:
        #print("Type \"rock, paper, or scissors:\"")
        #choice = input()
        #turnresults.append(opponent)
        #print (turnresults)
        #a=a+1 #Doesn't work to get 5 turn results




#It doesn't complete 5 successful turn results when the for loop is used
 

 

Friday, June 21, 2024

Rock Paper Scissors

**See 6/22 post for adjustments.**

Code 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.)

First attempt at rock, paper, scissors in Python. I was inspired by this post, https://bsky.app/profile/coding.bsky.social/post/3kq7rtxldn42v

 

import random
#import numpy/itertools later (install, run pip, code later)

#a = 1
turnresults = []
choiceplayer = []
scoreplayer = 0
opponentresults = 0
#Do 128 later, 5 for now
while (len(turnresults)<5):
    #for a in range(1, 5):
    #Have to reindent if using for
    choice = input("Enter rock, paper, or scissors: ")
    opponent = (random.randint(1,3))

    if (choice == "rock") and (opponent == 2):
        print("Rock loses to paper \n")
        opponentresults = opponentresults + 1        
    if (choice == "rock") and (opponent == 3):
        print("Rock wins to scissors \n")
        scoreplayer = scoreplayer + 1        
    if (choice == "paper") and (opponent == 1):
        print("Paper wins to rock \n")
        scoreplayer = scoreplayer + 1  
    if (choice == "paper") and (opponent == 3):
        print("Paper loses to scissors \n")
        opponentresults = opponentresults + 1        
    if (choice == "scissors") and (opponent == 1):
        print("Scissors loses to rock \n")
        opponentresults = opponentresults + 1
    if (choice == "scissors") and (opponent == 2):
        print("Scissors wins to paper \n")
        scoreplayer = scoreplayer + 1

    #opponent = str(opponent)
    #choice = str(choice)

    if (choice == "rock" and opponent == 1) or (choice == "paper" and opponent == 2) or (choice == "scissors" and opponent == 3):        
        print("SAME!! Try again. \n")
        #print ("turnresults = ", turnresults)
        #print ("SAME / Turn results = ", turnresults)
        
    else:
        choiceplayer.append(choice)
        turnresults.append(opponent)
        ##print ("opponent's choices: ", turnresults)
        ##print ("your choices: ", choiceplayer)
        ##print (turnresults)
        print ("Score: YOU ", scoreplayer, " - THEM ", opponentresults)

if (scoreplayer > opponentresults):
    print ("***YOU WIN!!!***")
else:
    print ("***YOU LOSE!!!***")
               
        
    #print (len(turnresults))

    
    #if (choice == "rock" or choice == "paper" or choice == "scissors"):
        #print("choice is: " + choice)
        #opponent = (random.randint(1,3))
        #opponent = str(opponent)
        #turnresults.append(opponent)
        #print (turnresults)
    #else:
        #print("Type \"rock, paper, or scissors:\"")
        #choice = input()
        #turnresults.append(opponent)
        #print (turnresults)
        #a=a+1 #Doesn't work to get 5 turn results




#It doesn't complete 5 successful turn results when the for loop is used

Card Shuffling