# Evolving Fish Pond 5: Balancing and Simulating Realism

Planning
Step 1
In this lesson we are going to start balancing our game by giving Fish properties positive and negative effects
Information
Step 2
Right now bigger Fish have more of a chance to collide with food, but there is no downside to being large.

#### No downside = no balance

Planning
Step 3
One balancing idea is to make the size of Fish affect their stats

#### Smaller fish should use less energy to swim around

Step 4
Lets change the Fish so larger Fish use more food to move

#### Then we subtract `cost` from food rather than `2` as we had

Step 5
At the same time, larger Fish should have bigger stomachs

We can represent setting `maxfood` based on size

```  //Add this to the end of the Fish class' mutate method
this.maxfood = round(this.size*3+10);```
Step 6
Now the size of Fish balances positives and negatives
Planning
Step 7
Similarly faster Fish are currently more likely to collect food but have no drawbacks

The faster fish wins..

Step 8
Let's balance this by making speed affect how much food it takes to move

#### Now `cost` is proportional to the Fish's size and its speed.

Step 9
Now we have a balancing act for speed as well

More chances to hit food vs more need to collect food

Information
Step 10
All of this makes it harder to tell if its "better" for a Fish to be big or small, fast or slow, or something in between

Which of these do you think is the best fit for your environment so far?

Step 11
Here we can balance reproduction by requiring Fish to have enough food to support a child.

It used to just be a random chance, but here was say the Fish must also have at least 30 food.

Step 12
Here we make new Fish start with some of the food their parent has when they were born.

This way starving fish can't "cheat" natural selection by suddenly making a fully healthy baby fish just before it dies.

Planning
Step 13
Next we'll work on balancing our Plants which right now can grow forever and never disappear.

Way too many plants

Step 14
Let's start by adding a variable to limit the number of plants this pond can support.
`var maxPlants = 200;`
Challenge
Step 15
Prevent your plants from duplicating if the number of plants has reached (or passed) the maximum

Hints:

1. Right now, your plants duplicate if a random number from 0 to 10 is less than 1.
2. We can check the number of plants currently alive by logging `plantsArray.length`
Step 16
In real-life there are many complex factors which determine the number of plants a given pond can support

We've simplified all of that complexity into a single variable which we can tune up or down

Planning
Step 17
Similarly the factors that decide if a plant will grow or not are also very complicated

We can simplify this by adding a random probability component to our Plant's grow method

Step 18
Here is how we can add a 1 in 4 chance that our plants will grow every 2 seconds
Planning
Step 19
Next we're going to give our Plants a random chance of dying

In real-life plants can die for many different reasons

We are going to combine all of those reasons into a single probability. A 2% chance for each plant to die every frame.

Challenge
Step 20
Implement the above plan for you Plant class
• Give each Plant a new property named `dead` whose value starts as false
• In the plant's grow method it has a 2% chance of setting `dead` to true
• In "index.js" use a `.filter` to remove any dead plants from the plantArray
Step 21
We've now added some details to our simulation to reflect complications in real life

#### We've also learned some techniques for balancing stats.

• There are positives and negatives associated with being fast or slow, large or small, etc..

#### What other balance changes can you think of adding?

Evolving Fish Pond 5: Balancing and Simulating Realism Info

Account

MVCode Clubs

Created By

Course:

Evolving Fish Pond

Access Level