Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 14 additions & 49 deletions BULBASAUR.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link

@Johanneslueke Johanneslueke Jul 20, 2019

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

Copy link
Author

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.


with open('BulbasaurPopulation.csv', 'a', newline='') as csv_file:
fieldnames = ['tick', 'females', 'males']
Expand Down Expand Up @@ -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



Expand All @@ -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):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • I see that you count on the fact that everything not 0 is evaluated as True but FemalePop is not a boolean and the actual comparison would convey the abort condition better in my eyes.

  • building the sum to check if no egg is left is clever. in my solution, I iterated over every element checked if the content is zero and then assigned the result to a boolean via &= operator, a bit more work then your solution XD

Copy link
Author

Choose a reason for hiding this comment

The 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.

Choose a reason for hiding this comment

The 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:
if FemalePop <= 0 and not any(eggs)
The any function goes through and checks if any element in an iterable is non zero which makes it a bit more ideal for boolean checks over sum. Plus I feel like the phrase 'and not any(eggs)' is more self-documenting.

print("Extinction")
break
break