Dobble Card Game

Dobble is a simple pattern recognition game in which players try to find an image shown on two cards. Each card in Dobble features eight different symbols, with the symbols varying in size from one card to the next. Any two cards have exactly one symbol in common. 

Coding:

#string contains the constant ascii_letters that has all lowercase and uppercase letters concatenated
import string   
import random       

while(True):
    symbols = []
    symbols = list(string.ascii_letters)   

    card1 = [0]*5                    
    card2 = [0]*5              

    #pos1 and pos2 contains some random integer ranging from 0 to 4
    pos1 = random.randint(0,4)        
    pos2 = random.randint(0,4)

    #select a random symbol from the symbols list
    samesymbol=random.choice(symbols)   
    #remove the randomly selected symbol from the list, so that it is not selected again
    symbols.remove(samesymbol)          

    #one common symbol placed in pos1 & pos2 irrespective of whether pos1 & pos2 are same or          #not
    card1[pos1] = samesymbol           
    card2[pos2] = samesymbol

    i = 0
    #to generate other symbols in card1 & card2
    while(i<5):                        
            #do not to disturb the common symbol placed at pos1 in card1
            if(i!=pos1):    
                    alphabet1=random.choice(symbols)
                    symbols.remove(alphabet1)
                    card1[i]=alphabet1
            #do not to disturb the common symbol placed at pos2 in card2
            if(i!=pos2):    
                    alphabet2=random.choice(symbols)
                    symbols.remove(alphabet2)
                    card2[i]=alphabet2
            i=i+1

    print(card1)
    print(card2)
    ch = input("Ask the user to spot the similar symbol-")
    if (ch==samesymbol):
            print("Right")
    else:
            print("Wrong")

    playagain=input("Wish to play again(Y/N) ")
    if playagain=='N' or playagain=='n':
        print("Thanks for playing")
        break



If you have any doubts, feel free to post it in comment Section.

Comments

Popular posts from this blog

Guessing the Number Game

Find the final amount after Discount

Simple Arithmetic Calculator - User Defined Function