Search for life

Search for life

Procedural generation to make a galaxy.

Try


Select the button below to open the Python program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.

Watch this video to learn about the new concepts shown in the program:

Knowledge Organiser

Giving a list some data when it is declared is called `enumerating`. In this program, the lists creature, colour and characteristic are all enumerated with data for the program to use.


As the size of the data structures for creature, colour and characteristic never change when the program is running, we can think of these structures as `arrays`.


Arrays are static and do not change their size. Lists are dynamic and do change their size.

Investigate


Questions to think about with this program to check your understanding:

Purpose question

What is the purpose using the variable `planet` in `random.seed(planet)` in line 17?

REVEAL ANSWER

Every time you run the program you need the planet to be the same as it was last time the program was run. By setting the seed using the planet variable you can ensure the same deterministic set of values are always generated for a given planet by the (not so) random number generator.


This is a pretty neat trick called procedural generation used in games development. Instead of storing all the data, the computer can generate it when it needs it instead.


In this example, we can have billions of planets that stay the same while only using a small fraction of memory because the attributes are stored, not the planets.

Reason question

Why are the random indexes in lines 18-20 between 0 and 2 instead of between 1 and 3 given that creature, colour and characteristic can have one of three possible attributes?

REVEAL ANSWER

Lists are zero-indexed. I.e. they start at zero and not one. E.g. creature[0] is "lizards", creature[1] is "humanoids" and creature[2] is "insects".

Make


Success Criteria

Change the program so that:

  1. It allows for planets to have a hot, frozen, barren or a temperate climate.
  2. The weather on the planet can be one of four values corresponding to the climate.
  3. Only temperate planets can sustain life.
  4. The output messages match those shown below.

Typical inputs and outputs from the program would be:

Enter the catalogue number of a planet: 10

Probes report a hot planet with no signs of life.


Enter the catalogue number of a planet: 11

Probes report green, angry insects on a temperate planet.


Enter the catalogue number of a planet: 12

Probes report blue, docile humanoids on a temperate planet.


Enter the catalogue number of a planet: 13

Probes report a barren planet with no signs of life.

Help

Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.

Evaluate


Run your code to check that your program has met the success criteria and produces the required output.

Enter the catalogue number of a planet: 204

Probes report blue, shy lizards on a temperate planet.

Enter the catalogue number of a planet: 205

Probes report blue, shy humanoids on a temperate planet.

Enter the catalogue number of a planet: 206

Probes report a hot planet with no signs of life.

Enter the catalogue number of a planet: 207

Probes report a frozen planet with no signs of life.

Enter the catalogue number of a planet: 208

Probes report a barren planet with no signs of life.

Enter the catalogue number of a planet: 212

Probes report red, docile insects on a temperate planet.