Sunday 31 May 2015

One-Time Pad Cipher | Python 3.4.3

The One-Time Pad Cipher is a very popular cipher as it is nearly impossible to break. It would take thousands of years and is therefore "practically" unbreakable, as oppose to "completely" unbreakable, as we will be long dead before our information is leaked.

The One-Time Pad works just like the previous cipher that I coded into python, in that it uses a sequence of numbers that both person_1 and person_2 know. However the difference with this cipher is that every single time it is called upon, it will generate a completely random, non-repeating, list of numbers that is the same length as the amount of characters in the secret message to be transmitted.

With no sequence by which to detect, computers will find it impossible to find any kind of frequency fingerprint in the encrypted message, and therefore can only brute-force that message open, which would take decades to centuries. (As you may notice, the code required for this cipher is almost twice of that required for the previous two)

I will be creating code soon on how to break some of the ciphers I have written, and along with more projects both cipher and non-cipher related!

Download link for my One-Time Pad Cipher in python 3.4.3 is here, feel free to ask any questions and I will endeavour to get back to you as soon as possible, as per:

http://tinyurl.com/ocb9axc

And here is the python 3.4.3 code in plain text for you:

import math
import time
import random

encrypt_letter_to_num = {"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,"l":11,"m":12,"n":13,"o":14,"p":15,"q":16,"r":17,"s":18,"t":19,"u":20,"v":21,"w":22,"x":23,"y":24,"z":25,"'":26,",":27,".":28,"?":29,"/":30," ":31}
encrypt_num_to_letter = {0:"a",1:"b",2:"c",3:"d",4:"e",5:"f",6:"g",7:"h",8:"i",9:"j",10:"k",11:"l",12:"m",13:"n",14:"o",15:"p",16:"q",17:"r",18:"s",19:"t",20:"u",21:"v",22:"w",23:"x",24:"y",25:"z",26:"'",27:",",28:".",29:"?",30:"/",31:" "}

while True:
    en_de = ""
    en_de = input("Would you like to encrypt a message or decrypt a message?[e/d]: ").lower()
   
    if en_de == "e":
        main_body = (input("Please input your message, all cases will be changed to lower: ")).lower()
        new_word = ""

        displacement_list = []
        for x in range(len(main_body)):
            displacement_list.append(random.randint(0,31))                          

        displacement_list_position_count = 0
       
        for x in main_body:
            if displacement_list_position_count == len(displacement_list):
                displacement_list_position_count = 0
            old_value = encrypt_letter_to_num[x]
            new_value = old_value + displacement_list[displacement_list_position_count]
            while new_value > 31:
                new_value -= 32
            new_word += encrypt_num_to_letter[new_value]
            displacement_list_position_count += 1

        print("Your encrypted word is: ")
        print("")
        print("")
        print(new_word)
        print("")
        print("")

        print("Your displacement pass is: ")
        print("")
        print("")
        for x in displacement_list:
            if len(str(x)) == 2:
                print (x,end="")
            if len(str(x)) == 1:
                print ("0" + str(x),end="")
        print("")
        print("")
        print("")
       

    if en_de == "d":
        displacement_pass = input("Please enter your displacement pass: ")
        print("")
        print("")
        main_body = (input("Please input your message, all cases will be changed to lower: ")).lower()
        print("")
        print("")

        new_word = ""

        split_count_start = 0
        split_count_finish = 2
        displacement_list = [displacement_pass[i:i+2] for i in range(0, len(displacement_pass), 2)]
        displacement_list = [int(i) for i in displacement_list]
                                   

        displacement_list_position_count = 0
       
        for x in main_body:
            if displacement_list_position_count == len(displacement_list):
                displacement_list_position_count = 0
            old_value = encrypt_letter_to_num[x]
            new_value = old_value - displacement_list[displacement_list_position_count]
            while new_value < 0:
                new_value += 32
            new_word += encrypt_num_to_letter[new_value]
            displacement_list_position_count += 1

        print("Your message translates as: ")
        print("")
        print("")
        print(new_word)
        print("")
        print("")

Sunday 24 May 2015

Polyalphabetic Cipher | Python 3.4.3

The next big changes in cipher development came around with the idea of a Polyalphabetic Cipher.

This type of cipher is much like the previous cipher I interpreted in python, in that letters are moved along the the alphabet a set amount of times that is defined be a pre-set number that both person_1(the sender) and person_2 know.

However instead of a single displacement number to move every character along by in the alphabet, this cipher uses a displacement word to define how many moves a character makes along the alphabet.

For example: If my displacement word where "abcd" then we would take the position of each letter in our displacement word (a=0,b=1,c=2,d=3), and we would apply the first displacement to the first letter of our secret message, then the second displacement to the second letter and so on, until we have gone through every displacement that was generated from our displacement word's characters, at which point we go back to the start of our displacement word and run through it over and over again UNTIL, our secret message is fully encrypted. At which point we send the message to person_2 who can decipher the word, as they know the displacement word too!

This method is called Polyalphabetical due to the fact that "poly" means many in Latin, so we have many different letters to encrypt out message.

The link to the python 3.4.3 code is here, and as always, feel free to ask any questions to me and I will be sure to answer them as soon as I can.

.py in 3.4.3: http://tinyurl.com/kza5r7n

Full code in plain text is below:

import math
import time
import random

encrypt_letter_to_num = {"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,"l":11,"m":12,"n":13,"o":14,"p":15,"q":16,"r":17,"s":18,"t":19,"u":20,"v":21,"w":22,"x":23,"y":24,"z":25,"'":26,",":27,".":28,"?":29,"/":30," ":31}
encrypt_num_to_letter = {0:"a",1:"b",2:"c",3:"d",4:"e",5:"f",6:"g",7:"h",8:"i",9:"j",10:"k",11:"l",12:"m",13:"n",14:"o",15:"p",16:"q",17:"r",18:"s",19:"t",20:"u",21:"v",22:"w",23:"x",24:"y",25:"z",26:"'",27:",",28:".",29:"?",30:"/",31:" "}

while True:
    en_de = ""
    en_de = input("Would you like to encrypt a message or decrypt a message?[e/d]: ").lower()
 
    if en_de == "e":
        displacement_word = input("Please enter your displacement word: ")
        main_body = (input("Please input your message, all cases will be changed to lower: ")).lower()

        new_word = ""

        displacement_list = []
        for x in displacement_word:
            displacement_list.append(encrypt_letter_to_num[x])

        displacement_list_position_count = 0
     
        for x in main_body:
            if displacement_list_position_count == len(displacement_list):
                displacement_list_position_count = 0
            old_value = encrypt_letter_to_num[x]
            new_value = old_value + displacement_list[displacement_list_position_count]
            while new_value > 31:
                new_value -= 32
            new_word += encrypt_num_to_letter[new_value]
            displacement_list_position_count += 1

        print(new_word)



    if en_de == "d":
        displacement_word = input("Please enter your displacement word: ")
        main_body = (input("Please input your message, all cases will be changed to lower: ")).lower()

        new_word = ""

        displacement_list = []
        for x in displacement_word:
            displacement_list.append(encrypt_letter_to_num[x])

        displacement_list_position_count = 0
     
        for x in main_body:
            if displacement_list_position_count == len(displacement_list):
                displacement_list_position_count = 0
            old_value = encrypt_letter_to_num[x]
            new_value = old_value - displacement_list[displacement_list_position_count]
            while new_value < 0:
                new_value += 32
            new_word += encrypt_num_to_letter[new_value]
            displacement_list_position_count += 1

        print(new_word)

Sunday 17 May 2015

Caesar Cipher | Python 3.4.3

I've been looking into basic ciphers and cryptography lately and thought I would try to code some of them in python 3.4.3.

So here we have the Caesar Cipher, one of the earliest ciphers which we know for sure was used for keeping messages secret. It is a simple concept with person_1 writing a message they want to deliver to person_2, person_1 picking a random number (I have called this the displacement number), adding that number to the values of each letter in their message to person_2 to generate a new number (e.g. a=0, b=1 --> displacement_number = 3 --> a=0+3, b=1+3 --> a=3=c, b=4=d| ab --> cd) and therefore generating a seemingly random set of characters, and then passing on this random looking message with the displacement number on the end to person_2. Then all person_2 has to do to get the message is reverse engineer the message using the displacement number, and their message has been safely delivered!

The code overall if fairly simple only taking up 41 lines! More Cipher programs to come in following weeks! Any questions, I am more than happy to reply

The link for the python 3.4.3 code is here:

http://tinyurl.com/l7homd6

and the plain text code is here:

import math
import time

encrypt_letter_to_num = {"a":0,"b":1,"c":2,"d":3,"e":4,"f":5,"g":6,"h":7,"i":8,"j":9,"k":10,"l":11,"m":12,"n":13,"o":14,"p":15,"q":16,"r":17,"s":18,"t":19,"u":20,"v":21,"w":22,"x":23,"y":24,"z":25,"'":26,",":27,".":28,"?":29,"/":30," ":31}
encrypt_num_to_letter = {0:"a",1:"b",2:"c",3:"d",4:"e",5:"f",6:"g",7:"h",8:"i",9:"j",10:"k",11:"l",12:"m",13:"n",14:"o",15:"p",16:"q",17:"r",18:"s",19:"t",20:"u",21:"v",22:"w",23:"x",24:"y",25:"z",26:"'",27:",",28:".",29:"?",30:"/",31:" "}

while True:
    en_de = ""
    en_de = input("Would you like to encrypt a message or decrypt a message?[e/d]: ").lower()
   
    if en_de == "e":
        displace_num = int(input("Please enter your displacement: "))
        main_body = (input("Please input your message, all cases will be changed to lower: ")).lower()

        new_word = ""

        for x in main_body:
            old_value = encrypt_letter_to_num[x]
            new_value = old_value + displace_num
            while new_value > 31:
                new_value -= 32
            new_word += encrypt_num_to_letter[new_value]

        print(new_word)



    if en_de == "d":
        displace_num = int(input("Please enter your displacement: "))
        main_body = (input("Please input your message as it was sent: ")).lower()

        new_word = ""

        for x in main_body:
            old_value = encrypt_letter_to_num[x]
            new_value = old_value - displace_num
            while new_value < 0:
                new_value += 32
            new_word += encrypt_num_to_letter[new_value]

        print(new_word)

Sunday 10 May 2015

Top Trumps GUI | Python 3.4.3

I decided I would attempt my very first TKinter in py 3.4.3 and i think it turned out pretty well! As before. link is below, as is the plain text code.
Download for python 3.4.3 (needs extracting):
For the plain text version, see below:
import tkinter as tk
import datetime
import math
import random
import time
import os
toon_list = [] #Python Lang
player_deck = []
cpu_deck = []
class character:
      def __init__(self, name, health, stamina, morality, strength, height, will, image):
              self.name = name
              self.health = health
              self.stamina = stamina
              self.morality = morality
              self.strength = strength
              self.height = height
              self.will = will
              self.image = image
              toon_list.append(self)
########################################################################Character definitions
vader = character('Darth Vader', 85, 30, 40, 75, 80, 40, "Top_Trumps_Cards\Darth_Vader.gif")             #1
finn = character('Finn', 80, 80, 95, 90, 60, 80, "Top_Trumps_Cards\Finn.gif")                     #2
gandalf = character('Gandalf', 75, 50, 100, 65, 90, 70, "Top_Trumps_Cards\Gandalf.gif")              #3
tony_stark = character('Iron Man', 85, 90, 90, 85, 60, 10, "Top_Trumps_Cards\Iron_Man.gif")           #4
batman = character('Batman', 90, 90, 90, 80, 80, 90, "Top_Trumps_Cards\Batman.gif")                 #5
joker = character('The Joker', 70, 80, 30, 40, 80, 50, "Top_Trumps_Cards\The_Joker.gif")               #6
two_face = character('Two Face', 70, 70, 50, 70, 80, 60, "Top_Trumps_Cards\Two-Face.gif")             #7
superman = character('Superman', 95, 90, 90, 90, 90, 90, "Top_Trumps_Cards\Superman.gif")             #8
wonder_woman = character('Wonder Woman', 80, 75, 90, 80, 70, 95, "Top_Trumps_Cards\Wonder_Woman.gif")     #9
spider_man = character('Spider Man', 70, 80, 70, 70, 80, 90, "Top_Trumps_Cards\Spiderman.gif")         #10
deadpool = character('Deadpool', 85, 90, 50, 83, 90, 85, "Top_Trumps_Cards\Deadpool.gif")             #11
harley_quinn = character('Harley Quinn', 70, 90, 40, 60, 70, 60, "Top_Trumps_Cards\Harley_Quinn.gif")     #12
loki = character('Loki', 100, 90, 10, 90, 85, 70, "Top_Trumps_Cards\Loki.gif")                    #13
thor = character('Thor', 100, 90, 85, 90, 90, 80, "Top_Trumps_Cards\Thor.gif")                    #14
penguin = character('Penguin', 60, 40, 40, 50, 50, 30, "Top_Trumps_Cards\Penguin.gif")               #15
picard = character('Cpt. Picard', 60, 60, 90, 70, 80, 100, "Top_Trumps_Cards\Picard.gif")           #16
groot = character('Groot', 80, 60, 90, 90, 100, 40, "Top_Trumps_Cards\Groot.gif")                  #17
green_arrow = character('Green Arrow', 80, 85, 85, 85, 70, 85, "Top_Trumps_Cards\Green_Arrow.gif")       #18
flash = character('The Flash', 70, 100, 85, 80, 80, 90, "Top_Trumps_Cards\The_Flash.gif")              #19
aqua_man = character('Aqua Man', 85, 90, 85, 90, 90, 85, "Top_Trumps_Cards\Aquaman.gif")             #20
########################################################################Print character stats
cpu_index = ['health', 'stamina', 'morality', 'strength', 'height', 'will']
def print_all_toon_stats(deck):
      print ("*****************************************************************************************************************************************")
      print ("* Name ********* Health ********* Stamina ********* Morality ********* Strength ********* Height ********* Will**")
      print ("-----------------------------------------------------------------------------------------------------------------------------------------")
      for toon in deck:
              col_1 = "*************"
              col_1 = col_1.replace("*", toon.name + " ",1)
              col_1 = col_1[:14]
              col_2 = "**************"
              col_2 = col_2.replace("*", str(toon.health) + " ",1)
              col_2 = col_2[:16]
              col_3 = "*******************************************"
              col_3 = col_3.replace("*", str(toon.stamina) + " ",1)
              col_3 = col_3[:17]
              col_4 = "**************************"
              col_4 = col_4.replace("*", str(toon.morality) + " ",1)
              col_4 = col_4[:18]
              col_5 = "****************"
              col_5 = col_5.replace("*", str(toon.strength) + " ",1)
              col_5 = col_5[:18]
              col_6 = "****************************"
              col_6 = col_6.replace("*", str(toon.height) + " ",1)
              col_6 = col_6[:16]
              col_7 = "**************"
              col_7 = col_7.replace("*", str(toon.will) + " ",1)
              col_7 = col_7[:10]
              data_length = (len(toon.name) + len(str(toon.health)) + len(str(toon.stamina)) + len(str(toon.morality)) + len(str(toon.strength)) + len(str(toon.height)) + len(str(toon.will)))
              print ("*", col_1 + "|" + col_2, col_3, col_4, col_5, col_6, col_7)
              print (" ")
#######################################################################Randomly assign cards to deck
def random_asign(deck):
      if len(toon_list) == 0:
              print ("Pack out of cards")
      else:
              while len(deck) < 10:
                      temp = random.choice(toon_list)
                      if temp in deck:
                              pass
                      else:
                              deck.append(temp)
                              toon_list.remove(temp)
def cards_back(deck):
      while len(deck) > 0:
              for x in deck:
                      toon_list.append(x)
                      deck.remove(x)
#######################################################################Card manipulation
def draw_card(deck):
      try:
              return deck[0]
      except:
              pass
def card_back(deck):
      deck.insert(-1, deck.pop(0))
#######################################################################Button Presses
player_win = 0
times_played = 0
player_won_last = 0
def reset_card():
      winning_text = (str(current_card.name)+ " WINS")
      if str(current_card.name) == "Wonder Woman" or str(current_card.name) == "Harley Quinn":
              label4 = tk.Label(root, text=(winning_text), font=("Helvetica", (win_varw * win_varh * 50)))
              label4.grid(row=0, column=0, columnspan=6)
      else:
              label4 = tk.Label(root, text=(winning_text), font=("Helvetica", (win_varw * win_varh * 60)))
              label4.grid(row=0, column=0, columnspan=6, padx=(win_varw * win_varh * (win_width-700)/2))
      label4.after(2000, label4.grid_forget)
def reset_cpu_card():
      winning_text = (str(cpu_current_card.name)+ " WINS")
      if str(cpu_current_card.name) == "Wonder Woman" or str(cpu_current_card.name) == "Harley Quinn":
              label4 = tk.Label(root, text=(winning_text), font=("Helvetica", (win_varw * win_varh * 50)))
              label4.grid(row=0, column=0, columnspan=6)
      else:
              label4 = tk.Label(root, text=(winning_text), font=("Helvetica", (win_varw * win_varh * 60)))
              label4.grid(row=0, column=0, columnspan=6, padx=(win_varw * win_varh * (win_width-700)/2))
      label4.after(2000, label4.grid_forget)
def it_a_draw():
      winning_text = "It's a draw!"
      label4 = tk.Label(root, text=(winning_text), font=("Helvetica", (win_varw * win_varh * 60)))
      label4.grid(row=0, column=0, columnspan=6, padx=(win_varw * win_varh * (win_width-700)/2))
      label4.after(2000, label4.grid_forget)
def cpu_choose(cpu_current_card):
      cpu_current_battle_stat = 0
      cpu_current_class = 0
      print("TestIsBest")
      for x in cpu_index:
              if x == 'health':
                      if cpu_current_card.health > cpu_current_battle_stat:
                              cpu_current_battle_stat = cpu_current_card.health
                              current_battle_stat = current_card.health
                              current_class = x
              if x == 'stamina':
                      if cpu_current_card.stamina > cpu_current_battle_stat:
                              cpu_current_battle_stat = cpu_current_card.stamina
                              current_battle_stat = current_card.stamina
                              current_class = x
              if x == 'morality':
                      if cpu_current_card.morality > cpu_current_battle_stat:
                              cpu_current_battle_stat = cpu_current_card.morality
                              current_battle_stat = current_card.morality
                              current_class = x
              if x == 'strength':
                      if cpu_current_card.strength > cpu_current_battle_stat:
                              cpu_current_battle_stat = cpu_current_card.strength
                              current_battle_stat = current_card.strength
                              current_class = x
              if x == 'height':
                      if cpu_current_card.height > cpu_current_battle_stat:
                              cpu_current_battle_stat = cpu_current_card.height
                              current_battle_stat = current_card.height
                              current_class = x
              if x == 'will':
                      if cpu_current_card.will > cpu_current_battle_stat:
                              cpu_current_battle_stat = cpu_current_card.will
                              current_battle_stat = current_card.will
                              current_class = x
      print ("cpu current " + str(cpu_current_battle_stat))
      game_calc(current_battle_stat, cpu_current_battle_stat)
def game_calc(current_battle_stat, cpu_current_battle_stat):
      print("E")
      global player_won_last
      global current_card
      global cpu_current_card
      global label1
      global label2
      global player_win
      if current_battle_stat > cpu_current_battle_stat:
              reset_card()
              player_turn = True
              player_deck.append(cpu_current_card)
              try:
                      cpu_deck.remove(cpu_current_card)
                      card_back(player_deck)
                      player_won_last = 0
              except:
                      player_win = 1
              if len(player_deck) == 20:
                      player_win = 1
                      label5.config(text="20")
                      label6.config(text="0")
              print("F")
              print(player_win)
              print(len(cpu_deck))
      elif current_battle_stat < cpu_current_battle_stat:
              reset_cpu_card()
              player_turn = False
              cpu_deck.append(current_card)
              try:
                      player_deck.remove(current_card)
                      card_back(cpu_deck)
                      player_won_last = 1
              except:
                      player_win = -1
              if len(cpu_deck) == 20:
                      player_win = -1
                      label5.config(text="0")
                      label6.config(text="20")
              print("G")
      else:
              it_a_draw()
              card_back(player_deck)
              card_back(cpu_deck)
              print("H")
      print(player_win)
      print(player_won_last)
      if player_win == 0:
              current_card = draw_card(player_deck)
              print("len player " + str(len(player_deck)))
              print("len comp " + str(len(cpu_deck)))
              label5.config(text=str(len(player_deck)))
              label6.config(text=str(len(cpu_deck)))
              photo = tk.PhotoImage(file=current_card.image)
              print("YESH")
              print(current_card.image)
              label1.config(image = "")
              label1.grid_forget
              label1.config(image = photo)
              label1.image = photo
              print (label1.image)
              label1.grid(row=0, column=0, columnspan=2)
              cpu_current_card = draw_card(cpu_deck)
              photo1 = tk.PhotoImage(file=((str(cpu_current_card.image)[:-4]) + "1" + ".gif"))
              label2.config(image = "")
              label2.grid_forget
              label2.config(image = photo1)
              label2.image = photo1
              label2.grid(row=0, column=4, columnspan=2)
              if player_won_last == 1:
                      healthb.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      staminab.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      moralityb.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      strengthb.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      staminab.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      heightb.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      willb.config(state=tk.DISABLED, relief=tk.SUNKEN)
                      cpu_choose(cpu_current_card)
              if player_won_last != 1:
                      healthb.config(state='normal', relief=tk.RAISED)
                      staminab.config(state='normal', relief=tk.RAISED)
                      moralityb.config(state='normal', relief=tk.RAISED)
                      strengthb.config(state='normal', relief=tk.RAISED)
                      staminab.config(state='normal', relief=tk.RAISED)
                      heightb.config(state='normal', relief=tk.RAISED)
                      willb.config(state='normal', relief=tk.RAISED)
              print("I")
      print("J")
      if player_win != 0:
              healthb.config(state=tk.DISABLED, relief=tk.SUNKEN)
              staminab.config(state=tk.DISABLED, relief=tk.SUNKEN)
              moralityb.config(state=tk.DISABLED, relief=tk.SUNKEN)
              strengthb.config(state=tk.DISABLED, relief=tk.SUNKEN)
              staminab.config(state=tk.DISABLED, relief=tk.SUNKEN)
              heightb.config(state=tk.DISABLED, relief=tk.SUNKEN)
              willb.config(state=tk.DISABLED, relief=tk.SUNKEN)
              if player_win == 1:
                      label4 = tk.Label(root, text="You WON!!!", font=("Helvetica", (win_varw * win_varh * 60)))
                      label4.grid(row=0, column=0, columnspan=6, padx=(win_varw * win_varh * (win_width-700)/2))
              else:
                      label4 = tk.Label(root, text="You Lost", font=("Helvetica", (win_varw * win_varh * 60)))
                      label4.grid(row=0, column=0, columnspan=6, padx=(win_varw * win_varh * (win_width-700)/2))
              label4.after(7000, label4.grid_forget)
              play_again = tk.Button(root, text="Play again?", font=("Helvetica"), command= play).grid(row=6, column=2)
              exit = tk.Button(root, text="Exit?", font=("Helvetica"), command= root.destroy).grid(row=6, column=3)
def cpu_press(current_class, current_battle_stat):
      print("C")
      cpu_class_selected = False
      while cpu_class_selected == False:
              cpu_current_class = current_class
              if cpu_current_class == 'health' or cpu_current_class == 'Health':
                      cpu_current_battle_stat = cpu_current_card.health
                      cpu_class_selected = True
              elif cpu_current_class == 'stamina' or cpu_current_class == 'Stamina':
                      cpu_current_battle_stat = cpu_current_card.stamina
                      cpu_class_selected = True
              elif cpu_current_class == 'morality' or cpu_current_class == 'Morality':
                      cpu_current_battle_stat = cpu_current_card.morality
                      cpu_class_selected = True
              elif cpu_current_class == 'strength' or cpu_current_class == 'Strength':
                      cpu_current_battle_stat = cpu_current_card.strength
                      cpu_class_selected = True
              elif cpu_current_class == 'stamina' or cpu_current_class == 'Stamina':
                      cpu_current_battle_stat = cpu_current_card.stamina
                      cpu_class_selected = True
              elif cpu_current_class == 'height' or cpu_current_class == 'Height':
                      cpu_current_battle_stat = cpu_current_card.height
                      cpu_class_selected = True
              elif cpu_current_class == 'will' or cpu_current_class == 'Will':
                      cpu_current_battle_stat = cpu_current_card.will
                      cpu_class_selected = True
              else:
                      pass
      print (cpu_current_battle_stat)
      print("D")
      game_calc(current_battle_stat, cpu_current_battle_stat)
def current_press(button_pressed):
      print("a")
      current_battle_stat = getattr(current_card,button_pressed)
      class_selected = True
      print (current_battle_stat)
      print("b")
      cpu_press(button_pressed, current_battle_stat)
#######################################################################Game initialisation
print("J")
game_started = False
player_win = 0
turn_count = 0
times_played = 0
cards_back(player_deck)
cards_back(cpu_deck)
random_asign(cpu_deck)
random_asign(player_deck)
current_card = draw_card(player_deck)
cpu_current_card = draw_card(cpu_deck)
root = tk.Tk()
root.columnconfigure('all', minsize = 200)
w, h = root.winfo_screenwidth(), root.winfo_screenheight()
root.overrideredirect(1)
root.geometry("%dx%d+0+0" % (w, h))
print("L")
win_width = root.winfo_screenwidth()
win_height = root.winfo_screenheight()
win_varw = int(win_width/1600)
win_varh = int(win_height/900)
root.columnconfigure('all', minsize = (win_width/6))
'''space = tk.PhotoImage(file="crab_nebula.gif")
Background = tk.Label(root, image=space)
Background.image = space
Background.grid(row=0, column=0, columnspan=6,rowspan=7,pady=(0), padx=(0))'''
def play():
      global player_won_last
      global player_win
      global turn_count
      global current_card
      global cpu_current_card
      global times_played
      healthb = tk.Button(root, text="Health", font=("Helvetica"), command= lambda: current_press('health'), state=tk.DISABLED)
      staminab = tk.Button(root, text="Stamina", font=("Helvetica"), command= lambda: current_press('stamina'), state=tk.DISABLED)
      moralityb = tk.Button(root, text="Morality", font=("Helvetica"), command= lambda: current_press('morality'), state=tk.DISABLED)
      strengthb = tk.Button(root, text="Strength", font=("Helvetica"), command= lambda: current_press('strength'), state=tk.DISABLED)
      heightb = tk.Button(root, text="Height", font=("Helvetica"), command= lambda: current_press('height'), state=tk.DISABLED)
      willb = tk.Button(root, text="Will", font=("Helvetica"), command= lambda: current_press('will'), state=tk.DISABLED)
      times_played += 1
      player_won_last = 0
      player_win = 0
      turn_count = 0
      print("Cards being put into pack")
      cards_back(player_deck)
      cards_back(cpu_deck)
      print(len(toon_list))
      print(len(player_deck))
      print(len(cpu_deck))
      print("assigning to cpu")
      random_asign(cpu_deck)
      print(len(toon_list))
      print(len(player_deck))
      print(len(cpu_deck))
      print("assigning to player")
      random_asign(player_deck)
      print(len(toon_list))
      print(len(player_deck))
      print(len(cpu_deck))
      print("123")
      current_card = draw_card(player_deck)
      print("cur card = " + current_card.name)
      print("432")
      cpu_current_card = draw_card(cpu_deck)
      print("543")
      if times_played != 0:
              healthb.config(state='normal', relief=tk.RAISED)
              staminab.config(state='normal', relief=tk.RAISED)
              moralityb.config(state='normal', relief=tk.RAISED)
              strengthb.config(state='normal', relief=tk.RAISED)
              staminab.config(state='normal', relief=tk.RAISED)
              heightb.config(state='normal', relief=tk.RAISED)
              willb.config(state='normal', relief=tk.RAISED)
      print("srguedrbjkgn")
      print(current_card.image)
      player = tk.PhotoImage(file=current_card.image)
      computer = tk.PhotoImage(file=((str(cpu_current_card.image)[:-4]) + "1" + ".gif"))
      print("M")
      print(player)
      label1.config(image = "")
      label1.grid_forget
      label1.config(image = player)
      label1.image = player
      label1.grid(row=0, column=0, columnspan=2, padx=(win_varw * win_varh * ((win_width/3)-400)/2))
      label2.config(image = "")
      label2.grid_forget
      label2.config(image = computer)
      label2.image = computer
      label2.grid(row=0, column=4, columnspan=2, padx=(win_varw * win_varh * ((win_width/3)-400)/2))
      label3 = tk.Label(root, text="VS", font=("Helvetica", (win_varw * win_varh * 70)))
      label3.grid(row=0, column=2, columnspan=2, padx=(win_varw * win_varh * ((win_width/3)-140)/2))
      print("Tester1")
      print(len(player_deck))
      label7 = tk.Label(root, text="Your Deck", font=("Helvetica", (win_varw * win_varh * 60)))
      label7.grid(row=5, column=0, columnspan=2)
      label8 = tk.Label(root, text="CPU's Deck", font=("Helvetica", (win_varw * win_varh * 60)))
      label8.grid(row=5, column=4, columnspan=2)
      label5.config(text = "")
      label5.grid_forget
      label5.config(text = str(len(player_deck)))
      label5.text = str(len(player_deck))
      label5.grid(row=6, column=0, columnspan=2)
      label6.config(text = "")
      label6.grid_forget
      label6.config(text = str(len(cpu_deck)))
      label6.text = str(len(cpu_deck))
      label6.grid(row=6, column=4, columnspan=2)
      healthb = tk.Button(root, text="Health", font=("Helvetica"), command= lambda: current_press('health'))
      healthb.grid(row=1, column=0)
      staminab = tk.Button(root, text="Stamina", font=("Helvetica"), command= lambda: current_press('stamina'))
      staminab.grid(row=1, column=1)
      moralityb = tk.Button(root, text="Morality", font=("Helvetica"), command= lambda: current_press('morality'))
      moralityb.grid(row=1, column=2)
      strengthb = tk.Button(root, text="Strength", font=("Helvetica"), command= lambda: current_press('strength'))
      strengthb.grid(row=1, column=3)
      heightb = tk.Button(root, text="Height", font=("Helvetica"), command= lambda: current_press('height'))
      heightb.grid(row=1, column=4)
      willb = tk.Button(root, text="Will", font=("Helvetica"), command= lambda: current_press('will'))
      willb.grid(row=1, column=5)
      escape = tk.Button(root, text="Escape", font=("Helvetica"), command= root.destroy)
      escape.grid(row=2, column=2, columnspan=2)
      print("K")
player = tk.PhotoImage(file=current_card.image)
computer = tk.PhotoImage(file=((str(cpu_current_card.image)[:-4]) + "1" + ".gif"))
print("M")
label1 = tk.Label(root, image=player)
label1.image = player
label1.grid(row=0, column=0, columnspan=2, padx=(win_varw * win_varh * ((win_width/3)-400)/2))
label2 = tk.Label(root, image=computer)
label2.image = computer
label2.grid(row=0, column=4, columnspan=2, padx=(win_varw * win_varh * ((win_width/3)-400)/2))
label3 = tk.Label(root, text="VS", font=("Helvetica", (win_varw * win_varh * 70)))
label3.grid(row=0, column=2, columnspan=2, padx=(win_varw * win_varh * ((win_width/3)-140)/2))
label7 = tk.Label(root, text="Your Deck", font=("Helvetica", (win_varw * win_varh * 60)))
label7.grid(row=5, column=0, columnspan=2)
label8 = tk.Label(root, text="CPU's Deck", font=("Helvetica", (win_varw * win_varh * 60)))
label8.grid(row=5, column=4, columnspan=2)
label5 = tk.Label(root, text=str(len(player_deck)), font=("Helvetica", (win_varw * win_varh * 70)))
label5.grid(row=6, column=0, columnspan=2)
label6 = tk.Label(root, text=str(len(cpu_deck)), font=("Helvetica", (win_varw * win_varh * 70)))
label6.grid(row=6, column=4, columnspan=2)
label4 = tk.Label(root, text="", font=("Helvetica", (win_varw * win_varh * 60)))
label4.grid(row=0, column=0, columnspan=6, padx=(win_varw * win_varh * (win_width-700)/2))
healthb = tk.Button(root, text="Health", font=("Helvetica"), command= lambda: current_press('health'))
healthb.grid(row=1, column=0)
staminab = tk.Button(root, text="Stamina", font=("Helvetica"), command= lambda: current_press('stamina'))
staminab.grid(row=1, column=1)
moralityb = tk.Button(root, text="Morality", font=("Helvetica"), command= lambda: current_press('morality'))
moralityb.grid(row=1, column=2)
strengthb = tk.Button(root, text="Strength", font=("Helvetica"), command= lambda: current_press('strength'))
strengthb.grid(row=1, column=3)
heightb = tk.Button(root, text="Height", font=("Helvetica"), command= lambda: current_press('height'))
heightb.grid(row=1, column=4)
willb = tk.Button(root, text="Will", font=("Helvetica"), command= lambda: current_press('will'))
willb.grid(row=1, column=5)
escape = tk.Button(root, text="Escape", font=("Helvetica"), command= root.destroy)
escape.grid(row=2, column=2, columnspan=2)
print("N")
root.mainloop()

Sunday 3 May 2015

Text-Based Top Trumps Game | Python 3.4.3

I had an idea that to practice my classes in python i would make a text based Top Trumps for characters from some of my favourite universes. Took a good week or two but here it is!
Download link for .py in python 3.4.3:
Below is the plain text code, any questions, please comment and ask!
import math
import random
import time
toon_list = [] #Python Lang
player_deck = []
cpu_deck = []
class character:
       def __init__(self, name, health, stamina, morality, strength, height, will):
               self.name = name
               self.health = health
               self.stamina = stamina
               self.morality = morality
               self.strength = strength
               self.height = height
               self.will = will
               toon_list.append(self)
########################################################################Character definitions
vader = character(‘Darth Vader’, 85, 30, 40, 75, 80, 40)
finn = character('Finn’, 80, 80, 95, 90, 60, 80)
gandalf = character('Gandalf’, 75, 50, 100, 65, 90, 70)
tony_stark = character('Iron Man’, 85, 90, 90, 85, 60, 10)
batman = character('Batman’, 90, 90, 90, 80, 80, 10)
joker = character('The Joker’, 70, 90, 30, 40, 80, 50)
two_face = character('Two Face’, 70, 70, 50, 70, 80, 60)
superman = character('Superman’, 90, 90, 90, 90, 90, 90)
wonder_woman = character('Wonder Woman’, 80, 75, 90, 80, 70, 95)
spider_man = character('Spider Man’, 70, 90, 70, 70, 80, 90)
all_cards = {'Darth Vader’:vader, 'Vader’:vader, 'vader’:vader, 'Finn’:finn, 'finn’:finn, 'White Wizard’:gandalf,
            'white wizard’:gandalf, 'Stark’:tony_stark, 'Tony Stark’:tony_stark, 'Tony’:tony_stark, 'Iron man’:tony_stark,
            'iron man’:tony_stark, 'gandalf’:gandalf, 'Gandalf’:gandalf, 'Batman’:batman, 'Bat man’:batman,
            'Bat Man’:batman, 'BatMan’:batman, 'Bruce Wayne’:batman, 'bruce wayne’:batman, 'The Joker’:joker,
            'the joker’:joker, 'joker’:joker, 'Joker’:joker, 'Two Face’:two_face, 'two face’:two_face,
            'Harvey Dent’:two_face, 'harvey dent’:two_face, 'Twoface’:two_face, 'TwoFace’:two_face, 'superman’:superman,
            'Superman’:superman, 'super man’:superman, 'Super Man’:superman, 'Super man’:superman, 'Wonder Woman’:wonder_woman,
            'wonder woman’:wonder_woman, 'Wonderwoman’:wonder_woman, 'WonderWoman’:wonder_woman, 'Spider Man’:spider_man, 'spider man’:spider_man,
            'Spiderman’:spider_man}
########################################################################Print character stats
cpu_index = ['health’, 'stamina’, 'morality’, 'strength’, 'height’, 'will’]
def print_all_toon_stats(deck):
       print (“*****************************************************************************************************************************************”)
       print (“* Name ********* Health ********* Stamina ********* Morality ********* Strength ********* Height ********* Will**”)
       print (“—————————————————————————————————————————————–”)
       for toon in deck:
               col_1 = “*************”
               col_1 = col_1.replace(“*”, toon.name + “ ”,1)
               col_1 = col_1[:14]
               col_2 = “**************”
               col_2 = col_2.replace(“*”, str(toon.health) + “ ”,1)
               col_2 = col_2[:16]
               col_3 = “*******************************************”
               col_3 = col_3.replace(“*”, str(toon.stamina) + “ ”,1)
               col_3 = col_3[:17]
               col_4 = “**************************”
               col_4 = col_4.replace(“*”, str(toon.morality) + “ ”,1)
               col_4 = col_4[:18]
               col_5 = “****************”
               col_5 = col_5.replace(“*”, str(toon.strength) + “ ”,1)
               col_5 = col_5[:18]
               col_6 = “****************************”
               col_6 = col_6.replace(“*”, str(toon.height) + “ ”,1)
               col_6 = col_6[:16]
               col_7 = “**************”
               col_7 = col_7.replace(“*”, str(toon.will) + “ ”,1)
               col_7 = col_7[:10]
               data_length = (len(toon.name) + len(str(toon.health)) + len(str(toon.stamina)) + len(str(toon.morality)) + len(str(toon.strength)) + len(str(toon.height)) + len(str(toon.will)))
               print (“*”, col_1 + “|” + col_2, col_3, col_4, col_5, col_6, col_7)
               print (“ ”)
########################################################################Player 1 character selections
def player_card_picker():
       def player_1_pick():
               player_1_pick = input(“Select a character to fight!”)
               return str(player_1_pick)
       card_picked = False
       while card_picked == False:
               player_1_pick = player_1_pick()
               if player_1_pick in all_cards:
                       player_1_pick = all_cards[player_1_pick]
                       if player_1_pick in player_deck:
                               card_picked = True
                       else:
                               pass
               else:
                       print (“Invalid card. Please re-enter”)
#######################################################################Random card selection
def cpu_card_picker():
       random_1_pick = random.choice(cpu_deck)
       return random_1_pick
#######################################################################Randomly assign cards to deck
def random_asign(deck):
       if len(toon_list) == 0:
               print (“Pack out of cards”)
       else:
               while len(deck) < 5:
                       temp = random.choice(toon_list)
                       if temp in deck:
                               pass
                       else:
                               deck.append(temp)
                               toon_list.remove(temp)
               if deck == player_deck:
                       print (“Your deck updated: ”)
                       print (deck[0].name, “|”, deck[1].name, “|”, deck[2].name, “|”, deck[3].name, “|”, deck[4].name, “|”)
#######################################################################Player terms
#######################################################################Game initialisation
game_started = False
turn_count = 0
while game_started == False:
       random_asign(cpu_deck)
       random_asign(player_deck)        
       game_started = True
       print (“START”)
       player_turn = True
       while len(player_deck) > 0 and len(cpu_deck) > 0:
               turn_count += 1
               current_card = random.choice(player_deck)
               cpu_current_card = random.choice(cpu_deck)
               if player_turn == True:
                       print (“”)
                       print (“YOU’RE NOW PLAYING WITH”, (current_card.name).upper() + “!”)
                       print (“*********************************************************************************************************************”)
                       print (“* Name ********* Health ********* Stamina ********* Morality ********* Strength ********* Height ********* Will******”)
                       print (“———————————————————————————————————————”)
                       col_1 = “*************”
                       col_1 = col_1.replace(“*”, current_card.name + “ ”,1)
                       col_1 = col_1[:14]
                       col_2 = “**************”
                       col_2 = col_2.replace(“*”, str(current_card.health) + “ ”,1)
                       col_2 = col_2[:16]
                       col_3 = “*******************************************”
                       col_3 = col_3.replace(“*”, str(current_card.stamina) + “ ”,1)
                       col_3 = col_3[:17]
                       col_4 = “**************************”
                       col_4 = col_4.replace(“*”, str(current_card.morality) + “ ”,1)
                       col_4 = col_4[:18]
                       col_5 = “****************”
                       col_5 = col_5.replace(“*”, str(current_card.strength) + “ ”,1)
                       col_5 = col_5[:18]
                       col_6 = “****************************”
                       col_6 = col_6.replace(“*”, str(current_card.height) + “ ”,1)
                       col_6 = col_6[:16]
                       col_7 = “**************”
                       col_7 = col_7.replace(“*”, str(current_card.will) + “ ”,1)
                       col_7 = col_7[:10]
                       print (“*”, col_1 + “|” + col_2, col_3, col_4, col_5, col_6, col_7)
                       print (“ ”)
                       class_selected = False
                       while class_selected == False:
                               current_class = (input(“What will you battle with?”)).lower()
                               if current_class == 'health’ or current_class == 'Health’:
                                       current_battle_stat = current_card.health
                                       class_selected = True
                               elif current_class == 'stamina’ or current_class == 'Stamina’:
                                       current_battle_stat = current_card.stamina
                                       class_selected = True
                               elif current_class == 'morality’ or current_class == 'Morality’:
                                       current_battle_stat = current_card.morality
                                       class_selected = True
                               elif current_class == 'strength’ or current_class == 'Strength’:
                                       current_battle_stat = current_card.strength
                                       class_selected = True
                               elif current_class == 'stamina’ or current_class == 'Stamina’:
                                       current_battle_stat = current_card.stamina
                                       class_selected = True
                               elif current_class == 'height’ or current_class == 'Height’:
                                       current_battle_stat = current_card.height
                                       class_selected = True
                               elif current_class == 'will’ or current_class == 'Will’:
                                       current_battle_stat = current_card.will
                                       class_selected = True
                               else:
                                       pass
                       cpu_class_selected = False
                       while cpu_class_selected == False:
                               cpu_current_class = current_class
                               if cpu_current_class == 'health’ or cpu_current_class == 'Health’:
                                       cpu_current_battle_stat = cpu_current_card.health
                                       cpu_class_selected = True
                               elif cpu_current_class == 'stamina’ or cpu_current_class == 'Stamina’:
                                       cpu_current_battle_stat = cpu_current_card.stamina
                                       cpu_class_selected = True
                               elif cpu_current_class == 'morality’ or cpu_current_class == 'Morality’:
                                       cpu_current_battle_stat = cpu_current_card.morality
                                       cpu_class_selected = True
                               elif cpu_current_class == 'strength’ or cpu_current_class == 'Strength’:
                                       cpu_current_battle_stat = cpu_current_card.strength
                                       cpu_class_selected = True
                               elif cpu_current_class == 'stamina’ or cpu_current_class == 'Stamina’:
                                       cpu_current_battle_stat = cpu_current_card.stamina
                                       cpu_class_selected = True
                               elif cpu_current_class == 'height’ or cpu_current_class == 'Height’:
                                       cpu_current_battle_stat = cpu_current_card.height
                                       cpu_class_selected = True
                               elif cpu_current_class == 'will’ or cpu_current_class == 'Will’:
                                       cpu_current_battle_stat = cpu_current_card.will
                                       cpu_class_selected = True
                               else:
                                       pass
                       print (current_card.name, “has”, current_battle_stat, current_class.capitalize())
                       print (“”)
                       print (“”)
                       print (“************************”, (current_card.name).upper(), “(” + str(current_battle_stat) + “)”,“VS”, (cpu_current_card.name).upper(), “(” + str(cpu_current_battle_stat) + “)”, “************************”)
                       print (“”)
                       print (“”)
                       time.sleep(2)
               elif player_turn == False:
                       cpu_current_battle_stat = 0
                       cpu_current_class = 0
                       for x in cpu_index:
                               if x == 'health’:
                                       if cpu_current_card.health > cpu_current_battle_stat:
                                               cpu_current_battle_stat = cpu_current_card.health
                                               current_battle_stat = current_card.health
                                               current_class = x
                               if x == 'stamina’:
                                       if cpu_current_card.stamina > cpu_current_battle_stat:
                                               cpu_current_battle_stat = cpu_current_card.stamina
                                               current_battle_stat = current_card.stamina
                                               current_class = x
                               if x == 'morality’:
                                       if cpu_current_card.morality > cpu_current_battle_stat:
                                               cpu_current_battle_stat = cpu_current_card.morality
                                               current_battle_stat = current_card.morality
                                               current_class = x
                               if x == 'strength’:
                                       if cpu_current_card.strength > cpu_current_battle_stat:
                                               cpu_current_battle_stat = cpu_current_card.strength
                                               current_battle_stat = current_card.strength
                                               current_class = x
                               if x == 'height’:
                                       if cpu_current_card.height > cpu_current_battle_stat:
                                               cpu_current_battle_stat = cpu_current_card.height
                                               current_battle_stat = current_card.height
                                               current_class = x
                               if x == 'will’:
                                       if cpu_current_card.will > cpu_current_battle_stat:
                                               cpu_current_battle_stat = cpu_current_card.will
                                               current_battle_stat = current_card.will
                                               current_class = x
                       print (“”)
                       print (“YOU’RE NOW PLAYING WITH”, (current_card.name).upper() + “!”)
                       print (“*********************************************************************************************************************”)
                       print (“* Name ********* Health ********* Stamina ********* Morality ********* Strength ********* Height ********* Will******”)
                       print (“———————————————————————————————————————”)
                       col_1 = “*************”
                       col_1 = col_1.replace(“*”, current_card.name + “ ”,1)
                       col_1 = col_1[:14]
                       col_2 = “**************”
                       col_2 = col_2.replace(“*”, str(current_card.health) + “ ”,1)
                       col_2 = col_2[:16]
                       col_3 = “*******************************************”
                       col_3 = col_3.replace(“*”, str(current_card.stamina) + “ ”,1)
                       col_3 = col_3[:17]
                       col_4 = “**************************”
                       col_4 = col_4.replace(“*”, str(current_card.morality) + “ ”,1)
                       col_4 = col_4[:18]
                       col_5 = “****************”
                       col_5 = col_5.replace(“*”, str(current_card.strength) + “ ”,1)
                       col_5 = col_5[:18]
                       col_6 = “****************************”
                       col_6 = col_6.replace(“*”, str(current_card.height) + “ ”,1)
                       col_6 = col_6[:16]
                       col_7 = “**************”
                       col_7 = col_7.replace(“*”, str(current_card.will) + “ ”,1)
                       col_7 = col_7[:10]
                       print (“*”, col_1 + “|” + col_2, col_3, col_4, col_5, col_6, col_7)
                       print (“ ”)
                       print (current_card.name, “has”, current_battle_stat, current_class.capitalize())
                       print (“”)
                       print (“”)
                       print (“************************”, (current_card.name).upper(), “(” + str(current_battle_stat) + “)”,“VS”, (cpu_current_card.name).upper(), “(” + str(cpu_current_battle_stat) + “)”, “************************”)
                       print (“”)
                       print (“”)
                       time.sleep(2)
               if current_battle_stat > cpu_current_battle_stat:
                       print ((current_card.name).upper(), “WINS!”)
                       time.sleep(2)
                       player_turn = True
                       player_deck.append(cpu_current_card)
                       cpu_deck.remove(cpu_current_card)
               elif current_battle_stat < cpu_current_battle_stat:
                       print ((cpu_current_card.name).upper(), “WINS!”)
                       time.sleep(2)
                       player_turn = False
                       cpu_deck.append(current_card)
                       player_deck.remove(current_card)
               else:
                       print (“BOTH HERO’S LIVE TO FIGHT ANOTHER DAY!”)
                       time.sleep(2)
               print (“CPU has”, len(cpu_deck), “cards left!”)
               print (“You have”, len(player_deck), “cards left!”)
               if current_battle_stat > cpu_current_battle_stat:
                       print (“”)
                       print (“”)
                       print (“##############”)
                       print (“###HAND WON###”)
                       print (“##############”)
                       print (“”)
                       print (“”)
               elif current_battle_stat < cpu_current_battle_stat:
                       print (“”)
                       print (“”)
                       print (“###############”)
                       print (“###HAND LOST###”)
                       print (“###############”)
                       print (“”)
                       print (“”)
               else:
                       print (“”)
                       print (“”)
                       print (“###############”)
                       print (“###HAND DRAW###”)
                       print (“###############”)
                       print (“”)
                       print (“”)
               time.sleep(2.0)
       if len(cpu_deck) == 0:
               print (“*****************************************************************************************************************************************”)
               print (“**************************************************************         ******************************************************************”)
               print (“************************************************************** YOU WIN ******************************************************************”)
               print (“**************************************************************         ******************************************************************”)
               print (“*****************************************************************************************************************************************”)
       else:
               print (“*****************************************************************************************************************************************”)
               print (“**************************************************************          *****************************************************************”)
               print (“************************************************************** YOU LOSE *****************************************************************”)
               print (“**************************************************************          *****************************************************************”)
               print (“*****************************************************************************************************************************************”)
       print(“”)
       for x in player_deck:
               toon_list.append(x)
               player_deck.remove(x)
       for x in cpu_deck:
               toon_list.append(x)
               cpu_deck.remove(x)
       Valid = False
       while Valid == False:
               play_again = input(“Would you like to play again?”)
               if play_again == 'Yes’ or play_again == 'yes’ or play_again == 'y’ or play_again == 'Y’:
                       game_started = False
                       Valid = True
               elif play_again == 'No’ or play_again == 'no’ or play_again == 'n’ or play_again == 'N’:
                       print (“Thanks for playing!!”)
                       Valid = True
                       continue
               else:
                       print (“Invalid input, please try again!”)