Skip to content

Instantly share code, notes, and snippets.

@Arkitan
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Arkitan/10751996 to your computer and use it in GitHub Desktop.
Save Arkitan/10751996 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3.3
import random
grep_a = {}
grep_b = {}
grep_c = {}
offspring = {}
dom_colors = 'red yellow green blue orange white brown black violet'.split()
rec_colors = 'indigo pink magenta khaki crimson gray turquoise gold silver'.split()
parts = 'eyes fur ears tail claws paws whiskers crest'.split()
dom_fur_accents = 'stripes spots'.split()
rec_fur_accents = 'zigzags checkers chevrons'.split()
num_of_greps = 2
genes = 'DD Dd dd'.split()
def examine_genes(genes):
pick = random.randint(0, 2)
if pick == 0:
chosen_genes = genes[0]
# Sets the genes to dominant/dominant
elif pick == 1:
chosen_genes = genes[1]
# Sets the genes to dominant/rececive
else:
chosen_genes = genes[2]
#sets the genes to rececive/rececive
return(chosen_genes)
def gene_slicing():
chosen_genes = examine_genes(genes)
first_gene = chosen_genes[0:1]
second_gene = chosen_genes[1:]
if first_gene == 'D' or second_gene == 'D':
return 'dom'
else:
return 'rec'
def choose_trait(x):
trait = random.randint(0, len(x))
return (x[trait - 1])
def define_trait():
if gene_slicing() == 'dom':
color1 = choose_trait(dom_colors)
color2 = choose_trait(dom_colors)
accent = choose_trait(dom_fur_accents)
else:
color1 = choose_trait(rec_colors)
color2 = choose_trait(rec_colors)
accent = choose_trait(rec_fur_accents)
return color1, color2, accent
def build_grep(grep):
for i in parts:
grep[i] = (define_trait())
def display_grep(grep):
print('Congratulations, your grep has the following traits')
print('Your grep\'s eyes are ' + grep['eyes'][0] + ' with ' + grep['eyes'][1] + ' ' + grep['eyes'][2])
print('Your grep\'s fur is ' + grep['fur'][0] + ' with ' + grep['fur'][1] + ' ' + grep['fur'][2])
print('Your grep\'s ears are ' + grep['ears'][0] + ' with ' + grep['ears'][1] + ' ' + grep['ears'][2])
print('Your grep\'s tail is ' + grep['tail'][0] + ' with ' + grep['tail'][1] + ' ' + grep['tail'][2])
print('Your grep\'s claws are ' + grep['claws'][0] + ' with ' + grep['claws'][1] + ' ' + grep['claws'][2])
print('Your grep\'s paws are ' + grep['paws'][0] + ' with ' + grep['paws'][1] + ' ' + grep['paws'][2])
print('Your grep\'s whiskers are ' + grep['whiskers'][0] + ' with ' + grep['whiskers'][1] + ' ' + grep['whiskers'][2])
print('Your grep\'s crest is ' + grep['crest'][0] + ' with ' + grep['crest'][1] + ' ' + grep['crest'][2])
#build_grep(grep_a)
#build_grep(grep_b)
#print('This is parent #1')
#display_grep(grep_a)
#print('')
#print('This is parent #2')
#display_grep(grep_b)
def mate_grepz(grep_a, grep_b, offspring):
for i in parts:
if grep_a[i][0] in rec_colors and grep_b[i][0] in rec_colors:
# Because both are rececive this will return a trait from one of the parents at random.
if random.randint(0, 1) == 1:
offspring[i] = grep_a[i]
else:
offspring[i] = grep_b[i]
elif grep_a[i][0] in dom_colors and grep_b[i][0] in rec_colors:
# Because A is dominant and B is rececive this will return the trait from A
offspring[i] = grep_a[i]
elif grep_a[i][0] in rec_colors and grep_b[i][0] in dom_colors:
# Because A is rececive and B is dominant this will return the trait from B
offspring[i] = grep_b[i]
elif grep_a[i][0] in dom_colors and grep_b[i][0] in dom_colors:
#because both are dominant this will return a trait from one of the parents at random.
if random.randint(0, 1) == 1:
offspring[i] = grep_a[i]
else:
offspring[i] = grep_b[i]
elif grep_a[i][0] in rec_fur_accents and grep_b[i][0] in rec_fur_accents:
# Because both are rececive this will return a trait from one of the parents at random.
if random.randint(0, 1) == 1:
offspring[i] = grep_a[i]
else:
offspring[i] = grep_b[i]
elif grep_a[i][0] in dom_fur_accents and grep_b[i][0] in rec_fur_accents:
# Because A is dominant and B is rececive this will return the trait from A
offspring[i] = grep_a[i]
elif grep_a[i][0] in rec_fur_accents and grep_b[i][0] in dom_fur_accents:
# Because A is rececive and B is dominant this will return the trait from B
offspring[i] = grep_b[i]
elif grep_a[i][0] in dom_fur_accents and grep_b[i][0] in dom_fur_accents:
#because both are dominant this will return a trait from one of the parents at random.
if random.randint(0, 1) == 1:
offspring[i] = grep_a[i]
else:
offspring[i] = grep_b[i]
def name_grep(grep):
# This will allow the user to name the grep
grep['name'] = input('What would you like to name this grep?')
print(grep['name'])
def player_action():
action = ''
actionlist = 'view name release feed breed'.split()
while action not in actionlist:
action = input('What would you like to do with your greps? (View / Name / Release / Feed / Breed)').lower()
if action == 'view':
chosen_grep = input('Which grep would you like to view? (A, B, C)').lower()
chosen_grep =('grep_' + chosen_grep)
display_grep(chosen_grep)
def introduction():
print('Welcome to GREPS! We will start you off with two greps.')
print('As time goes on you\'ll breed them and get even more greps')
print('')
print('Here are two greps to get you started')
print('You currently have ' + str(num_of_greps) + ' greps')
build_grep(grep_a)
build_grep(grep_b)
player_action()
introduction()
#mate_grepz(grep_a, grep_b, offspring)
#print('')
#print('This is the offspring')
#display_grep(offspring)
_______________________________________________________________
Welcome to GREPS! We will start you off with two greps.
As time goes on you'll breed them and get even more greps
Here are two greps to get you started
What would you like to do with your greps? (View / Name / Release / Feed / Breed)vie
w
Which grep would you like to view? (A, B, C)a
Congratulations, your grep has the following traits
Traceback (most recent call last):
File "/home/Arkitan/learningpython/grepz/grepz.py", line 139, in <module>
introduction()
File "/home/Arkitan/learningpython/grepz/grepz.py", line 137, in introduction
player_action()
File "/home/Arkitan/learningpython/grepz/grepz.py", line 127, in player_action
display_grep(chosen_grep)
File "/home/Arkitan/learningpython/grepz/grepz.py", line 58, in display_grep
print('Your grep\'s eyes are ' + grep['eyes'][0] + ' with ' + grep['eyes'][1] +
' ' + grep['eyes'][2])
TypeError: string indices must be integers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment