PY tutorial

From WikiManual
Jump to: navigation, search

A complete tutorial for Version 2.36

NOTE: not complete here at the wiki yet.
go to to download the entire spiel.
will get it all here as i [or someone] finds time. or hey! you could do it. ;) Griztalk

(please bear with me as I convert this help file from its older format to the newer version as many of the older controls will not work in quite the same way.)

A basic overview What is a DarwinBot? A DarwinBot is a computer simulation of a simple life form. It is not intended to be an exact replica of any known living organism, nor is ever likely to be one. Think of it as a simple, but not necessarily single celled, creature with the ability to interact with it's surroundings in a number of ways. A DarwinBot lives in a 2-dimensional universe and feeds by extracting energy from other DarwinBots. DarwinBots of various design form the entire food chain. DarwinBots operate on a series of DNA like conditional instructions which I will refer to as Genes. These genes control every facet of the DarwinBot's life, from the way he looks for food to the way he defends himself or reproduces. As with any life form, these genes are able to mutate slightly each time a new generation is born. Sometimes the mutation will enable the young DarwinBot to perform a certain task in a more efficient way, in which case he is more likely to pass on his genes than was his predecessor. Sometimes the mutation will make him less efficient. Sometimes the mutation will even make him completely sterile. For the purpose of this tutorial I will largely ignore mutations and focus on programming strategies instead.

What commands can a DarwinBot use in his DNA? In Appendix 1 you can find a list of all the possible memory locations that are reserved for DNA commands and functions, and the names of the commands or functions found at each location. This information can also be found in the 'sysvars.txt' file in the DarwinBots directory where your game is stored. Each one of these will be discussed in detail later.

What is a Command? A command is a memory location into which a value is stored in order to make the robot perform a certain operation. They are addressed via labels.

What is a label? A label is a name preceded by a period. Each command and function can be addressed either by a label or by using their numerical address. Examples of labels are .refeye or .up.

What is a function A Function is a memory location into which the program automatically saves a value. Functions are used by the DarwinBot's DNA to read data about himself and his surroundings. Many (but not all) functions are cleared at the start of each cycle. Others may be renewed only when a certain event occurs.

How does the DarwinBot process the information in his DNA. The DNA of each robot is processed sequentially using a system of conditions and actions along with a 'stack' of data. This is somewhat similar to assembly language but is much easier to understand. The DarwinBot DNA uses a version of the more common IF/THEN statements found in all versions of BASIC, to decide on which actions to take based on input from certain of his memory locations (Functions). In normal BASIC the format will be:

IF 'condition' = true (or false) THEN 'perform action'

In the DarwinBot's DNA this would be written:

Cond 'condition' = true (or false) start 'perform action' stop

In addition to this slight difference in layout, the DarwinBot's DNA uses Reverse Polish Notation. Also variables cannot be used as they would be in BASIC. This means that instead of writing a condition as follows:

IF Apples = 10 THEN 'perform action' END IF

We would have to write something like:

Cond .eye5 10 = start 'perform action' stop

As you can see, we cannot use a variable such as 'apples'. Instead we must use a memory location within the robot's structure. .eye5 represents the value stored in just such a memory location. The '*' is a symbol used to indicate that we are reading a value stored in a location pointed to by the label .eye5. The '.' Means that the label immediately after it represents a numerical value. .eye5 is equal to 505. .eye5 could also be written as *505 (the value stored in location 505)

You will also notice that the syntax of the condition is reversed from the previous example. The '=' sign is placed after the two values that we wish to compare. This is because of the 'stack' nature of the DarwinBot's memory.

.eye5 places the value stored in memory location 505, onto the top of the stack. 10 places the value 10 onto the top of the stack. It goes in above the previous value, providing there is enough remaining space in the stack for it to do so. = This 'operand' takes the top two values out of the stack then compares them. If the two values are equal then the condition has been met and the program continues on to the 'action' step of the gene. If they are not equal then the program will skip the rest of the gene.

Several other 'operands' can be used in the DNA also. The following is a list of all of them and a brief description of their functions.

(=) The 2 values are equal. != The 2 values are not equal. > The first value is greater than the second value. < The first value is less than the second value. (%=) The two values are almost equal (within 10%)

How do I create a robot?

In order to make a good robot, you need to give him three things.

The ability to find food. 2. The ability to eat the food. 3. The ability to reproduce. Here is an example of a very simple combat robot. Rather than copy/pasting this into a txt file, it is better to type it in. then save the file as 'simplebot.txt' in the robots folder of the DarwinBots directory. Each stage of the development is also included as a txt file in the zip file. Alternatively each stage of the development of Simplebot can just be loaded into the game from the Simplebot files included with this tutorial. Run the DarwinBots program using the default settings. Ensure that vegs are not Blocked at this time. Don't bother to add any other robots just yet. Choose your favorite color, select 5 robots and give them 3000 energy. Finally disable all mutations before starting the simulation. We don't want him evolving yet. During this tutorial I will take you through all the stages of development of a combat oriented robot. Many of the things we try will inevitably be dead ends and will make our robot worse than at previous stages. These failed strategies can teach us a lot about the war DarwinBots works and hopefully make us all better programmers.

Simple Bot

Tie Bots The next evolutionary step for a DarwinBot has to be improved feeding capabilities. How are we going to improve on Simplebot? He feeds pretty well and reproduces well too but he still can't compete with the true top bots like Devincio Eversor (Tie destroyer). The name of my Devincio series of robots really says it all. Devincio is Latin for tie. All Devincio robots use ties to feed though some are better than others. Simplebot is able to defeat the first tie feeder bots with ease due to its amazingly efficient reproduction system. H_Devincio_Venator (HDV) was the robot that first started the tie feeders on their path to glory. HDV4 is a somewhat modified version of the original HDV and held the top spot until the birth of VEX. VEX was the first tie feeder to utilize the spinning search pattern that Simplebot uses and it gave him enough of an edge to unseat HDV.

What are ties? That is a good question. Ties are a feature of DarwinBots that was added in order to enable multiple individual DarwinBots to join up and form a multi cellular organism. A tie represents a defined relationship between two robots and is seen in DarwinBots as a thick line joining the two robots together. The tie keeps the robots in a fixed but flexible orientation to each other but only after a certain number of game cycles have passed. For the first 20 cycles the ties allow for free rotation of both robots.

What do ties do? Ties are one of the best and most challenging parts of the whole game. The things that ties allow robots to do are amazingly varied and a good proportion of all gene commands relate to ties in some way or other. When a tie is newly formed and is not yet 'hardened', it may be used for reading information about the tied robot, sending instructions to the tied robot, waste transfer, venom transfer and energy transfer. Once hardened, the tie can also be set for length and orientation angle with respect to the robot on either end of it. It also enables sharing of waste, shell and slime.

For the time being we are not interested in hardened ties. If we wish to feed from the tie then we need to act fast, not wait 20 cycles before doing anything. The only thing we need to do is to utilize the energy transfer function to drain energy from the robot on the other end of the tie.

How do we make a tie? Actually creating a tie is quite easy. All you need to do is to store a non zero value in .tie (memory location 330). In practice though, this isn't quite so simple. In the following examples I will lead you through the best way to create an efficient tie feeder and point out some of the pitfalls along the way. Tie Feeder Tutorial

In the next part of this tutorial we will begin to delve into the complexities of creating stable Multi-Bots. If you think that the lessons you have learned this far have been complex then you are sadly mistaken. In order to make a Multi-Bot work properly we will need to learn a whole new set of rules.

Happy coding

Purple Youko