-
Notifications
You must be signed in to change notification settings - Fork 9
access eggs from list of ints #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,27 +6,8 @@ | |
| MalePop = 14 | ||
| FemalePop = 2 | ||
| tick = 0 | ||
| Egg0 = 0 | ||
| Egg1 = 0 | ||
| Egg2 = 0 | ||
| Egg3 = 0 | ||
| Egg4 = 0 | ||
| Egg5 = 0 | ||
| Egg6 = 0 | ||
| Egg7 = 0 | ||
| Egg8 = 0 | ||
| Egg9 = 0 | ||
| Egg10 = 0 | ||
| Egg11 = 0 | ||
| Egg12 = 0 | ||
| Egg13 = 0 | ||
| Egg14 = 0 | ||
| Egg15 = 0 | ||
| Egg16 = 0 | ||
| Egg17 = 0 | ||
| Egg18 = 0 | ||
| Egg19 = 0 | ||
| Egg20 = 0 | ||
| # This initializes a list [ 0 ... 0] with 20 elements | ||
| eggs = [0] * 20 | ||
|
|
||
| with open('BulbasaurPopulation.csv', 'a', newline='') as csv_file: | ||
| fieldnames = ['tick', 'females', 'males'] | ||
|
|
@@ -54,51 +35,35 @@ | |
| MalePop += -1 | ||
|
|
||
|
|
||
| if Egg0 > 0: | ||
| print (Egg0, "Bulbasaur eggs are hatching!") | ||
| for x in range(Egg0): | ||
| if eggs[0] > 0: | ||
| print (eggs[0], "Bulbasaur eggs are hatching!") | ||
| for x in range(eggs[0]): | ||
| sexroll = random.randint(1,8) | ||
| if sexroll <= 7: | ||
| MalePop += 1 | ||
| else: | ||
| FemalePop += 1 | ||
|
|
||
| Egg0 = Egg0-Egg0+Egg1 | ||
| Egg1 = Egg1-Egg1+Egg2 | ||
| Egg2 = Egg2-Egg2+Egg3 | ||
| Egg3 = Egg3-Egg3+Egg4 | ||
| Egg4 = Egg4-Egg4+Egg5 | ||
| Egg5 = Egg5-Egg5+Egg6 | ||
| Egg6 = Egg6-Egg6+Egg7 | ||
| Egg7 = Egg7-Egg7+Egg8 | ||
| Egg8 = Egg8-Egg8+Egg9 | ||
| Egg9 = Egg9-Egg9+Egg10 | ||
| Egg10 = Egg10-Egg10+Egg11 | ||
| Egg11 = Egg11-Egg11+Egg12 | ||
| Egg12 = Egg12-Egg12+Egg13 | ||
| Egg13 = Egg13-Egg13+Egg14 | ||
| Egg14 = Egg14-Egg14+Egg15 | ||
| Egg15 = Egg15-Egg15+Egg16 | ||
| Egg16 = Egg16-Egg16+Egg17 | ||
| Egg17 = Egg17-Egg17+Egg18 | ||
| Egg18 = Egg18-Egg18+Egg19 | ||
| Egg19 = Egg19-Egg19+Egg20 | ||
| Egg20 = Egg20-Egg20 | ||
| for i in range(len(eggs)): | ||
| if i < len(eggs) - 1: | ||
| eggs[i] = eggs[i+1] | ||
| else: | ||
| eggs[i] = 0 | ||
|
|
||
|
|
||
|
|
||
| if MalePop >=1 and tick <=100: | ||
| for x in range(FemalePop): | ||
| egg = random.randint(1,100) | ||
| if egg <= 50: | ||
| Egg20 += 1 | ||
| egg[-1] += 1 | ||
|
|
||
| elif FemalePop >=1: | ||
|
|
||
| for x in range(FemalePop): | ||
| egg = random.randint(1,100) | ||
| if egg <=10: | ||
| Egg20 += 1 | ||
| eggs[-1] += 1 | ||
|
|
||
|
|
||
|
|
||
|
|
@@ -112,6 +77,6 @@ | |
| print("Population max reached") | ||
|
|
||
| break | ||
| elif FemalePop == 0 and Egg0 == 0 and Egg1 == 0 and Egg2 == 0 and Egg3 == 0 and Egg4 == 0 and Egg5 == 0 and Egg6 == 0 and Egg7 == 0 and Egg8 == 0 and Egg9 == 0 and Egg10 == 0 and Egg11 == 0 and Egg12 == 0 and Egg13 == 0 and Egg14 == 0 and Egg15 == 0 and Egg16 == 0 and Egg17 == 0 and Egg18 == 0 and Egg19 == 0 and Egg20 == 0: | ||
| elif not FemalePop + sum(eggs): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I agree! I'll update this branch. Truthiness is a feature of python I've cooled to as I've done more in other languages. Yep! Overall, your refactor gets to a lot of what I was intending to do in further PRs. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with Johannes that its better to treat FemalePop like an integer rather than a boolean. You can also improve your eggs comparison by using the any function with something like this: |
||
| print("Extinction") | ||
| break | ||
| break | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
neat. Did not know this was possible
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I initially had it as a trivial comprehension
[ x for x in range(20) ]but decided that was more convoluted.